From f8b7d5c76d114dc86366200199d6b48bbfe98316 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 27 May 2015 22:53:43 +0100 Subject: [PATCH] Tracking ActiveIdWindow along with ActiveId --- imgui.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ea70d592..fe182ea2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1250,8 +1250,9 @@ struct ImGuiState ImGuiID ActiveId; // Active widget ImGuiID ActiveIdPreviousFrame; bool ActiveIdIsAlive; - bool ActiveIdIsJustActivated; // Set when - bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction. + bool ActiveIdIsJustActivated; // Set at the time of activation for one frame + bool ActiveIdIsFocusedOnly; // Set only by active widget. Denote focus but no active interaction + ImGuiWindow* ActiveIdWindow; ImGuiWindow* MovedWindow; // Track the child window we clicked on to move a window. Only valid if ActiveID is the "#MOVE" identifier of a window. float SettingsDirtyTimer; ImVector Settings; @@ -1466,12 +1467,13 @@ static inline ImGuiWindow* GetParentWindow() return g.CurrentWindowStack[g.CurrentWindowStack.size() - 2]; } -static void SetActiveId(ImGuiID id) +static void SetActiveId(ImGuiID id, ImGuiWindow* window = NULL) { ImGuiState& g = *GImGui; g.ActiveId = id; g.ActiveIdIsFocusedOnly = false; g.ActiveIdIsJustActivated = true; + g.ActiveIdWindow = window; } static void RegisterAliveId(ImGuiID id) @@ -2379,7 +2381,7 @@ void ImGui::Render() { IM_ASSERT(g.MovedWindow == NULL); g.MovedWindow = g.HoveredWindow; - SetActiveId(g.HoveredRootWindow->MoveID); + SetActiveId(g.HoveredRootWindow->MoveID, g.HoveredRootWindow); } else if (g.FocusedWindow != NULL) { @@ -4887,7 +4889,7 @@ static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } else { - SetActiveId(id); + SetActiveId(id, window); } FocusWindow(window); } @@ -5537,7 +5539,7 @@ static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int char text_buf[64]; ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v); - SetActiveId(g.ScalarAsInputTextId); + SetActiveId(g.ScalarAsInputTextId, window); g.HoveredId = 0; // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen) @@ -5767,7 +5769,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) { - SetActiveId(id); + SetActiveId(id, window); FocusWindow(window); const bool is_ctrl_down = g.IO.KeyCtrl; @@ -5825,7 +5827,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float if (hovered && g.IO.MouseClicked[0]) { - SetActiveId(id); + SetActiveId(id, window); FocusWindow(window); } @@ -6071,7 +6073,7 @@ bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, f const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] | g.IO.MouseDoubleClicked[0]))) { - SetActiveId(id); + SetActiveId(id, window); FocusWindow(window); if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0]) @@ -6855,16 +6857,14 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT if (focus_requested_by_tab || (user_clicked && is_ctrl_down)) select_all = true; } - SetActiveId(id); + SetActiveId(id, window); FocusWindow(window); } else if (io.MouseClicked[0]) { // Release focus when we click outside if (g.ActiveId == id) - { SetActiveId(0); - } } // Although we are active we don't prevent mouse from hovering other elements unless we are interacting right now with the widget.