From 5de1312e1c7e11827d8fed1fd32e9a7d7dbd9d64 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Nov 2023 15:34:30 +0100 Subject: [PATCH] SplitterBehavior: tweak to not assert due to floating point precision. Not guaranting behavior: clamping makes output lossy, size_1+size_2 in theory may be instable but couldn't repro. API probably needs rework anyhow (should redistribute from provided available space). --- imgui_widgets.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b597d27de..d347dda5d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1564,8 +1564,7 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float ImRect bb_render = bb; if (held) { - ImVec2 mouse_delta_2d = g.IO.MousePos - g.ActiveIdClickOffset - bb_interact.Min; - float mouse_delta = (axis == ImGuiAxis_Y) ? mouse_delta_2d.y : mouse_delta_2d.x; + float mouse_delta = (g.IO.MousePos - g.ActiveIdClickOffset - bb_interact.Min)[axis]; // Minimum pane size float size_1_maximum_delta = ImMax(0.0f, *size1 - min_size1); @@ -1578,12 +1577,8 @@ bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float // Apply resize if (mouse_delta != 0.0f) { - if (mouse_delta < 0.0f) - IM_ASSERT(*size1 + mouse_delta >= min_size1); - if (mouse_delta > 0.0f) - IM_ASSERT(*size2 - mouse_delta >= min_size2); - *size1 += mouse_delta; - *size2 -= mouse_delta; + *size1 = ImMax(*size1 + mouse_delta, min_size1); + *size2 = ImMax(*size2 - mouse_delta, min_size2); bb_render.Translate((axis == ImGuiAxis_X) ? ImVec2(mouse_delta, 0.0f) : ImVec2(0.0f, mouse_delta)); MarkItemEdited(id); }