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

Horizontal Scrolling Child Window and CollapsingHeader #7659

Open
ElectroidDes opened this issue Jun 4, 2024 · 3 comments
Open

Horizontal Scrolling Child Window and CollapsingHeader #7659

ElectroidDes opened this issue Jun 4, 2024 · 3 comments

Comments

@ElectroidDes
Copy link

ElectroidDes commented Jun 4, 2024

Version/Branch of Dear ImGui:

Version 1.90.6

Back-ends:

Raylib/OpenGL

Compiler, OS:

Windows 10

Full config/build information:

No response

Details:

if (ImGui::Begin("Parent Window"))
 {

 if (ImGui::BeginChild("Child Window", ImVec2(0, 0), true))
 {
 if (ImGui::CollapsingHeader("My Very Long Header That Does Not Fit Inside The Window"))
 {
 ImGui::Text("Hello, world!");
 }
 ImGui::EndChild();
 }
 }

 ImGui::End();

This code draws a child window and a CollapsingHeader and when the length of the CollapsingHeader name goes beyond the child window, a horizontal scroll is drawn in the child window. Everything is working fine.

But if I remove the line ImGui::Text("Hello, world!") from CollapsingHeader, then the child window will no longer draw a horizontal scroll if the length of the CollapsingHeader name extends beyond the child window.

Is this how it should be?

@DynamicalCreator
Copy link

When i run your code, i dont get horizontal scrollbar when the CollapsingHeader name goes beyond the child window, no matter if the ImGui::Text is there. Horizontal scrollbars are disabled by default, so I dont know how you got a scrollbar without a corresponding flag. If you need a horizontal scrollbar, just pass ImGuiWindowFlags_HorizontalScrollbar to the window_flags of BeginChild(). Use ImGuiWindowFlags_AlwaysHorizontalScrollbar if you need to have the scrollbar visible even when the text is fully visible.

Also, why are you passing true as the child_flags to BeginChild()? It seems a bit weird to me.

@ocornut
Copy link
Owner

ocornut commented Jun 5, 2024

Also, why are you passing true as the child_flags to BeginChild()? It seems a bit weird to me.

We changed the signature of BeginChild() quite recently (Sept 2023)

// old
bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0, 0), bool border = false;

// current
bool BeginChild(const char* str_id, const ImVec2& size = ImVec2(0, 0), ImGuiChildFlags child_flags = 0, ImGuiWindowFlags window_flags = 0);

// Flags for ImGui::BeginChild()
// (Legacy: bit 0 must always correspond to ImGuiChildFlags_Border to be backward compatible with old API using 'bool border = false'.
enum ImGuiChildFlags_
{
    ImGuiChildFlags_None                    = 0,
    ImGuiChildFlags_Border                  = 1 << 0,   // Show an outer border and enable WindowPadding. (IMPORTANT: this is always == 1 == true for legacy reason)
    ...
};

Which allowed a smoother transition, so old code frequently uses true which will still work, but ideally should be changed to ImGuiChildFlags_Border.

@DynamicalCreator
Copy link

Oh, didn't know that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants