From 526e2303bc1bfec7ca98e1328c15ce835cb47bc5 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 May 2019 19:09:44 +0200 Subject: [PATCH] Window: Fixed SetNextWindowSizeConstraints() with non-rounded positions making windows drift. (#2067, #2530) --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 ++ imgui.h | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8b26cab7e..514c5d3cf 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -68,6 +68,7 @@ Other Changes: highlight from parent menu items earlier than necessary while approaching the child menu. - Window: Close button is horizontally aligned with style.FramePadding.x. - Window: Fixed contents region being off by WindowBorderSize amount on the right when scrollbar is active. +- Window: Fixed SetNextWindowSizeConstraints() with non-rounded positions making windows drift. (#2067, 2530) - Popups: Closing a popup restores the focused/nav window in place at the time of the popup opening, instead of restoring the window that was in the window stack at the time of the OpenPopup call. (#2517) Among other things, this allows opening a popup while no window are focused, and pressing Escape to diff --git a/imgui.cpp b/imgui.cpp index 19c0906bd..68ac63acb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4648,6 +4648,8 @@ static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size) g.NextWindowData.SizeCallback(&data); new_size = data.DesiredSize; } + new_size.x = ImFloor(new_size.x); + new_size.y = ImFloor(new_size.y); } // Minimum size diff --git a/imgui.h b/imgui.h index 17d9d4c39..774c1b51d 100644 --- a/imgui.h +++ b/imgui.h @@ -269,7 +269,7 @@ namespace ImGui // Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin). IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0, const ImVec2& pivot = ImVec2(0,0)); // set next window position. call before Begin(). use pivot=(0.5f,0.5f) to center on given point, etc. IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin() - IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints. + IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_callback = NULL, void* custom_callback_data = NULL); // set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Sizes will be rounded down. Use callback to apply non-trivial programmatic constraints. IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ enforce the range of scrollbars). not including window decorations (title bar, menu bar, etc.). set an axis to 0.0f to leave it automatic. call before Begin() IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()