You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (ImGui::IsKeyDown(ImGuiMod_Alt)) // Poll on Active: we don't need to check for ownership of ImGuiMod_Alt since we know we unconditionally own it.
8094
+
spinner0 += io.MouseDelta.x;
8095
+
}
8096
+
8097
+
// When using of keys is conditioned by item being hovered or active,
8098
+
// it creates a natural exclusivity, since only one item can be hovered or active.
8099
+
// SetItemKeyOwner(...) is a shortcut for doing 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(..., GetItemID()); }'
8100
+
static int value1 = 0;
8101
+
ImGui::Text("%d", value1);
8102
+
ImGui::SameLine();
8103
+
HelpMarker("Item1 claims ALT key when Hovered or Active, counter increase when pressing ALT while Hovered.");
8104
+
ImGui::Button("Item1", button_sz);
8105
+
ImGui::SetItemKeyOwner(ImGuiMod_Alt); // Claim Alt on Hover and Active
8106
+
if (ImGui::IsItemHovered() && ImGui::IsKeyPressed(ImGuiMod_Alt, false)) // Poll on Hover: we don't need to check for ownership of ImGuiMod_Alt since we know we unconditionally own it.
8107
+
value1++;
8108
+
8109
+
ImGui::TreePop();
8110
+
}
8111
+
8112
+
// Routing options are only available for Shortcuts (not Key)
8113
+
// Using shortcut functions with only ImGuiMod_Alt means that other modifiers e.g. CTRL+ALT+S won't be affected, which is often desirable.
8114
+
// Here we use ImGuiInputFlags_RouteFocused which will claim the Alt shortcut when the window is focused.
8115
+
// Notice that opening this node will claim Alt, therefore change the behavior of the key checks in section (2) above.
8116
+
if (ImGui::TreeNode("3. Claiming Alt shortcut"))
8117
+
{
8118
+
// Using Shortcut() with ImGuiInputFlags_RouteFocused means we react when parent window is focused.
8119
+
// - Passing 0 (== ImGuiKeyOwner_Any) means current location will be used to identify.
8120
+
// As both calls are from the same location, both items will receive the shortcut.
8121
+
// - Passing GetItemID() here means they both have their unique id,
8122
+
// - Item2 will only receive the shortcut when parent window is focused.
8123
+
// - Item3 will only receive the shortcut when active.
8124
+
// Not passing an item id would use current location as id so both items will always receive shortcut.
8125
+
static bool use_shared_owner = false;
8126
+
ImGui::Checkbox("Item2 and Item3 use same owner/location", &use_shared_owner);
8127
+
static int value2 = 0;
8128
+
ImGui::Text("%d", value2);
8129
+
ImGui::SameLine();
8130
+
HelpMarker("Item2 reads ALT shortcut when its parent window is focused.");
8131
+
ImGui::Button("Item2", button_sz);
8132
+
if (ImGui::Shortcut(ImGuiMod_Alt, 0, use_shared_owner ? 0 : ImGui::GetItemID()))
8133
+
value2++;
8134
+
8135
+
static int value3 = 0;
8136
+
ImGui::Text("%d", value3);
8137
+
ImGui::SameLine();
8138
+
HelpMarker("Item3 reads ALT shortcut when its parent window is focused AND it is active. Therefore, only active previous button will get the shortcut");
8139
+
ImGui::Button("Item3", button_sz);
8140
+
if (ImGui::Shortcut(ImGuiMod_Alt, 0, use_shared_owner ? 0 : ImGui::GetItemID()))
8141
+
value3++;
8142
+
8143
+
ImGui::TreePop();
8144
+
}
8145
+
8146
+
if (ImGui::TreeNode("4. Claiming Home key globally"))
// Disable CTRL+Tab shortcuts (if focused): assign an owner to steal the route to our two shortcuts, applies focus testing so will only apply if window is in focus chain
// Read CTRL+Tab (global): reading keys without interfering with any behaviors (need to specify ImGuiInputFlags_RouteAlways as other policies will interfere)
8257
+
if (ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_Tab, ImGuiInputFlags_RouteAlways, ImGuiKeyOwner_Any))
8258
+
counter++;
8259
+
if (ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiMod_Shift | ImGuiKey_Tab, ImGuiInputFlags_RouteAlways, ImGuiKeyOwner_Any))
8260
+
counter--;
8261
+
break;
8262
+
case 6:
8263
+
{
8264
+
// Replace CTRL+Tab (global)
8265
+
// - We steal the route and assign it to our ID (so core system won't access it). Our reading queries now need to specify that ID.
0 commit comments