From a908c109c09cbb54962bb5b3a5056c188fe260e7 Mon Sep 17 00:00:00 2001 From: Nikolay Zapolnov Date: Sun, 31 Jan 2016 22:08:35 +0100 Subject: [PATCH 1/2] Added flag for selectables to handle double clicks. --- imgui.cpp | 7 ++++++- imgui.h | 3 ++- imgui_demo.cpp | 7 ++++++- imgui_internal.h | 25 +++++++++++++------------ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8f55e6bf..22300c3e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5222,7 +5222,11 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool SetHoveredID(id); if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) { - if (g.IO.MouseClicked[0]) + if (g.IO.MouseDoubleClicked[0] && (flags & ImGuiButtonFlags_PressedOnDoubleClick)) + { + pressed = true; + } + else if (g.IO.MouseClicked[0]) { if (flags & ImGuiButtonFlags_PressedOnClick) { @@ -8135,6 +8139,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick; if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnClick|ImGuiButtonFlags_PressedOnRelease; if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; + if (flags & ImGuiSelectableFlags_HandleDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnDoubleClick; bool hovered, held; bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, button_flags); if (flags & ImGuiSelectableFlags_Disabled) diff --git a/imgui.h b/imgui.h index a6a249d0..ba3ba9a5 100644 --- a/imgui.h +++ b/imgui.h @@ -504,7 +504,8 @@ enum ImGuiSelectableFlags_ { // Default: 0 ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window - ImGuiSelectableFlags_SpanAllColumns = 1 << 1 // Selectable frame can span all columns (text will still fit in current column) + ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) + ImGuiSelectableFlags_HandleDoubleClick = 1 << 2 // Generate press events on double clicks too }; // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 46883706..26d33ead 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -392,11 +392,16 @@ void ImGui::ShowTestWindow(bool* p_opened) { if (ImGui::TreeNode("Basic")) { - static bool selected[3] = { false, true, false }; + static bool selected[4] = { false, true, false, false }; ImGui::Selectable("1. I am selectable", &selected[0]); ImGui::Selectable("2. I am selectable", &selected[1]); ImGui::Text("3. I am not selectable"); ImGui::Selectable("4. I am selectable", &selected[2]); + if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_HandleDoubleClick)) + { + if (ImGui::IsMouseDoubleClicked(0)) + selected[3] = !selected[3]; + } ImGui::TreePop(); } if (ImGui::TreeNode("Rendering more text into the same block")) diff --git a/imgui_internal.h b/imgui_internal.h index c8748ada..b3c84e66 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -152,14 +152,15 @@ inline void operator delete(void*, ImPlacementNewDummy, void*) {} enum ImGuiButtonFlags_ { - ImGuiButtonFlags_Repeat = 1 << 0, - ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release) - ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release) - ImGuiButtonFlags_FlattenChilds = 1 << 3, - ImGuiButtonFlags_DontClosePopups = 1 << 4, - ImGuiButtonFlags_Disabled = 1 << 5, - ImGuiButtonFlags_AlignTextBaseLine = 1 << 6, - ImGuiButtonFlags_NoKeyModifiers = 1 << 7 + ImGuiButtonFlags_Repeat = 1 << 0, + ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release) + ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release) + ImGuiButtonFlags_FlattenChilds = 1 << 3, + ImGuiButtonFlags_DontClosePopups = 1 << 4, + ImGuiButtonFlags_Disabled = 1 << 5, + ImGuiButtonFlags_AlignTextBaseLine = 1 << 6, + ImGuiButtonFlags_NoKeyModifiers = 1 << 7, + ImGuiButtonFlags_PressedOnDoubleClick = 1 << 8 }; enum ImGuiTreeNodeFlags_ @@ -176,10 +177,10 @@ enum ImGuiSliderFlags_ enum ImGuiSelectableFlagsPrivate_ { // NB: need to be in sync with last value of ImGuiSelectableFlags_ - ImGuiSelectableFlags_Menu = 1 << 2, - ImGuiSelectableFlags_MenuItem = 1 << 3, - ImGuiSelectableFlags_Disabled = 1 << 4, - ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 5 + ImGuiSelectableFlags_Menu = 1 << 3, + ImGuiSelectableFlags_MenuItem = 1 << 4, + ImGuiSelectableFlags_Disabled = 1 << 5, + ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 6 }; // FIXME: this is in development, not exposed/functional as a generic feature yet. From b816d05e337f6bfbf05ec98702c5f11356b00ff6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 3 Mar 2016 00:30:08 +0100 Subject: [PATCH 2/2] Minor tidying up following (#516) - renamed ImGuiSelectableFlags_HandleDoubleClick to ImGuiSelectableFlags_AllowDoubleClick + comments --- imgui.cpp | 2 +- imgui.h | 2 +- imgui_demo.cpp | 4 +--- imgui_internal.h | 18 +++++++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8e8ab2b6..50b0219a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8147,7 +8147,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (flags & ImGuiSelectableFlags_Menu) button_flags |= ImGuiButtonFlags_PressedOnClick; if (flags & ImGuiSelectableFlags_MenuItem) button_flags |= ImGuiButtonFlags_PressedOnClick|ImGuiButtonFlags_PressedOnRelease; if (flags & ImGuiSelectableFlags_Disabled) button_flags |= ImGuiButtonFlags_Disabled; - if (flags & ImGuiSelectableFlags_HandleDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnDoubleClick; + if (flags & ImGuiSelectableFlags_AllowDoubleClick) button_flags |= ImGuiButtonFlags_PressedOnDoubleClick; bool hovered, held; bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, button_flags); if (flags & ImGuiSelectableFlags_Disabled) diff --git a/imgui.h b/imgui.h index 27a8ce95..57a7f797 100644 --- a/imgui.h +++ b/imgui.h @@ -506,7 +506,7 @@ enum ImGuiSelectableFlags_ // Default: 0 ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) - ImGuiSelectableFlags_HandleDoubleClick = 1 << 2 // Generate press events on double clicks too + ImGuiSelectableFlags_AllowDoubleClick = 1 << 2 // Generate press events on double clicks too }; // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 47e97526..b2e4e09e 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -397,11 +397,9 @@ void ImGui::ShowTestWindow(bool* p_opened) ImGui::Selectable("2. I am selectable", &selected[1]); ImGui::Text("3. I am not selectable"); ImGui::Selectable("4. I am selectable", &selected[2]); - if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_HandleDoubleClick)) - { + if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick)) if (ImGui::IsMouseDoubleClicked(0)) selected[3] = !selected[3]; - } ImGui::TreePop(); } if (ImGui::TreeNode("Rendering more text into the same block")) diff --git a/imgui_internal.h b/imgui_internal.h index 51d97093..eaeb312e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -152,15 +152,15 @@ inline void operator delete(void*, ImPlacementNewDummy, void*) {} enum ImGuiButtonFlags_ { - ImGuiButtonFlags_Repeat = 1 << 0, - ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click only (default requires click+release) - ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release only (default requires click+release) - ImGuiButtonFlags_FlattenChilds = 1 << 3, - ImGuiButtonFlags_DontClosePopups = 1 << 4, - ImGuiButtonFlags_Disabled = 1 << 5, - ImGuiButtonFlags_AlignTextBaseLine = 1 << 6, - ImGuiButtonFlags_NoKeyModifiers = 1 << 7, - ImGuiButtonFlags_PressedOnDoubleClick = 1 << 8 + ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat + ImGuiButtonFlags_PressedOnClick = 1 << 1, // return pressed on click (default requires click+release) + ImGuiButtonFlags_PressedOnRelease = 1 << 2, // return pressed on release (default requires click+release) + ImGuiButtonFlags_PressedOnDoubleClick = 1 << 3, // return pressed on double-click (default requires click+release) + ImGuiButtonFlags_FlattenChilds = 1 << 4, // allow interaction even if a child window is overlapping + ImGuiButtonFlags_DontClosePopups = 1 << 5, // disable automatically closing parent popup on press + ImGuiButtonFlags_Disabled = 1 << 6, // disable interaction + ImGuiButtonFlags_AlignTextBaseLine = 1 << 7, // vertically align button to match text baseline - ButtonEx() only + ImGuiButtonFlags_NoKeyModifiers = 1 << 8, // disable interaction if a key modifier is held }; enum ImGuiTreeNodeFlags_