Inputs: added SetItemKeyOwner(ImGuiKey key) in public API. (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641)

This commit is contained in:
ocornut 2024-07-19 18:39:07 +02:00
parent b6e313bc05
commit f9cda1fa24
4 changed files with 22 additions and 2 deletions

View File

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

View File

@ -9805,6 +9805,11 @@ void ImGui::SetItemKeyOwner(ImGuiKey key, ImGuiInputFlags flags)
}
}
void ImGui::SetItemKeyOwner(ImGuiKey key)
{
SetItemKeyOwner(key, ImGuiInputFlags_None);
}
// This is the only public API until we expose owner_id versions of the API as replacements.
bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord)
{

10
imgui.h
View File

@ -28,7 +28,7 @@
// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.91.0 WIP"
#define IMGUI_VERSION_NUM 19096
#define IMGUI_VERSION_NUM 19097
#define IMGUI_HAS_TABLE
/*
@ -984,6 +984,14 @@ namespace ImGui
IMGUI_API bool Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
IMGUI_API void SetNextItemShortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0);
// Inputs Utilities: Key/Input Ownership [BETA]
// - One common use case would be to allow your items to disable standard inputs behaviors such
// as Tab or Alt key handling, Mouse Wheel scrolling, etc.
// e.g. Button(...); SetItemKeyOwner(ImGuiKey_MouseWheelY); to make hovering/activating a button disable wheel for scrolling.
// - Reminder ImGuiKey enum include access to mouse buttons and gamepad, so key ownership can apply to them.
// - Many related features are still in imgui_internal.h. For instance, most IsKeyXXX()/IsMouseXXX() functions have an owner-id-aware version.
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());'.
// Inputs Utilities: Mouse specific
// - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
// - You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle.

View File

@ -3337,7 +3337,7 @@ namespace ImGui
IMGUI_API ImGuiID GetKeyOwner(ImGuiKey key);
IMGUI_API void SetKeyOwner(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
IMGUI_API void SetKeyOwnersForKeyChord(ImGuiKeyChord key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
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());'.
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());'.
IMGUI_API bool TestKeyOwner(ImGuiKey key, ImGuiID owner_id); // Test that key is either not owned, either owned by 'owner_id'
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]; }