Skip to content

Commit

Permalink
Allow Android text input
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterdish committed Oct 19, 2023
1 parent 40ddf3b commit dfded1e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
27 changes: 27 additions & 0 deletions src/port/android/AndroidImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifdef __ANDROID__
#include "AndroidImpl.h"
#include <SDL2/SDL.h>
#include "public/bridge/consolevariablebridge.h"

#include <ImGui/imgui_internal.h>

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
14 changes: 14 additions & 0 deletions src/port/android/AndroidImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <cstdint>
#include <string>

#include <ImGui/imgui.h>

namespace LUS {

class Android {
public:
static void ImGuiProcessEvent(bool wantsTextInput);
};
}; // namespace LUS
7 changes: 7 additions & 0 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
#include "port/switch/SwitchImpl.h"
#endif

#ifdef __ANDROID__
#include "port/android/AndroidImpl.h"
#endif

#ifdef ENABLE_OPENGL
#include <ImGui/backends/imgui_impl_opengl3.h>
#include <ImGui/backends/imgui_impl_sdl2.h>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dfded1e

Please sign in to comment.