Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex layout implementation #153

Closed
Osiris-Team opened this issue Jan 19, 2023 · 5 comments
Closed

Flex layout implementation #153

Osiris-Team opened this issue Jan 19, 2023 · 5 comments
Labels
question Question issue type

Comments

@Osiris-Team
Copy link

Osiris-Team commented Jan 19, 2023

Is there an implementation of css flexbox for this?
I find it quite annoying to give absolute coordinates and sizes to almost all my components.
https://www.w3.org/TR/css-flexbox-1/#box-model

Also it looks like I can't position text?

@Osiris-Team Osiris-Team added the missing binding Some of the original library API is missing label Jan 19, 2023
@SpaiR SpaiR added question Question issue type and removed missing binding Some of the original library API is missing labels Jan 20, 2023
@SpaiR
Copy link
Owner

SpaiR commented Jan 20, 2023

Unfortunately, Dear ImGui (the original library) is not built with layouts in mind. There are PR's like ocornut/imgui#846, but as you can see from the date of its create (2016) and the fact that it's still not merged - widgets layout is not a main course of the library.

It's possible to implement stuff like that by yourself, but it's always a work from the ground. A hard work I might say.

Also, as the workaround solution you can try to use table API. It's pretty useful in situations when you need to spread items properly. Still, it's far away from functionality like flexbox though...

For the reference:

@Osiris-Team
Copy link
Author

Osiris-Team commented Jan 20, 2023

Thanks @SpaiR , that's sad to hear though.
I started working on a java flex layout implementation, using the table api like you said.
And some basic functionality is already working:

        FlexLayout ly = new FlexLayout(null); // parent == null thus sets the window as its parent
        // Default alignment of FlexLayout is vertical
        ly.horizontal() // returns a new child FlexLayout with horizontal alignment
                .text("Some ").text("text!");
        ly.vertical() // returns a new child FlexLayout with vertical alignment
                .text("More ").text("text!");

If someone is interested in using/contributing, the source code for this is here:
https://github.com/Osiris-Team/BetterDesktop/tree/main/src/main/java/com/osiris/betterdesktop/utils/flex
I'll move it to a separate repo someday maybe.

Currently I am having troubles setting custom widths, specially heights for the components, no clue how to achieve that in imgui, since setNextItemWidth() is the only method that looked good, but doesnt exist for height.

@SpaiR
Copy link
Owner

SpaiR commented Jan 20, 2023

@Osiris-Team
Copy link
Author

Osiris-Team commented Jan 20, 2023

Wow that looks exactly like what I was looking for! Thanks!
But the API is kind of ugly, so I guess I'll still try developing it myself, but it's definitively a pretty good resource to see how they managed to create such a complex layout via imgui.

@Osiris-Team Osiris-Team changed the title Flex layout implementation? Flex layout implementation Jan 20, 2023
@Osiris-Team
Copy link
Author

Osiris-Team commented Feb 6, 2023

So in the end the library is not meant to be used with imgui it seems.
I then lost it and made my own GUI library Desku available here: https://github.com/Osiris-Team/Desku
Its uses chromium to render, thus the GUI is based on HTML/CSS/JS, however it removes the need to write in those languages and makes it possible to have a fully Java based GUI.

The main reason that I gave up imgui is, because its weird and harder to write async code that interacts with the UI.
HTML/CSS are also much more developed/flexible GUI languages, thus it makes more sense to use them.

Besides that I have a full Java FlexBox "implementation", check out this class: https://github.com/Osiris-Team/Desku/blob/main/src/main/java/com/osiris/desku/ui/Component.java

The memory usage and the cpu usage are very low (around 17MB for an almost blank window + dev tools window, note that I substracted the reserved null heap from Java wich is around 160MB).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question issue type
Projects
None yet
Development

No branches or pull requests

2 participants