mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
Legacy: clear g.ActiveIdUsingNavInputMask when active id is clear + Internals: added helpers GetKeyChordName(), ImGuiModFlags_All.
Amend 8b8a61b
This commit is contained in:
parent
8b8a61bdf9
commit
105bb3ef8a
35
imgui.cpp
35
imgui.cpp
@ -4414,6 +4414,20 @@ void ImGui::NewFrame()
|
||||
g.ActiveIdUsingKeyInputMask.ClearAllBits();
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
if (g.ActiveId == 0)
|
||||
g.ActiveIdUsingNavInputMask = 0;
|
||||
else if (g.ActiveIdUsingNavInputMask != 0)
|
||||
{
|
||||
// If your custom widget code used: { g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); }
|
||||
// Since IMGUI_VERSION_NUM >= 18804 it should be: { SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel); }
|
||||
if (g.ActiveIdUsingNavInputMask & (1 << ImGuiNavInput_Cancel))
|
||||
SetActiveIdUsingKey(ImGuiKey_Escape);
|
||||
if (g.ActiveIdUsingNavInputMask & ~(1 << ImGuiNavInput_Cancel))
|
||||
IM_ASSERT(0); // Other values unsupported
|
||||
}
|
||||
#endif
|
||||
|
||||
// Drag and drop
|
||||
g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr;
|
||||
g.DragDropAcceptIdCurr = 0;
|
||||
@ -7674,6 +7688,18 @@ const char* ImGui::GetKeyName(ImGuiKey key)
|
||||
return GKeyNames[key - ImGuiKey_NamedKey_BEGIN];
|
||||
}
|
||||
|
||||
void ImGui::GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT((mods & ~ImGuiModFlags_All) == 0 && "Passing invalid ImGuiModFlags value!"); // A frequent mistake is to pass ImGuiKey_ModXXX instead of ImGuiModFlags_XXX
|
||||
ImFormatString(out_buf, (size_t)out_buf_size, "%s%s%s%s%s",
|
||||
(mods & ImGuiModFlags_Ctrl) ? "Ctrl+" : "",
|
||||
(mods & ImGuiModFlags_Shift) ? "Shift+" : "",
|
||||
(mods & ImGuiModFlags_Alt) ? "Alt+" : "",
|
||||
(mods & ImGuiModFlags_Super) ? (g.IO.ConfigMacOSXBehaviors ? "Cmd+" : "Super+") : "",
|
||||
GetKeyName(key));
|
||||
}
|
||||
|
||||
// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime)
|
||||
// t1 = current time (e.g.: g.Time)
|
||||
// An event is triggered at:
|
||||
@ -10614,15 +10640,6 @@ static void ImGui::NavUpdateCancelRequest()
|
||||
if (!IsKeyPressed(ImGuiKey_Escape, false) && !IsKeyPressed(ImGuiKey_NavGamepadCancel, false))
|
||||
return;
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
// If your custom widget code used: { g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); }
|
||||
// Since IMGUI_VERSION_NUM >= 18804 it should be: { SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel); }
|
||||
if (g.ActiveIdUsingNavInputMask & (1 << ImGuiNavInput_Cancel))
|
||||
SetActiveIdUsingKey(ImGuiKey_Escape);
|
||||
if (g.ActiveIdUsingNavInputMask & ~(1 << ImGuiNavInput_Cancel))
|
||||
IM_ASSERT(0); // Other values unsupported
|
||||
#endif
|
||||
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n");
|
||||
if (g.ActiveId != 0)
|
||||
{
|
||||
|
3
imgui.h
3
imgui.h
@ -1459,8 +1459,9 @@ enum ImGuiModFlags_
|
||||
ImGuiModFlags_None = 0,
|
||||
ImGuiModFlags_Ctrl = 1 << 0,
|
||||
ImGuiModFlags_Shift = 1 << 1,
|
||||
ImGuiModFlags_Alt = 1 << 2, // Menu
|
||||
ImGuiModFlags_Alt = 1 << 2, // Option/Menu key
|
||||
ImGuiModFlags_Super = 1 << 3, // Cmd/Super/Windows key
|
||||
ImGuiModFlags_All = 0x0F
|
||||
};
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
|
@ -2701,6 +2701,7 @@ namespace ImGui
|
||||
inline bool IsLegacyKey(ImGuiKey key) { return key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_LegacyNativeKey_END; }
|
||||
inline bool IsGamepadKey(ImGuiKey key) { return key >= ImGuiKey_Gamepad_BEGIN && key < ImGuiKey_Gamepad_END; }
|
||||
IMGUI_API ImGuiKeyData* GetKeyData(ImGuiKey key);
|
||||
IMGUI_API void GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size);
|
||||
IMGUI_API void SetItemUsingMouseWheel();
|
||||
IMGUI_API void SetActiveIdUsingNavAndKeys();
|
||||
inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; }
|
||||
|
Loading…
Reference in New Issue
Block a user