Legacy: clear g.ActiveIdUsingNavInputMask when active id is clear + Internals: added helpers GetKeyChordName(), ImGuiModFlags_All.
Amend 8b8a61b
diff --git a/imgui.cpp b/imgui.cpp
index 821ede3..11ecf78 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -4414,6 +4414,20 @@
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 @@
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 @@
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)
{
diff --git a/imgui.h b/imgui.h
index e90ac2f..d8c7d7d 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1459,8 +1459,9 @@
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
diff --git a/imgui_internal.h b/imgui_internal.h
index baf55f6..32136cf 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -2701,6 +2701,7 @@
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; }