diff --git a/imgui.cpp b/imgui.cpp index 3c6ade3..2f46ee4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -992,6 +992,7 @@ ImGuiID ActiveId; ImGuiID ActiveIdPreviousFrame; bool ActiveIdIsAlive; + bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction. float SettingsDirtyTimer; ImVector Settings; ImVector ColorModifiers; @@ -1046,6 +1047,7 @@ ActiveId = 0; ActiveIdPreviousFrame = 0; ActiveIdIsAlive = false; + ActiveIdIsFocusedOnly = false; SettingsDirtyTimer = 0.0f; SetNextWindowPosVal = ImVec2(0.0f, 0.0f); SetNextWindowPosCond = 0; @@ -1149,6 +1151,7 @@ { ImGuiState& g = *GImGui; g.ActiveId = id; + g.ActiveIdIsFocusedOnly = false; } static void RegisterAliveId(const ImGuiID& id) @@ -3791,8 +3794,11 @@ if (g.HoveredId == 0) { ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.ActiveId == 0 || g.ActiveId == id) && IsMouseHoveringBox(bb); - return hovered; + if (g.HoveredRootWindow == window->RootWindow) + { + bool hovered = (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdIsFocusedOnly) && IsMouseHoveringBox(bb); + return hovered; + } } return false; } @@ -4516,20 +4522,14 @@ if (g.SliderAsInputTextId == 0) { // First frame - IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both which is also possible) + IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible) g.SliderAsInputTextId = g.ActiveId; - SetActiveId(id); g.HoveredId = id; } - else + else if (g.ActiveId != g.SliderAsInputTextId) { - if (g.ActiveId == g.SliderAsInputTextId) - SetActiveId(id); - else - { - SetActiveId(0); - g.SliderAsInputTextId = 0; - } + // Release + g.SliderAsInputTextId = 0; } if (value_changed) { @@ -5379,6 +5379,11 @@ } } + // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget. + // Down the line we should have a cleaner concept of focused vs active in the library. + if (g.ActiveId == id) + g.ActiveIdIsFocusedOnly = !io.MouseDown[0]; + bool value_changed = false; bool cancel_edit = false; bool enter_pressed = false;