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

Child window with no border seems to be ignoring WindowPadding #462

Closed
dsusini opened this issue Dec 30, 2015 · 4 comments
Closed

Child window with no border seems to be ignoring WindowPadding #462

dsusini opened this issue Dec 30, 2015 · 4 comments

Comments

@dsusini
Copy link

dsusini commented Dec 30, 2015

I've created a "tool panel" style child window that is aligned with the left of the parent window. When I set it's border to 'false', all window padding seems to be ignored. I tried setting the default padding to something large like 20. When BeginChild is called with border=true, the padding shows like usual. When I pass false, the padding is ignored. I'm not sure if this is intended or not. I made a simple example to test this out:

(We have to make sure the childBG has a valid color)

ImGui::SetNextWindowSize(ImVec2(1200, 700), ImGuiSetCond_FirstUseEver);
ImGui::Begin("edit_window", NULL);
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 8));
    ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, ImVec4(0.16f, 0.16f, 0.16f, 1.00f));
    ImVec2 toolbarSize(300, 0);
    ImGui::BeginChild("toolbar", toolbarSize, false);
        ImGui::Text("Testing");
        ImGui::Spacing();
        ImGui::Text("Testing2");
    ImGui::EndChild();
    ImGui::PopStyleColor();
    ImGui::PopStyleVar();
ImGui::End();

Please let me know if this is something I'm doing wrong, working as intended, or if it's a bug. I can easily work around it for now, but it's just one of those annoying things :)

Thanks!
Don

@ocornut
Copy link
Owner

ocornut commented Dec 30, 2015

The code in Begin() is intentionally doing that:

window->WindowPadding = ((flags & ImGuiWindowFlags_ChildWindow) && (flags & (ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_ComboBox | ImGuiWindowFlags_Popup)) == 0) ? ImVec2(0,0) : style.WindowPadding;

It sort of made sense because if you don't see a border then the spacing would be odd. But probably it'd be more consistent to not do that and let the user set the WindowPadding to 0.0 if they need it. I'll need to think about it a little more and see the side-effect it could have to change that.

@ocornut ocornut added the bug label Dec 30, 2015
@dsusini
Copy link
Author

dsusini commented Dec 30, 2015

Ok, I get what you're saying. I guess in this specific case allowing the user to control the padding makes more sense to me, but I know that child windows are used for a lot of different things in the framework and could affect a lot. A simple workaround was to just set the border color to the childBG color and not worry about it.

@ocornut
Copy link
Owner

ocornut commented Apr 3, 2016

Came back to that, initially decided to remove the inconsistency and require the user to set the padding to 0.0f. I then went and looked at merely the demo.cpp code and it became apparent that it would be an annoyance and break many people code (even if the breakage is so slight).

In addition, it is a rather common pattern to create a "header" full of widget followed by a child filling the rest of the window, and that looks weirder with padding.

So we can either:

  • A. Enforce consistent padding usage, break some people code and require use of PushStyleVar in more cases.
  • B. Add a rarely used flag to handle your situation, e.g. ImGuiWindowFlags_ChildWindowUsesWindowPadding.
  • C. Or document your workaround as the right way to do it.

I think I want to actually go for C there.
I am going to think about it a little more, also because I am thinking that Border information should be explicitly declared in ImGuiStyle for consistency, so that might affect something here.

ocornut added a commit that referenced this issue Apr 3, 2016
ocornut added a commit that referenced this issue Apr 3, 2016
@ocornut
Copy link
Owner

ocornut commented Apr 3, 2016

Alright, I went for B seeing even C looked tedious from user's point of view, and added a flag ImGuiWindowFlags_AlwaysUseWindowPadding.

Also fixed bug with ListBox(), InputTextMultiline() where the content would be misplaced when border was enabled on widgets, because of that same thing.

@ocornut ocornut closed this as completed Apr 3, 2016
ocornut added a commit that referenced this issue Nov 2, 2023
…mGuiWindowFlags_AlwaysUseWindowPadding. (#462, (toward #1666, #1496, #1395, #1710)

(bonus: will also eventually free a window flag)
ocornut added a commit that referenced this issue Nov 7, 2023
…eginChildFrame(). (#1666, #1496, #1395, #1710, #462, #503, #263)

Effectively allows us to avoid extending BeginChildFrame() api to mimic BeginChild() new parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants