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

Column separator/border sizing issue #170

Closed
unpacklo opened this issue Mar 20, 2015 · 3 comments
Closed

Column separator/border sizing issue #170

unpacklo opened this issue Mar 20, 2015 · 3 comments

Comments

@unpacklo
Copy link

Back to my columns!

I've been noticing some strange behavior with the column separator/border sizing when a child region is used within the columns. Here is some test code to illustrate:

        ImGui::Begin("Column separator");
        static bool useChild = false;
        ImGui::Checkbox("use child", &useChild);

        static bool useChildBorder = false;
        ImGui::Checkbox("use child border", &useChildBorder);

        static float childHeight = 0.0f;
        ImGui::SliderFloat("child height", &childHeight, 0.0f, 500.0f);

        ImGui::Columns(2);

        if (useChild) ImGui::BeginChild("col 1", ImVec2(0.0f, childHeight), useChildBorder);

        for (int i = 0; i < 10; ++i)
        {
            ImGui::Text("line %d", i + 1);
        }

        if (useChild) ImGui::EndChild();

        ImGui::NextColumn();

        if (useChild) ImGui::BeginChild("col 2", ImVec2(0.0f, childHeight),useChildBorder);

        for (int i = 0; i < 20; ++i)
        {
            ImGui::Text("line %d", i + 1);
        }

        if (useChild) ImGui::EndChild();
        ImGui::End();

screenshot-imgui opengl2 example-2
screenshot-imgui opengl2 example-3
screenshot-imgui opengl2 example-4

In the first screenshot, the column separator is the size I would expect. However, in the second screenshot where the child regions are given sizes of zero to automatically use up the remaining space, the separator is tiny and does not match the size of the child region. Finally, in the third, we give an explicit non-zero height and the column separator is going back to what we expect.

Aside from this issue specifically, is there a way to force the column separators to be at least a certain length without actually populating the columns with content? There are some use cases I have where I set up a basic column layout and the columns get filled with user input. At the start, when it's empty, the window is basically completely empty and it feels strange not seeing the borders to show the basic layout.

ocornut added a commit that referenced this issue Mar 20, 2015
@ocornut
Copy link
Owner

ocornut commented Mar 20, 2015

The problem is a bit tricky. Auto-filling child windows don't notify the parent of their size (intentionally) so it doesn't feed back into auto-fitting measurement (that's used e.g. when you double-click on the lower-right corner). Now to be realistic this feature only work if you use a subset of features, so it's already partly broken (but still useful in many cases).

I just made them pass their size to the parent. It will probably solve a few problems including yours. It will also create a few odd cases but they may be on less common path so it is probably a worthy change.
e.g. If you add ImGui::Text("Hello"); just before the final end, you are effectively drawing past the window content sizes. With the change it will show a scrollbar and everytime you try to scroll down it will grow the total scroll area a little more. That's odd but I suppose what is happening is more "obvious": you are asking for something to take 100% of the space and then adding more, it is bound to grow.

The second question: how to extend the columns to the bottom. You can do it simply by positioning the cursor how far you want them to go before closing the column. Unfortunately the exact position that doesn't feed back into auto-fitting is a bit tedious:

ImGui::SetCursorPosY(ImGui::GetWindowSize().y - style.ItemSpacing.y - style.AutoFitPadding.y);

style.ItemSpacing.y because closing columns adds spacing.
I'll have a think about the right way to make it simpler.

EDIT it's actually trickier than that, that formula is only correct for the top window. Considering removing AutoFitPadding it may simplify several things.

@unpacklo
Copy link
Author

Sorry about the late response; had a new computer to build and migrate a bunch of our build servers over as a result of newer hardware becoming available!

I tried my test program out with the current master and the border sizing behavior with children looks perfect now.

With regard to the border extension to bottom, would it be possible to just have another parameter sent in to ImGui::Columns()? Something like:

IMGUI_API void          Columns(int count = 1, const char* id = NULL, bool border=true, bool border_extend = false);

border_extend = true just automatically assumes you want to use up the rest of the remaining vertical space? Certainly would make things easier for me as the user.

What I don't like about this is having a whole extra parameter for something that doesn't apply at all if border = false.

@ocornut
Copy link
Owner

ocornut commented May 1, 2015

I was about to add that and decided against. Because Columns() need bigger changes and I want to add them before adding an extra parameter. Perhaps the API itself will change into a BeginColumns()/EndColumns() ? I don't know. But until we have proper header and easy scrolling within a column set it's not worth adding this.
I'll close this to merge with #125

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