Skip to content

Commit

Permalink
Internals: move ItemHandleShortcut() next to Shortcut(), it's calling…
Browse files Browse the repository at this point in the history
… it anyhow. (#456)
  • Loading branch information
ocornut committed May 23, 2024
1 parent a689fa2 commit 0eb025f
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9687,6 +9687,28 @@ void ImGui::SetNextItemShortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags)
g.NextItemData.ShortcutFlags = flags;
}

void ImGui::ItemHandleShortcut(ImGuiID id)
{
ImGuiContext& g = *GImGui;
ImGuiInputFlags flags = g.NextItemData.ShortcutFlags;
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedBySetNextItemShortcut) == 0); // Passing flags not supported by SetNextItemShortcut()!

if (flags & ImGuiInputFlags_Tooltip)
{
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HasShortcut;
g.LastItemData.Shortcut = g.NextItemData.Shortcut;
}
if (!Shortcut(g.NextItemData.Shortcut, flags & ImGuiInputFlags_SupportedByShortcut, id) || g.NavActivateId != 0)
return;

// FIXME: Generalize Activation queue?
g.NavActivateId = id; // Will effectively disable clipping.
g.NavActivateFlags = ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_FromShortcut;
//if (g.ActiveId == 0 || g.ActiveId == id)
g.NavActivateDownId = g.NavActivatePressedId = id;
NavHighlightActivated(id);
}

bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags)
{
return Shortcut(key_chord, flags, ImGuiKeyOwner_Any);
Expand Down Expand Up @@ -10004,7 +10026,6 @@ void ImGuiStackSizes::CompareWithContextState(ImGuiContext* ctx)
// [SECTION] ITEM SUBMISSION
//-----------------------------------------------------------------------------
// - KeepAliveID()
// - ItemHandleShortcut() [Internal]
// - ItemAdd()
//-----------------------------------------------------------------------------

Expand All @@ -10018,28 +10039,6 @@ void ImGui::KeepAliveID(ImGuiID id)
g.ActiveIdPreviousFrameIsAlive = true;
}

void ImGui::ItemHandleShortcut(ImGuiID id)
{
ImGuiContext& g = *GImGui;
ImGuiInputFlags flags = g.NextItemData.ShortcutFlags;
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedBySetNextItemShortcut) == 0); // Passing flags not supported by SetNextItemShortcut()!

if (flags & ImGuiInputFlags_Tooltip)
{
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HasShortcut;
g.LastItemData.Shortcut = g.NextItemData.Shortcut;
}
if (!Shortcut(g.NextItemData.Shortcut, flags & ImGuiInputFlags_SupportedByShortcut, id) || g.NavActivateId != 0)
return;

// FIXME: Generalize Activation queue?
g.NavActivateId = id; // Will effectively disable clipping.
g.NavActivateFlags = ImGuiActivateFlags_PreferInput | ImGuiActivateFlags_FromShortcut;
//if (g.ActiveId == 0 || g.ActiveId == id)
g.NavActivateDownId = g.NavActivatePressedId = id;
NavHighlightActivated(id);
}

// Declare item bounding box for clipping and interaction.
// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
// declare their minimum size requirement to ItemSize() and provide a larger region to ItemAdd() which is used drawing/interaction.
Expand Down

0 comments on commit 0eb025f

Please sign in to comment.