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

Vertical scrollbar in child window doesn't affect content region width #8195

Open
Teselka opened this issue Nov 29, 2024 · 5 comments
Open
Labels

Comments

@Teselka
Copy link
Contributor

Teselka commented Nov 29, 2024

Version/Branch of Dear ImGui:

master

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux + GCC

Full config/build information:

Dear ImGui 1.91.6 WIP (19152)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: __linux__
define: __GNUC__=14
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 1.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

I've made a simple sidebar by using a child window, but when the scrollbar appears, it doesn't change the content region width as it should when using a normal window.

Screenshots/Video:

Expected behavior (as in normal window):
image

Current behavior (child window):
image

Minimal, Complete and Verifiable Example code:

ImGui::SetNextWindowSize({ 500.f, 350.f }, ImGuiCond_Appearing);
ImGui::Begin("Child window scrollbar bug");
ImGui::BeginChild("##Sidebar", { 250.f, 0.f });
for (int i = 0; i < 20; i++) {
    ImGui::Text("Item %i", i);
    if (i % 5 == 0)
        ImGui::Separator();
}
ImGui::EndChild();
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Nov 29, 2024

it doesn't change the content region width as it should when using a normal window.

I am not sure what you mean exactly?

If you mean that the issue is that the Separator() reach the right border touching the scrollbar, it is because a BeginChild() without borders by default has zero WindowPadding. If you enable borders ImGuiChildFlags_Borders by default it inherit WindowPadding:

image

If you use ImGuiChildFlags_AlwaysUseWindowPadding:

image

Then you have both the parent padding + the child padding.

@ocornut ocornut added the layout label Nov 29, 2024
@Teselka
Copy link
Contributor Author

Teselka commented Nov 29, 2024

If you mean that the issue is that the Separator() reach the right border touching the scrollbar, it is because a BeginChild() without borders by default has zero WindowPadding. If you enable borders ImGuiChildFlags_Borders by default it inherit WindowPadding:

Yes, thanks! I thought for some reason that scrollbar overlaps it.
But now i have another issue: i don't really want window padding for every single side, except for the right (because it basically doubles padding amount)

@ocornut
Copy link
Owner

ocornut commented Nov 29, 2024

If you child window completely fill the parent window (and that's where the issue is most likely to happen) then there's no value in using a child window. What's your actual setup?

@Teselka
Copy link
Contributor Author

Teselka commented Nov 29, 2024

If you child window completely fill the parent window (and that's where the issue is most likely to happen) then there's no value in using a child window. What's your actual setup?

It'a sidebar menu in my use case

image

@ocornut
Copy link
Owner

ocornut commented Nov 29, 2024

I realize it is not ideal, but the easiest way at the moment would be to "undo" the current offset in the parent window and then submit the child with padding:

ImGui::SetCursorPos(GetCursorPos() - style.WindowPadding);
ImGui::BeginChild(...., ImGuiChildFlags_AlwaysUseWindowPadding)

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

No branches or pull requests

2 participants