From dfded1e97cb97e4f95bdfff57998a5b091393640 Mon Sep 17 00:00:00 2001 From: Waterdish Date: Thu, 19 Oct 2023 16:41:50 -0700 Subject: [PATCH] Allow Android text input --- src/CMakeLists.txt | 5 +++++ src/port/android/AndroidImpl.cpp | 27 +++++++++++++++++++++++++++ src/port/android/AndroidImpl.h | 14 ++++++++++++++ src/window/gui/Gui.cpp | 7 +++++++ 4 files changed, 53 insertions(+) create mode 100644 src/port/android/AndroidImpl.cpp create mode 100644 src/port/android/AndroidImpl.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46ad61df6..3d4be97da 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -223,6 +223,11 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.cpp ${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchPerformanceProfiles.h ) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Android") + set(Source_Files__Port + ${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.h + ${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.cpp + ) endif() source_group("port" FILES ${Source_Files__Port}) diff --git a/src/port/android/AndroidImpl.cpp b/src/port/android/AndroidImpl.cpp new file mode 100644 index 000000000..b9ce25e85 --- /dev/null +++ b/src/port/android/AndroidImpl.cpp @@ -0,0 +1,27 @@ +#ifdef __ANDROID__ +#include "AndroidImpl.h" +#include +#include "public/bridge/consolevariablebridge.h" + +#include + +static bool isShowingVirtualKeyboard = true; + +void LUS::Android::ImGuiProcessEvent(bool wantsTextInput) { + ImGuiInputTextState* state = ImGui::GetInputTextState(ImGui::GetActiveID()); + + if (wantsTextInput) { + if (!isShowingVirtualKeyboard) { + state->ClearText(); + + isShowingVirtualKeyboard = true; + SDL_StartTextInput(); + } + } else { + if (isShowingVirtualKeyboard) { + isShowingVirtualKeyboard = false; + SDL_StopTextInput(); + } + } +} +#endif diff --git a/src/port/android/AndroidImpl.h b/src/port/android/AndroidImpl.h new file mode 100644 index 000000000..548469872 --- /dev/null +++ b/src/port/android/AndroidImpl.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +#include + +namespace LUS { + +class Android { + public: + static void ImGuiProcessEvent(bool wantsTextInput); +}; +}; // namespace LUS diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 879a9cbb5..accb63026 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -42,6 +42,10 @@ #include "port/switch/SwitchImpl.h" #endif +#ifdef __ANDROID__ +#include "port/android/AndroidImpl.h" +#endif + #ifdef ENABLE_OPENGL #include #include @@ -274,6 +278,9 @@ void Gui::Update(WindowEvent event) { #ifdef __SWITCH__ LUS::Switch::ImGuiProcessEvent(mImGuiIo->WantTextInput); +#endif +#ifdef __ANDROID__ + LUS::Android::ImGuiProcessEvent(mImGuiIo->WantTextInput); #endif break; #endif