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

When ImGuiChildFlags_AlwaysUseWindowPadding is enabled, the left and right padding widths of the Child are different, but the Parent window is the same #7540

Closed
o-3-o opened this issue Apr 29, 2024 · 5 comments
Labels

Comments

@o-3-o
Copy link

o-3-o commented Apr 29, 2024

Version/Branch of Dear ImGui:

Version 1.90.6 WIP, Branch: docking (master/docking/etc.)

Back-ends:

imgui_impl_Win32.cpp + imgui_impl_DX11.cpp

Compiler, OS:

Win11 + MSVC 2022

Full config/build information:

Dear ImGui 1.90.6 WIP (19052)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: IMGUI_DISABLE_OBSOLETE_KEYIO
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x0000C443
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
 DpiEnableScaleViewports
 DpiEnableScaleFonts
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDecoration
io.ConfigViewportsNoDefaultParent
io.ConfigDockingTransparentPayload
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 3440.00,1392.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: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

When [ImGuiChildFlags_AlwaysUseWindowPadding] is enabled, the left and right padding widths of the Child are different, but the Parent window is the same

Screenshots/Video:

20240430014257

Minimal, Complete and Verifiable Example code:

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20.0f, 20.0f));
ImGui::Begin("fafafaefaefe");
	ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(204, 205, 209, 255));
	ImGui::BeginChild("##Container", ImVec2(0.0f, 0.0f), ImGuiChildFlags_AlwaysUseWindowPadding);
		ImGui::Button("fafafqwfwqfqwfwqfe");
	ImGui::EndChild();
	ImGui::PopStyleColor();
ImGui::End();
ImGui::PopStyleVar();
@cfillion
Copy link
Contributor

cfillion commented Apr 29, 2024

The inner clipping rectangle of all windows (child or not) is always larger than the padding (by half).

The actual padding is the same on the left and right sides, which you can observe by setting ImGuiChildFlags_AutoResizeX. Or "Show window rectangles" in ShowMetricsWindow() under "Tools".

ImVec2(0.0f, 0.0f) makes the child window use all available width in the work rectangle which includes the full padding.

imgui/imgui.cpp

Lines 6824 to 6836 in a60387a

// Inner clipping rectangle.
// Will extend a little bit outside the normal work region.
// This is to allow e.g. Selectable or CollapsingHeader or some separators to cover that space.
// Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result.
// Note that if our window is collapsed we will end up with an inverted (~null) clipping rectangle which is the correct behavior.
// Affected by window/frame border size. Used by:
// - Begin() initial clip rect
float top_border_size = (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize);
window->InnerClipRect.Min.x = ImTrunc(0.5f + window->InnerRect.Min.x + ImMax(ImTrunc(window->WindowPadding.x * 0.5f), window->WindowBorderSize));
window->InnerClipRect.Min.y = ImTrunc(0.5f + window->InnerRect.Min.y + top_border_size);
window->InnerClipRect.Max.x = ImTrunc(0.5f + window->InnerRect.Max.x - ImMax(ImTrunc(window->WindowPadding.x * 0.5f), window->WindowBorderSize));
window->InnerClipRect.Max.y = ImTrunc(0.5f + window->InnerRect.Max.y - window->WindowBorderSize);
window->InnerClipRect.ClipWithFull(host_rect);

@o-3-o
Copy link
Author

o-3-o commented Apr 30, 2024

Thanks for @cfillion answer, now I realize that it is always larger than the padding (by half). It was a visual misunderstanding.

@o-3-o
Copy link
Author

o-3-o commented Apr 30, 2024

can solve this visual problem by using PushClipRect to limit it yourself.

ImGui::PushClipRect(ImGui::GetCurrentWindow()->Pos + ImGui::GetStyle().WindowPadding, ImGui::GetCurrentWindow()->Pos - ImGui::GetStyle().WindowPadding + ImGui::GetCurrentWindow()->Size, false);
//...
ImGui::PopClipRect();
QQ截图20240430112925

@ocornut ocornut added the layout label Apr 30, 2024
@ocornut
Copy link
Owner

ocornut commented Apr 30, 2024

Linking to #3312 as I've been considering changing this and make the clip rect fill entire inner rect. I'll post here too if this changes.

@ocornut ocornut changed the title When [ImGuiChildFlags_AlwaysUseWindowPadding] is enabled, the left and right padding widths of the Child are different, but the Parent window is the same When ImGuiChildFlags_AlwaysUseWindowPadding is enabled, the left and right padding widths of the Child are different, but the Parent window is the same Apr 30, 2024
@ocornut
Copy link
Owner

ocornut commented May 3, 2024

I went and pushed the change discussed in #3312 I think it's for the best 0b30947
Also generally makes it easier to draw stuff in edge of windows without requiring a clip rect change.

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

3 participants