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

Resizeable child? #1710

Closed
nikki93 opened this issue Mar 29, 2018 · 7 comments
Closed

Resizeable child? #1710

nikki93 opened this issue Mar 29, 2018 · 7 comments

Comments

@nikki93
Copy link

nikki93 commented Mar 29, 2018

Is it possible to make a child area / window that is resizable? I ask because I have a 'long text' view and would like the user to be able to expand the view to see more. The long text is wrapped in a BeginChild()/EndChild() pair. Here's what it looks like:

img_0102

The vertical bar is moveable / columns are resizable as usual in the horizontal direction, but would like resizing of in the vertical direction to see more of the text.

@ocornut
Copy link
Owner

ocornut commented Mar 30, 2018

Hello @nikki93 ,

It isn't possible at the moment but I would like to support it. I haven't decided how to handle enabling it flags and how precisely to handle the data persistence. Ideally we would make it the default and rely on e.g. ImGuiWindowFlags_NoResize to disable it, but that would unfortunately break quite a lot of old code, and for child window it is probably desirable to be able to control the feature on a per-axis basis.

I will eventually find and implement a solution for this but I don't know when yet.

@nikki93
Copy link
Author

nikki93 commented Mar 30, 2018

@ocornut Wonderful thanks for the heads up! I think after digging around I can do something in userspace over the current ImGui API by having a separator-like button that I watch for drag events on and adjust + persist the sizes of the relevant children accordingly.

@ocornut
Copy link
Owner

ocornut commented Mar 31, 2018 via email

@ocornut ocornut added this to the v1.90 milestone Oct 18, 2023
ocornut added a commit that referenced this issue Nov 2, 2023
…ldFlags type and the ImGuiChildFlags_Border value. (toward #1666, #1496, #1395, #1710)
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 2, 2023
…r geometry has moved. (#1710)

(e.g. resizing a child window triggering parent scroll) to avoid resizing feedback loop.
@ocornut
Copy link
Owner

ocornut commented Nov 2, 2023

It is now possible to manually resize child windows by using the ImGuiChildFlags_ResizeX / ImGuiChildFlags_ResizeY flag.

Resizable child window sizes are persistent in .ini file.

Double-click a resizing border makes the window auto-resize on this child (this was also applied to all windows).

There's special handling to switch to a specific relative resize mode only using mouse-delta when a window move within its parent, to avoid feedback loops when e.g. resizing a child window means the parent needs scrolls back up.

Main resizing changes 805cf8d and f1d1a8d, following some earlier related refactors to allow it (e.g. f8dc03d, c95fbb4, e2035a5, bc3c6e7, 4e4042b).

Please note that this come bundled with a slight but actually harmless API-breaking change to BeginChild() api, see 7713c29 and 34a0bc4.

e.g.

BeginChild("Child", ImVec2(0.0f, 400.0f), ImGuiChildFlags_ResizeY);

child_resizable

Resizing may only be done in the layout natural direction aka from the bottom or right border.
(When we add support for e.g. top-to-bottom layout it will become possible to resize from the opposite border)

@ocornut ocornut closed this as completed Nov 2, 2023
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.
ocornut added a commit that referenced this issue Nov 7, 2023
…ResizeY, ImGuiChildFlags_AlwaysAutoResize + support for SetNextWindowSizeConstraints(). (#1666, #1395, #1496, #1710) + Demo

Note that child don't report ideal content size to parent so nesting may be difficult.
Note 4e4042b simplified SkipItems logic.
Note e2035a5 standardizing WindowMinSize application on child
@ocornut ocornut mentioned this issue Nov 7, 2023
@ocornut
Copy link
Owner

ocornut commented Nov 7, 2023

Another example showcasing how this could be leverage in places where e.g. splitter patterns (which are not readily usable) would be used;

e.g. "Demo->Examples->Simple Layout" now does:

ImGui::BeginChild("left pane", ImVec2(150, 0), ImGuiChildFlags_Border | ImGuiChildFlags_ResizeX);
for (int i = 0; i < 100; i++)
{
    char label[128];
    sprintf(label, "MyObject %d", i);
    if (ImGui::Selectable(label, selected == i))
        selected = i;
}
ImGui::EndChild();
ImGui::SameLine();
....
ImGui::BeginChild("item view", ....);

child_resizable2

Double-clicking fits to required size.

ocornut added a commit that referenced this issue Nov 10, 2023
…ly have no value other than confusing user and IDE.

Amend 7713c29 (was for #1666, #1496, #1395, #1710)
@firesgc
Copy link

firesgc commented Jan 2, 2024

Hi!

I render my child windows with ImGuiWindowFlags_NoBackground, and for this reason, I don't see the resizing borders.
I have modified the static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window) function like this:

static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
{
    ImGuiContext& g = *GImGui;
    float rounding = window->WindowRounding;
    float border_size = window->WindowBorderSize;
    if (border_size > 0.0f && !(window->Flags & ImGuiWindowFlags_NoBackground))
        window->DrawList->AddRect(window->Pos, window->Pos + window->Size, GetColorU32(ImGuiCol_Border), rounding, 0, border_size);

    if (window->ChildFlags & (ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY))
    {
        int resize_border_mask = 0x00;
        if (window->Flags & ImGuiWindowFlags_ChildWindow)
            resize_border_mask |= ((window->ChildFlags & ImGuiChildFlags_ResizeX) ? 0x02 : 0) | ((window->ChildFlags & ImGuiChildFlags_ResizeY) ? 0x08 : 0);
        else
            resize_border_mask = g.IO.ConfigWindowsResizeFromEdges ? 0x0F : 0x00;
        for (int border_n = 0; border_n < 4; border_n++)
        {
            if ((resize_border_mask & (1 << border_n)) == 0)
                continue;

            const ImGuiResizeBorderDef& def = resize_border_def[border_n];
            const ImRect border_r = GetResizeBorderRect(window, border_n, rounding, 0.0f);
            const ImU32 border_col = GetColorU32(ImGuiCol_Separator);
            window->DrawList->PathArcTo(ImLerp(border_r.Min, border_r.Max, def.SegmentN1) + ImVec2(0.5f, 0.5f) + def.InnerDir * rounding, rounding, def.OuterAngle - IM_PI * 0.25f, def.OuterAngle);
            window->DrawList->PathArcTo(ImLerp(border_r.Min, border_r.Max, def.SegmentN2) + ImVec2(0.5f, 0.5f) + def.InnerDir * rounding, rounding, def.OuterAngle, def.OuterAngle + IM_PI * 0.25f);
            window->DrawList->PathStroke(border_col, 0, ImMax(2.0f, border_size)); // Thicker than usual
        }
    }
....

Is there a better solution to fix the issue without modifying ImGui directly? I don't want to "port" my fix with each new release.

Thank you for the awesome library!

@ocornut
Copy link
Owner

ocornut commented Jan 2, 2024

Please open a new issue about this so I can track it. Thank you!
EDIT Opened #7194

ocornut added a commit that referenced this issue Jan 4, 2024
ocornut pushed a commit that referenced this issue Mar 27, 2024
pull bot pushed a commit to TeamREPENTOGON/imgui that referenced this issue Mar 27, 2024
pull bot pushed a commit to TeamREPENTOGON/imgui that referenced this issue Mar 27, 2024
ocornut added a commit that referenced this issue May 24, 2024
…not both) ResizeX/ResizeY and double-clicking on a border. (#1710)

Calculation incorrectly didn't always account for scrollbar as it assumed the other axis would also be auto-fit.
ocornut added a commit to ocornut/imgui_test_engine that referenced this issue May 24, 2024
ocornut added a commit to ocornut/imgui_test_engine that referenced this issue May 24, 2024
ocornut added a commit that referenced this issue Sep 26, 2024
…n a child window using ImGuiChildFlags_ResizeX/ImGuiChildFlags_ResizeY. (#1710, #8020)
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

3 participants