Simpified code in GetKeyData() and used ImGuiKey_KeysData_OFFSET for consistency. Rework demo, Comments. Moved ImGuiKey_KeysData_OFFSET to internal.h (#4921, #6191)

This commit is contained in:
ocornut
2023-02-24 12:34:44 +01:00
parent 2496b973f9
commit bfce7750b1
4 changed files with 15 additions and 14 deletions

View File

@ -7660,18 +7660,14 @@ ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key)
if (key & ImGuiMod_Mask_)
key = ConvertSingleModFlagToKey(key);
int index;
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
IM_ASSERT(key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_NamedKey_END);
if (IsLegacyKey(key))
index = (g.IO.KeyMap[key] != -1) ? g.IO.KeyMap[key] : key; // Remap native->imgui or imgui->native
else
index = key;
if (IsLegacyKey(key) && g.IO.KeyMap[key] != -1)
key = (ImGuiKey)g.IO.KeyMap[key]; // Remap native->imgui or imgui->native
#else
IM_ASSERT(IsNamedKey(key) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
index = key - ImGuiKey_NamedKey_BEGIN;
#endif
return &g.IO.KeysData[index];
return &g.IO.KeysData[key - ImGuiKey_KeysData_OFFSET];
}
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
@ -13584,7 +13580,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
Text("KEYBOARD/GAMEPAD/MOUSE KEYS");
{
// We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allows displaying the data for old/new backends.
// User code should never have to go through such hoops: old code may use native keycodes, new code may use ImGuiKey codes.
// User code should never have to go through such hoops! You can generally iterate between ImGuiKey_NamedKey_BEGIN and ImGuiKey_NamedKey_END.
Indent();
#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } };