From 75c46a3930278d38af988499c2aaf547b65c4b25 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 13 Nov 2023 14:53:14 +0100 Subject: [PATCH] Demo: Partly fix resizing constraint demo. (#6210, #5627) Broken by 2569c6474 --- docs/CHANGELOG.txt | 1 + imgui_demo.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 53c21b752..0bcc27e5b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -215,6 +215,7 @@ Other changes: - Demo: Added "Drag and Drop -> Tooltip at target location" demo. - Demo: Added "Layout -> Child Windows -> Manual-resize" demo. (#1710) - Demo: Added "Layout -> Child Windows -> Auto-resize with constraints" demo. (#1666, #1395, #1496, #1710) +- Demo: Partly fixed "Examples -> Constrained-resizing window" custom constrains demo. (#6210) [@cfillion] - Backends: Vulkan: Removed parameter from ImGui_ImplVulkan_CreateFontsTexture(): backend now creates its own command-buffer to upload fonts. Removed ImGui_ImplVulkan_DestroyFontUploadObjects() which is now unecessary. No need to call ImGui_ImplVulkan_CreateFontsTexture() as it is done automatically in NewFrame(). diff --git a/imgui_demo.cpp b/imgui_demo.cpp index a283fe354..2ff2cbbeb 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -7674,9 +7674,21 @@ static void ShowExampleAppConstrainedResize(bool* p_open) { // Helper functions to demonstrate programmatic constraints // FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier. - static void AspectRatio(ImGuiSizeCallbackData* data) { float aspect_ratio = *(float*)data->UserData; data->DesiredSize.x = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); } - static void Square(ImGuiSizeCallbackData* data) { data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->CurrentSize.x, data->CurrentSize.y); } - static void Step(ImGuiSizeCallbackData* data) { float step = *(float*)data->UserData; data->DesiredSize = ImVec2((int)(data->CurrentSize.x / step + 0.5f) * step, (int)(data->CurrentSize.y / step + 0.5f) * step); } + // FIXME: None of the three demos works consistently when resizing from borders. + static void AspectRatio(ImGuiSizeCallbackData* data) + { + float aspect_ratio = *(float*)data->UserData; + data->DesiredSize.y = (float)(int)(data->DesiredSize.x / aspect_ratio); + } + static void Square(ImGuiSizeCallbackData* data) + { + data->DesiredSize.x = data->DesiredSize.y = IM_MAX(data->DesiredSize.x, data->DesiredSize.y); + } + static void Step(ImGuiSizeCallbackData* data) + { + float step = *(float*)data->UserData; + data->DesiredSize = ImVec2((int)(data->DesiredSize.x / step + 0.5f) * step, (int)(data->DesiredSize.y / step + 0.5f) * step); + } }; const char* test_desc[] =