-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Feature request: Horizontal layout #97
Comments
Yes! The reason I haven't added the simple version yet (like your suggested API) is that I wanted to spend more time considering the layout problem holistically. We'd probably want
Notes
Thanks for the suggestion! |
But you are right, a simple helper would be welcome asap. |
Could also skip on the Layout word. ? Horizontal() / BeginHorizontal() / EndHorizontal() |
And add ImGui::NextLine() as well. |
Yeah, for now I've created my own NextLine based on Separator - that kind of works =) I feel push/pop is more descriptive iff nesting is supported. I'm all for skipping the "Layout" part, i.e. PushHorizontal/PopHorizontal. PushHorizontal(); Text("a"); Text("b"); PushVertical(); Text("c"); Text("d"); PopVertical(); PopHorizontal(); ->
Something like that? |
But:
Currently becomes:
So starting a vertical layout should "lock" the X current coordinate? Which is what happens with your example. In which case how to do achieve the layout above with the Push/Pop system?
If locking is done on "pushing" the vertical layout and not "popping" then we can't have Horizontal() /
Does that become the layout in your example or in mine? Gets a bit confusing. So my proposal is that all those gives the same output:
That is:
So there's less stored state. Now if we want to implement your layout example (which is more of a rare case) we can have a way to set the value internally called "ColumnsStartX" (those variables can be cleaned up/renamed before being publicly exposed).
Passing a float is more flexible but the difference between 0.0f (left side) and -1.0f (current cursor x) may be a bit arbitrary ? I guess you can always do ImGui::Vertical(ImGui::GetCursorPosX()); as well. Does it makes sense? |
Also - the devil is in the details - we would probably want to add WindowPadding.x to the provided offset_x. Which becomes a problem because:
We could treat 0.0f as a special case but that would be dodgy. So a more consistent solution would be:
But then to implement your example you would need to call GetCursorPosX() and we lose the "lock current x position" shortcut. |
I think Horizontal()/Vertical() plus PushCurrentLayout() can simplify things: wanna change layout? -- change, wanna save? -- push/pop. |
Awesome library but I really hope this gets worked on soon as the current solution to use const ImGuiIO& guiIO = ImGui::GetIO();
const static char* titleWindowTitle = "title";
ImGui::Begin(titleWindowTitle, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
const static char* title = "Centered Title";
ImVec2 textSize = ImGui::CalcTextSize(title);
ImVec2 windowSize = ImVec2(textSize.x + Constants::UiPadding * 2.f, textSize.y + Constants::UiPadding * 2.f);
ImGui::SetWindowPos(ImVec2((guiIO.DisplaySize.x - windowSize.x) * 0.5f, (guiIO.DisplaySize.y - windowSize.y) * 0.5f));
ImGui::SetWindowSize(windowSize);
ImGui::SetWindowFontScale(2.f);
ImGui::TextUnformatted(title);
ImGui::End(); |
There is something for me. Basic implementation of layouts in form of BeginHorizontal/EndHorizontal. ImGui::BeginHorizontal("example_h1", spanToWindow ? bounds : ImVec2(0, 0));
ImGui::TextUnformatted("Left");
ImGui::Spring(middleWeight);
ImGui::TextUnformatted("Middle");
ImGui::Spring(1.0f - middleWeight);
ImGui::TextUnformatted("Right");
ImGui::EndHorizontal(); It is rough around the edges so please give me a feedback how it can be improved. |
It's been 7 years already, any updates on builtin layouts? |
What's wrong with Stack Layout? #846? |
@thedmd the only thing wrong with StackLayout is that it is not merged :D |
In some time I think a change can be proposed to allow other layout engines too. Truth is Stack Layouts are one of the possible solutions. Grids, forms (labels on the left anyone?), overflow layouts are examples of alternatives better suited for their respective use cases. As for today few small modifications in ImGui are necessary to make custom layout code possible. (#846 (comment)). There is a branch where Stack Layout code is moved to eventually became a plugin/extension to ImGui feature/layout-external. |
It's exactly what I want but It's still not merged( |
Yes importing yoga/flexbox would be a great addition too |
Any updates on this? |
It's taking ages 😂 |
One day... |
This works for me int maxColumns = 10;
ImGui::Columns(maxColumns, "MyLayout", false);
ImGui::SetColumnWidth(0, 80);
for (int i = 1; i < maxColumns - 1; i++)
{
ImGui::SetColumnWidth(i, 80);
ImGui::Text("item");
ImGui::NextColumn();
}
ImGui::EndColumns(); |
I'm just in the process of studying, and I'm unlikely to be useful in terms of project development right now. But, if someone decides to improve it, then I suggest considering the implementation https://developer.android.com/reference/android/widget/LinearLayout I don't mean the code itself, but the capabilities of this Layout, which has been built into the Android OS since the first version. What would be cool to see: weightSum, orientation and gravity setup |
The only way I've found to do horizontal layout in ImGui is to call SameLine() in between widgets that should go on the same line. This is problematic when the widgets are painted by some other code. In particular, I want to lay out an unknown number of Text:s horizontally on the same line.
May I suggest adding something like:
The text was updated successfully, but these errors were encountered: