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
// This is more or less equivalent to a fancier version of:
10712
10713
// if (IsItemHovered() || IsItemActive())
10713
10714
// SetKeyOwner(key, GetItemID());
10714
10715
// Extensive uses of that (e.g. many calls for a single item) may want to manually perform the tests once and then call SetKeyOwner() multiple times.
10715
10716
// More advanced usage scenarios may want to call SetKeyOwner() manually based on different condition.
10716
10717
// Worth noting is that only one item can be hovered and only one item can be active, therefore this usage pattern doesn't need to bother with routing and priority.
Copy file name to clipboardExpand all lines: imgui.h
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1092,10 +1092,11 @@ namespace ImGui
1092
1092
// Inputs Utilities: Key/Input Ownership [BETA]
1093
1093
// - One common use case would be to allow your items to disable standard inputs behaviors such
1094
1094
// as Tab or Alt key handling, Mouse Wheel scrolling, etc.
1095
-
// e.g. Button(...); SetItemKeyOwner(ImGuiKey_MouseWheelY); to make hovering/activating a button disable wheel for scrolling.
1095
+
// e.g. `Button(...); if (SetItemKeyOwner(ImGuiKey_MouseWheelY)) { ... }` to make hovering/activating a button disable wheel for scrolling.
1096
1096
// - Reminder ImGuiKey enum include access to mouse buttons and gamepad, so key ownership can apply to them.
1097
+
// - The return value of SetItemKeyOwner() says if ownership has been requested for the item, which is a shortcut to calling yet non-public TestKeyOwner() function.
1097
1098
// - Many related features are still in imgui_internal.h. For instance, most IsKeyXXX()/IsMouseXXX() functions have an owner-id-aware version.
1098
-
IMGUI_APIvoidSetItemKeyOwner(ImGuiKey key); // Set key owner to last item ID if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
1099
+
IMGUI_APIboolSetItemKeyOwner(ImGuiKey key); // Set key owner to last item ID if it is hovered or active. Return true when ownership has been set. Roughly equivalent to 'if (TestKeyOwner(key, GetItemID()) && (IsItemHovered() || IsItemActive())) { SetKeyOwner(key, GetItemID());'.
1099
1100
1100
1101
// Inputs Utilities: Mouse
1101
1102
// - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
IMGUI_APIvoidSetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags);// Set key owner to last item if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
0 commit comments