ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
57.81k stars 9.91k forks source link

Horizontal Scrolling Child Window and CollapsingHeader #7659

Open ElectroidDes opened 1 month ago

ElectroidDes commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 3 weeks ago

Oh, didn't know that.