diff --git a/imgui.cpp b/imgui.cpp index c60c1d9..c7b16b2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1858,7 +1858,7 @@ return g.CurrentWindowStack[(unsigned int)g.CurrentWindowStack.Size - 2]; } -void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL) +void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; g.ActiveId = id; @@ -1869,6 +1869,11 @@ g.ActiveIdWindow = window; } +void ImGui::ClearActiveID() +{ + SetActiveID(0, NULL); +} + void ImGui::SetHoveredID(ImGuiID id) { ImGuiContext& g = *GImGui; @@ -2204,7 +2209,7 @@ g.HoveredId = 0; g.HoveredIdAllowOverlap = false; if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) - SetActiveID(0); + ClearActiveID(); g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; g.ActiveIdIsJustActivated = false; @@ -2227,7 +2232,7 @@ } else { - SetActiveID(0); + ClearActiveID(); g.MovedWindow = NULL; g.MovedWindowMoveId = 0; } @@ -4214,7 +4219,7 @@ ApplySizeFullWithConstraint(window, size_auto_fit); if (!(flags & ImGuiWindowFlags_NoSavedSettings)) MarkIniSettingsDirty(); - SetActiveID(0); + ClearActiveID(); } else if (held) { @@ -4563,7 +4568,7 @@ // Steal focus on active widgets if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window) - SetActiveID(0); + ClearActiveID(); // Bring to front if ((window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) || g.Windows.back() == window) @@ -5536,7 +5541,7 @@ { if (out_hovered) *out_hovered = false; if (out_held) *out_held = false; - if (g.ActiveId == id) SetActiveID(0); + if (g.ActiveId == id) ClearActiveID(); return false; } @@ -5564,14 +5569,14 @@ if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) { pressed = true; - SetActiveID(0); + ClearActiveID(); FocusWindow(window); } if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) { if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). @@ -5593,7 +5598,7 @@ if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease)) if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } } @@ -6558,7 +6563,7 @@ } else { - SetActiveID(0); + ClearActiveID(); } } @@ -6874,7 +6879,7 @@ } else { - SetActiveID(0); + ClearActiveID(); } } @@ -7777,7 +7782,7 @@ { // Release focus when we click outside if (g.ActiveId == id) - SetActiveID(0); + ClearActiveID(); } bool value_changed = false; @@ -7879,7 +7884,7 @@ bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) { - SetActiveID(0); + ClearActiveID(); enter_pressed = true; } else if (is_editable) @@ -7895,7 +7900,7 @@ if (InputTextFilterCharacter(&c, flags, callback, user_data)) edit_state.OnKeyPressed((int)c); } - else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveID(0); cancel_edit = true; } + else if (IsKeyPressedMap(ImGuiKey_Escape)) { ClearActiveID(); cancel_edit = true; } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Z) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Y) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); edit_state.CursorFollow = true; } @@ -8490,7 +8495,7 @@ SetHoveredID(id); if (g.IO.MouseClicked[0]) { - SetActiveID(0); + ClearActiveID(); if (IsPopupOpen(id)) { ClosePopup(id); @@ -8539,7 +8544,7 @@ item_text = "*Unknown item*"; if (Selectable(item_text, item_selected)) { - SetActiveID(0); + ClearActiveID(); value_changed = true; *current_item = i; } diff --git a/imgui.cpp b/imgui.cpp index c60c1d9..c7b16b2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1858,7 +1858,7 @@ return g.CurrentWindowStack[(unsigned int)g.CurrentWindowStack.Size - 2]; } -void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL) +void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; g.ActiveId = id; @@ -1869,6 +1869,11 @@ g.ActiveIdWindow = window; } +void ImGui::ClearActiveID() +{ + SetActiveID(0, NULL); +} + void ImGui::SetHoveredID(ImGuiID id) { ImGuiContext& g = *GImGui; @@ -2204,7 +2209,7 @@ g.HoveredId = 0; g.HoveredIdAllowOverlap = false; if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) - SetActiveID(0); + ClearActiveID(); g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; g.ActiveIdIsJustActivated = false; @@ -2227,7 +2232,7 @@ } else { - SetActiveID(0); + ClearActiveID(); g.MovedWindow = NULL; g.MovedWindowMoveId = 0; } @@ -4214,7 +4219,7 @@ ApplySizeFullWithConstraint(window, size_auto_fit); if (!(flags & ImGuiWindowFlags_NoSavedSettings)) MarkIniSettingsDirty(); - SetActiveID(0); + ClearActiveID(); } else if (held) { @@ -4563,7 +4568,7 @@ // Steal focus on active widgets if (window->Flags & ImGuiWindowFlags_Popup) // FIXME: This statement should be unnecessary. Need further testing before removing it.. if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != window) - SetActiveID(0); + ClearActiveID(); // Bring to front if ((window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) || g.Windows.back() == window) @@ -5536,7 +5541,7 @@ { if (out_hovered) *out_hovered = false; if (out_held) *out_held = false; - if (g.ActiveId == id) SetActiveID(0); + if (g.ActiveId == id) ClearActiveID(); return false; } @@ -5564,14 +5569,14 @@ if (((flags & ImGuiButtonFlags_PressedOnClick) && g.IO.MouseClicked[0]) || ((flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDoubleClicked[0])) { pressed = true; - SetActiveID(0); + ClearActiveID(); FocusWindow(window); } if ((flags & ImGuiButtonFlags_PressedOnRelease) && g.IO.MouseReleased[0]) { if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). @@ -5593,7 +5598,7 @@ if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease)) if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps pressed = true; - SetActiveID(0); + ClearActiveID(); } } @@ -6558,7 +6563,7 @@ } else { - SetActiveID(0); + ClearActiveID(); } } @@ -6874,7 +6879,7 @@ } else { - SetActiveID(0); + ClearActiveID(); } } @@ -7777,7 +7782,7 @@ { // Release focus when we click outside if (g.ActiveId == id) - SetActiveID(0); + ClearActiveID(); } bool value_changed = false; @@ -7879,7 +7884,7 @@ bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) { - SetActiveID(0); + ClearActiveID(); enter_pressed = true; } else if (is_editable) @@ -7895,7 +7900,7 @@ if (InputTextFilterCharacter(&c, flags, callback, user_data)) edit_state.OnKeyPressed((int)c); } - else if (IsKeyPressedMap(ImGuiKey_Escape)) { SetActiveID(0); cancel_edit = true; } + else if (IsKeyPressedMap(ImGuiKey_Escape)) { ClearActiveID(); cancel_edit = true; } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Z) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_UNDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_Y) && is_editable) { edit_state.OnKeyPressed(STB_TEXTEDIT_K_REDO); edit_state.ClearSelection(); } else if (is_shortcut_key_only && IsKeyPressedMap(ImGuiKey_A)) { edit_state.SelectAll(); edit_state.CursorFollow = true; } @@ -8490,7 +8495,7 @@ SetHoveredID(id); if (g.IO.MouseClicked[0]) { - SetActiveID(0); + ClearActiveID(); if (IsPopupOpen(id)) { ClosePopup(id); @@ -8539,7 +8544,7 @@ item_text = "*Unknown item*"; if (Selectable(item_text, item_selected)) { - SetActiveID(0); + ClearActiveID(); value_changed = true; *current_item = i; } diff --git a/imgui_internal.h b/imgui_internal.h index ff188b0..5e18984 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -710,6 +710,7 @@ IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead! IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window); + IMGUI_API void ClearActiveID(); IMGUI_API void SetHoveredID(ImGuiID id); IMGUI_API void KeepAliveID(ImGuiID id);