Skip to content

Commit

Permalink
Inputs: Add optional support for untranslated key codes for backends
Browse files Browse the repository at this point in the history
  • Loading branch information
thedmd committed Aug 19, 2022
1 parent 2685650 commit 792a87d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7718,6 +7718,18 @@ const char* ImGui::GetKeyName(ImGuiKey key)
return GKeyNames[key - ImGuiKey_NamedKey_BEGIN];
}

ImGuiKey ImGui::GetUntranslatedKey(ImGuiKey key)
{
IM_ASSERT(IsNamedKey(key));

ImGuiIO& io = GetIO();

if (io.BackendFlags & ImGuiBackednFlags_HasUntranslatedKeys && io.GetUntranslatedKey)
return io.GetUntranslatedKey(key, &io.KeysData[key]);

return ImGuiKey_None;
}

void ImGui::GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size)
{
ImGuiContext& g = *GImGui;
Expand Down
5 changes: 5 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ namespace ImGui
IMGUI_API bool IsKeyReleased(ImGuiKey key); // was key released (went from Down to !Down)?
IMGUI_API int GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate
IMGUI_API const char* GetKeyName(ImGuiKey key); // [DEBUG] returns English name of the key. Those names a provided for debugging purpose and are not meant to be saved persistently not compared.
IMGUI_API ImGuiKey GetUntranslatedKey(ImGuiKey key); // map ImGuiKey_* into ImGuiKey_ on US keyboard layout if possible
IMGUI_API void SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard); // Override io.WantCaptureKeyboard flag next frame (said flag is left for your application to handle, typically when true it instructs your app to ignore inputs). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard"; after the next NewFrame() call.

// Inputs Utilities: Mouse
Expand Down Expand Up @@ -1507,6 +1508,7 @@ enum ImGuiBackendFlags_
ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Backend Platform supports honoring GetMouseCursor() value to change the OS cursor shape.
ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Backend Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3, // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
ImGuiBackednFlags_HasUntranslatedKeys = 1 << 4, // Backend Platform supports physical keyboard layout mapping to ImGuiKey_XXX.
};

// Enumeration for PushStyleColor() / PopStyleColor()
Expand Down Expand Up @@ -1951,6 +1953,9 @@ struct ImGuiIO
void* _UnusedPadding; // Unused field to keep data structure the same size.
#endif

// Optional: Untranslated key support
ImGuiKey (*GetUntranslatedKey)(ImGuiKey key, const ImGuiKeyData* key_data);

//------------------------------------------------------------------
// Input - Call before calling NewFrame()
//------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors);
ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &backend_flags, ImGuiBackendFlags_HasSetMousePos);
ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &backend_flags, ImGuiBackendFlags_RendererHasVtxOffset);
ImGui::CheckboxFlags("io.BackendFlags: HasUntranslatedKeys", &backend_flags, ImGuiBackednFlags_HasUntranslatedKeys);
ImGui::TreePop();
ImGui::Separator();
}
Expand Down

0 comments on commit 792a87d

Please sign in to comment.