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

BeginChild Resize to Contents? #1666

Closed
skl131313 opened this issue Mar 6, 2018 · 3 comments
Closed

BeginChild Resize to Contents? #1666

skl131313 opened this issue Mar 6, 2018 · 3 comments
Milestone

Comments

@skl131313
Copy link

Is there a resize to content mode for an axis using ImGui::BeginChild()?

I want to have horizontal scrolling but I don't want there to be vertical scrolling. I want it to resize to the size of the contents vertically. Is there anything like this?

I can manually set a fixed size, but then I need to calculate and compensate for when the horizontal scrollbar might be visible.

@ocornut
Copy link
Owner

ocornut commented Mar 7, 2018

Hello @skl131313, unfortunately it isn't possible at the moment. I see what you are trying to do and agree it would be helpful. I have an idea of how to implement it but it's not a trivial change and I don't know when I'll be able to tackle it.

In the meanwhile, maybe using both flags ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar can allow you to compute that extra height for the scrollbar since it won't change any more.

@skl131313
Copy link
Author

No worries if it requires a big change, it's more of a nice to have feature than a requirement.

@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 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
Copy link
Owner

ocornut commented Nov 7, 2023

It is now possible to

  • manually resize child windows (on either axis)
  • make child windows auto-fit (on either axis)

See #1710 and new examples in "Demo->Layout->Child Windows"

Basic auto-resize:

ImGui::BeginChild("name", ImVec2(-FLT_MIN, 0.0f), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY);

Using a min/max constraint may be particularly useful:

ImGui::SeparatorText("Auto-resize with constraints");

static int draw_lines = 3;
static int max_height_in_lines = 10;
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
ImGui::DragInt("Lines Count", &draw_lines, 0.2f);
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
ImGui::DragInt("Max Height (in Lines)", &max_height_in_lines, 0.2f);

ImGui::SetNextWindowSizeConstraints(ImVec2(0.0f, ImGui::GetTextLineHeightWithSpacing() * 1), ImVec2(FLT_MAX, ImGui::GetTextLineHeightWithSpacing() * max_height_in_lines));
if (ImGui::BeginChild("ConstrainedChild", ImVec2(-FLT_MIN, 0.0f), ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY))
    for (int n = 0; n < draw_lines; n++)
        ImGui::Text("Line %04d", n);
ImGui::EndChild();

child_resizable2_with_constraints

If you omit the SetNextWindowSizeConstraints() you can have auto-resizing on either axis.

Please note that combining both ImGuiChildFlags_AutoResizeX AND ImGuiChildFlags_AutoResizeY together is not recommended as it undo the main purpose of child windows.

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