From e83f37d5182a3b921ac26d158177075324f1c4cb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 10 May 2018 12:15:14 +0100 Subject: [PATCH] Enabled experimental ImGui keyboard navigation feature. --- Source/ImGui/Private/ImGuiInputState.h | 9 +++++++++ Source/ImGui/Private/ImGuiInteroperability.cpp | 10 ++++++++++ Source/ImGui/Private/SImGuiWidget.cpp | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/Source/ImGui/Private/ImGuiInputState.h b/Source/ImGui/Private/ImGuiInputState.h index f369e86..65b7a3b 100644 --- a/Source/ImGui/Private/ImGuiInputState.h +++ b/Source/ImGui/Private/ImGuiInputState.h @@ -117,6 +117,13 @@ public: // about dirty parts of keys or mouse buttons arrays. void ClearUpdateState(); + // Check whether keyboard navigation is enabled. + bool IsKeyboardNavigationEnabled() const { return bKeyboardNavigationEnabled; } + + // Set whether keyboard navigation is enabled. + // @param bEnabled - True, if navigation is enabled + void SetKeyboardNavigationEnabled(bool bEnabled) { bKeyboardNavigationEnabled = bEnabled; } + private: void Reset(bool bKeyboard, bool bMouse); @@ -144,4 +151,6 @@ private: bool bIsControlDown = false; bool bIsShiftDown = false; bool bIsAltDown = false; + + bool bKeyboardNavigationEnabled = false; }; diff --git a/Source/ImGui/Private/ImGuiInteroperability.cpp b/Source/ImGui/Private/ImGuiInteroperability.cpp index 7e2a3a5..9ef2b4c 100644 --- a/Source/ImGui/Private/ImGuiInteroperability.cpp +++ b/Source/ImGui/Private/ImGuiInteroperability.cpp @@ -65,8 +65,10 @@ namespace ImGuiInterops KeyMap[ImGuiKey_PageDown] = GetKeyIndex(EKeys::PageDown); KeyMap[ImGuiKey_Home] = GetKeyIndex(EKeys::Home); KeyMap[ImGuiKey_End] = GetKeyIndex(EKeys::End); + KeyMap[ImGuiKey_Insert] = GetKeyIndex(EKeys::Insert); KeyMap[ImGuiKey_Delete] = GetKeyIndex(EKeys::Delete); KeyMap[ImGuiKey_Backspace] = GetKeyIndex(EKeys::BackSpace); + KeyMap[ImGuiKey_Space] = GetKeyIndex(EKeys::SpaceBar); KeyMap[ImGuiKey_Enter] = GetKeyIndex(EKeys::Enter); KeyMap[ImGuiKey_Escape] = GetKeyIndex(EKeys::Escape); KeyMap[ImGuiKey_A] = GetKeyIndex(EKeys::A); @@ -161,6 +163,12 @@ namespace ImGuiInterops // Input State Copying //==================================================================================================== + template + static inline constexpr void SetFlag(TFlags& Flags, TFlag Flag, bool bSet) + { + Flags = bSet ? Flags | Flag : Flags & ~Flag; + } + void CopyInput(ImGuiIO& IO, const FImGuiInputState& InputState) { static const uint32 LeftControl = GetKeyIndex(EKeys::LeftControl); @@ -201,5 +209,7 @@ namespace ImGuiInterops { Copy(InputState.GetCharacters(), IO.InputCharacters); } + + SetFlag(IO.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard, InputState.IsKeyboardNavigationEnabled()); } } diff --git a/Source/ImGui/Private/SImGuiWidget.cpp b/Source/ImGui/Private/SImGuiWidget.cpp index 5c2c35f..0101168 100644 --- a/Source/ImGui/Private/SImGuiWidget.cpp +++ b/Source/ImGui/Private/SImGuiWidget.cpp @@ -51,6 +51,12 @@ namespace CVars TEXT("1: enabled, input is routed to ImGui and with a few exceptions is consumed"), ECVF_Default); + TAutoConsoleVariable InputNavigation(TEXT("ImGui.InputNavigation"), 0, + TEXT("[EXPERIMENTAL, WIP] Set ImGui navigation mode.\n") + TEXT("0: navigation is disabled\n") + TEXT("1: keyboard navigation"), + ECVF_Default); + TAutoConsoleVariable DrawMouseCursor(TEXT("ImGui.DrawMouseCursor"), 0, TEXT("Whether or not mouse cursor in input mode should be drawn by ImGui.\n") TEXT("0: disabled, hardware cursor will be used (default)\n") @@ -438,6 +444,8 @@ void SImGuiWidget::UpdateInputEnabled() { UpdateInputMode(false, IsDirectlyHovered()); } + + InputState.SetKeyboardNavigationEnabled(CVars::InputNavigation.GetValueOnGameThread() > 0); } void SImGuiWidget::UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer)