Skip to content

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

Closed

Description

@dsusini

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

Activity

  1. ocornut commented on Dec 30, 2015

    @ocornut
    Owner

    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.

  2. dsusini commented on Dec 30, 2015

    @dsusini
    Author

    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.

  3. ocornut commented on Apr 3, 2016

    @ocornut
    Owner

    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.

  4. ocornut commented on Apr 3, 2016

    @ocornut
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址