From 4faf99eff564d68bef9e43cb293c851fc489afc3 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 25 Oct 2017 09:28:54 +0200 Subject: [PATCH 1/2] Added most basic form of Disabled flag to disable interactions (but visuals aren't altered), in imgui_internals.h, undocumented/unsupported (#211, #1012) --- imgui.cpp | 6 +++++- imgui_internal.h | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 90a31c52b..c77d4d7f4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2051,6 +2051,8 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; if (!IsWindowContentHoverable(window, flags)) return false; + if (window->DC.ItemFlags & ImGuiItemFlags_Disabled) + return false; return true; } @@ -2070,6 +2072,8 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return false; if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_Default)) return false; + if (window->DC.ItemFlags & ImGuiItemFlags_Disabled) + return false; SetHoveredID(id); return true; @@ -2090,7 +2094,7 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop { ImGuiContext& g = *GImGui; - const bool allow_keyboard_focus = (window->DC.ItemFlags & ImGuiItemFlags_AllowKeyboardFocus) != 0; + const bool allow_keyboard_focus = (window->DC.ItemFlags & (ImGuiItemFlags_AllowKeyboardFocus | ImGuiItemFlags_Disabled)) == ImGuiItemFlags_AllowKeyboardFocus; window->FocusIdxAllCounter++; if (allow_keyboard_focus) window->FocusIdxTabCounter++; diff --git a/imgui_internal.h b/imgui_internal.h index 39efdb2bc..24e484121 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -582,9 +582,10 @@ enum ImGuiItemFlags_ { ImGuiItemFlags_AllowKeyboardFocus = 1 << 0, // true ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. - //ImGuiItemFlags_Disabled = 1 << 2, // false // All widgets appears are disabled - //ImGuiItemFlags_AllowNavDefaultFocus = 1 << 3, // true - ImGuiItemFlags_SelectableDontClosePopup = 1 << 4, // false // MenuItem/Selectable() automatically closes current Popup window + ImGuiItemFlags_Disabled = 1 << 2, // false // FIXME-WIP: Disable interactions but doesn't affect visuals. Should be: grey out and disable interactions with widgets that affect data + view widgets (WIP) + //ImGuiItemFlags_NoNav = 1 << 3, // false + //ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false + ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window ImGuiItemFlags_Default_ = ImGuiItemFlags_AllowKeyboardFocus }; From daef33e268264211e244e3e3294ea7e00adf29e6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 25 Oct 2017 11:01:41 +0200 Subject: [PATCH 2/2] Comments about mouse setup and clearing HoveredWindow when mouse down isn't owned by imgui (will affect some future hovered test and drag'n drop patterns) (#143, #1382, #1392) --- imgui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c77d4d7f4..2d27a79e0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2382,7 +2382,7 @@ void ImGui::NewFrame() g.ModalWindowDarkeningRatio = 0.0f; } - // Are we using inputs? Tell user so they can capture/discard the inputs away from the rest of their application. + // Update the WantCaptureMouse/WantCAptureKeyboard flags, so user can capture/discard the inputs away from the rest of their application. // When clicking outside of a window we assume the click is owned by the application and won't request capture. We need to track click ownership. int mouse_earliest_button_down = -1; bool mouse_any_down = false; @@ -2392,7 +2392,7 @@ void ImGui::NewFrame() g.IO.MouseDownOwned[i] = (g.HoveredWindow != NULL) || (!g.OpenPopupStack.empty()); mouse_any_down |= g.IO.MouseDown[i]; if (g.IO.MouseDown[i]) - if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[mouse_earliest_button_down] > g.IO.MouseClickedTime[i]) + if (mouse_earliest_button_down == -1 || g.IO.MouseClickedTime[i] < g.IO.MouseClickedTime[mouse_earliest_button_down]) mouse_earliest_button_down = i; } bool mouse_avail_to_imgui = (mouse_earliest_button_down == -1) || g.IO.MouseDownOwned[mouse_earliest_button_down]; @@ -2407,6 +2407,7 @@ void ImGui::NewFrame() g.OsImePosRequest = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. + // FIXME: For patterns of drag and drop between "application" and "imgui" we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) if (!mouse_avail_to_imgui) g.HoveredWindow = g.HoveredRootWindow = NULL;