Skip to content

Commit f9cda1f

Browse files
committed
Inputs: added SetItemKeyOwner(ImGuiKey key) in public API. (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641)
1 parent b6e313b commit f9cda1f

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

docs/CHANGELOG.txt

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ Other changes:
7777
Disabling this was previously possible for Selectable() via a direct flag but not for MenuItem().
7878
(#1379, #1468, #2200, #4936, #5216, #7302, #7573)
7979
- This was mostly all previously in imgui_internal.h.
80+
- Inputs: added SetItemKeyOwner(ImGuiKey key) in public API. This is a simplified version of a more
81+
complete set of function available in imgui_internal.h. One common use-case for this is to allow
82+
your items to disable standard inputs behaviors such as Tab or Alt handling, Mouse Wheel scrolling,
83+
etc. (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641)
84+
// Hovering or activating the button will disable mouse wheel default behavior to scroll
85+
InvisibleButton(...);
86+
SetItemKeyOwner(ImGuiKey_MouseWheelY);
8087
- Multi-Select: added multi-select API and demos. (#1861, #6518)
8188
- This system implements standard multi-selection idioms (CTRL+mouse click, CTRL+keyboard moves,
8289
SHIFT+mouse click, SHIFT+keyboard moves, etc.) with support for clipper (not submitting non-visible

imgui.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -9805,6 +9805,11 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags)
98059805
}
98069806
}
98079807

9808+
void ImGui::SetItemKeyOwner(ImGuiKey key)
9809+
{
9810+
SetItemKeyOwner(key, ImGuiInputFlags_None);
9811+
}
9812+
98089813
// This is the only public API until we expose owner_id versions of the API as replacements.
98099814
bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord)
98109815
{

imgui.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// Library Version
2929
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3030
#define IMGUI_VERSION "1.91.0 WIP"
31-
#define IMGUI_VERSION_NUM 19096
31+
#define IMGUI_VERSION_NUM 19097
3232
#define IMGUI_HAS_TABLE
3333

3434
/*
@@ -984,6 +984,14 @@ namespace ImGui
984984
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
985985
IMGUI_API void SetNextItemShortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
986986

987+
// Inputs Utilities: Key/Input Ownership [BETA]
988+
// - One common use case would be to allow your items to disable standard inputs behaviors such
989+
// as Tab or Alt key handling, Mouse Wheel scrolling, etc.
990+
// e.g. Button(...); SetItemKeyOwner(ImGuiKey_MouseWheelY); to make hovering/activating a button disable wheel for scrolling.
991+
// - Reminder ImGuiKey enum include access to mouse buttons and gamepad, so key ownership can apply to them.
992+
// - Many related features are still in imgui_internal.h. For instance, most IsKeyXXX()/IsMouseXXX() functions have an owner-id-aware version.
993+
IMGUI_API void SetItemKeyOwner(ImGuiKey key); // Set key owner to last item ID if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
994+
987995
// Inputs Utilities: Mouse specific
988996
// - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
989997
// - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle.

imgui_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3337,7 +3337,7 @@ namespace ImGui
33373337
IMGUI_API ImGuiID GetKeyOwner(ImGuiKey key);
33383338
IMGUI_API void SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
33393339
IMGUI_API void SetKeyOwnersForKeyChord(ImGuiKeyChord key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
3340-
IMGUI_API void SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags = 0); // Set key owner to last item if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
3340+
IMGUI_API void SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags); // Set key owner to last item if it is hovered or active. Equivalent to 'if (IsItemHovered() || IsItemActive()) { SetKeyOwner(key, GetItemID());'.
33413341
IMGUI_API bool TestKeyOwner(ImGuiKey key, ImGuiID owner_id); // Test that key is either not owned, either owned by 'owner_id'
33423342
inline ImGuiKeyOwnerData* GetKeyOwnerData(ImGuiContext* ctx, ImGuiKey key) { if (key & ImGuiMod_Mask_) key = ConvertSingleModFlagToKey(key); IM_ASSERT(IsNamedKey(key)); return &ctx->KeysOwnerData[key - ImGuiKey_NamedKey_BEGIN]; }
33433343

0 commit comments

Comments
 (0)