From ef3f87eec587179c0a82634f481412e25c707d15 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 17 Oct 2017 23:31:17 +0200 Subject: [PATCH] Internals: ButtonBehavior: made ImGuiButtonFlags_PressedOnClick and ImGuiButtonFlags_PressedOnDoubleClick set the click offset correctly + hold on g.ActiveId so Held state can be reported. Added ImGuiButtonFlags_NoHoldingActiveId flag to disable the later. --- imgui.cpp | 8 ++++++-- imgui_internal.h | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 445bba37b..51f7f3f5e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5777,8 +5777,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) { pressed = true; - ClearActiveID(); + if (flags & ImGuiButtonFlags_NoHoldingActiveID) + ClearActiveID(); + else + SetActiveID(id, window); // Hold on ID FocusWindow(window); + g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; } if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) { @@ -8851,7 +8855,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl } ImGuiButtonFlags button_flags = 0; - if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick; + if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_NoHoldingActiveID; if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnRelease; if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; if (flags & ImGuiSelectableFlags_AllowDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick; diff --git a/imgui_internal.h b/imgui_internal.h index 2d3b37391..7edcd9028 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -178,9 +178,10 @@ enum ImGuiButtonFlags_ ImGuiButtonFlags_FlattenChilds = 1 << 5, // allow interactions even if a child window is overlapping ImGuiButtonFlags_DontClosePopups = 1 << 6, // disable automatically closing parent popup on press // [UNUSED] ImGuiButtonFlags_Disabled = 1 << 7, // disable interactions - ImGuiButtonFlags_AlignTextBaseLine = 1 << 8, // vertically align button to match text baseline - ButtonEx() only + ImGuiButtonFlags_AlignTextBaseLine = 1 << 8, // vertically align button to match text baseline (ButtonEx() only) ImGuiButtonFlags_NoKeyModifiers = 1 << 9, // disable interaction if a key modifier is held - ImGuiButtonFlags_AllowOverlapMode = 1 << 10 // require previous frame HoveredId to either match id or be null before being usable + ImGuiButtonFlags_AllowOverlapMode = 1 << 10, // require previous frame HoveredId to either match id or be null before being usable + ImGuiButtonFlags_NoHoldingActiveID = 1 << 11 // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) }; enum ImGuiSliderFlags_