From 0e46d65b031ea796439d9df2c43215d51b625d44 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 18 Apr 2019 15:35:20 +0200 Subject: [PATCH] Misc: Fixed PushItemWidth(-width) (for right-side alignment) laying out certain items (button, listbox, etc.) with negative sizes if the 'width' argument was smaller than the available width at the time of item submission, --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c9401b3a4..511e381c9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -53,6 +53,8 @@ Other Changes: - Window: Window close button is horizontally aligned with style.FramePadding.x. - Columns: Fixed boundary of clipping being off by 1 pixel within the left column. - Combo, Slider, Scrollbar: Improve rendering in situation when there's only a few pixels available (<3 pixels). +- Misc: Fixed PushItemWidth(-width) (for right-side alignment) laying out certain items (button, listbox, etc.) + with negative sizes if the 'width' argument was smaller than the available width at the time of item submission, - Misc: Added IM_MALLOC/IM_FREE macros mimicking IM_NEW/IM_DELETE so user doesn't need to revert to using the ImGui::MemAlloc()/MemFree() calls directly. - Metrics: Added "Show windows rectangles" tool to visualize the different rectangles. diff --git a/imgui.cpp b/imgui.cpp index 02d7ad9f7..2b4b7a830 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5789,6 +5789,7 @@ float ImGui::CalcItemWidth() // [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth(). // Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical. // Note that only CalcItemWidth() is publicly exposed. +// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable) ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) { ImGuiWindow* window = GImGui->CurrentWindow; @@ -5800,12 +5801,12 @@ ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) if (size.x == 0.0f) size.x = default_w; else if (size.x < 0.0f) - size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x) + size.x; + size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x + size.x); if (size.y == 0.0f) size.y = default_h; else if (size.y < 0.0f) - size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y) + size.y; + size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y + size.y); return size; }