Open Slluxx opened 2 years ago
A correct approach would be to open a keyboard whenever ImGuiIO::WantCaptureKeyboard
ImGuiIO::WantTextInput
is set.
Mobile/console: when set, you may display an on-screen keyboard. This is set by Dear ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active).
You'd want two things:
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad
)io.WantTextInput
and when this is true you can spawn the OS keyboard. OS keyboard data should be fed into io.AddInputCharacter()
functiions before the call to NewFrame()
.This seems to work just fine. The only issue i have is that after the keyboard closes and the text is added zo the widget, the keyboard opens again. Imgui doesnt know when my software keyboard closes (obviously) but whats the best way to tell imgui that it shouldnt want input anymore?
The "enter/validation" key of your keyboard should probably send a ImGuiNavInput_Input
event (io.NavInputs[ImGuiNavInput_Input] = 1.0f;
)
The "cancel" key of your keyboard should send a ImGuiNavInput_Cancel
event.
ImGuiIO &io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableSetMousePos;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
// ....
while (!glfwWindowShouldClose(window))
{
if(io.WantTextInput){
io.AddInputCharactersUTF8(openKeyboard("", 501).c_str());
// io.NavInputs[ImGuiNavInput_Input] = 1.0f;
io.NavInputs[ImGuiNavInput_Cancel] = 1.0f;
}
// .... (newframe etc)
}
Multiple things
ImGuiNavInput_Input
and ImGuiNavInput_Cancel
are ignored) and the keyboard opens up right again, softlocking me in the applicationI have to write the code like that because the keyboard does not have any callbacks. Well, the Switch has 2 keyboards: Fullsized and Inline. Only the inline keyboard has callbacks but i dont want to use that because of a few unrelated reasons. openKeyboard
always returns a string.
This seems to work just fine. The only issue i have is that after the keyboard closes and the text is added zo the widget, the keyboard opens again. Imgui doesnt know when my software keyboard closes (obviously) but whats the best way to tell imgui that it shouldnt want input anymore?
Bit of a hack, but I worked around the same issue with this: https://github.com/averne/Fizeau/blob/master/application/src/swkbd.hpp#L34
Hello,
i'm working on the Nintendo Switch which uses both touchscreen and gamepad navigations. Interacting with a button is as straight forward as it can be: Wrap it in an if statement and both touchscreen and the gamepad A button work as click and will execute the code inside.
Trying to archive the same functionality with InputTextis giving me a lot of headaches though. I cant for my life figure out a good way to execute my
apiKey = openKeyboard(apiKey, 501);
once the user has "just clicked" the textinput widget with either touchscreen or gamepad.Something like
Seems to work with touch inputs but is completly ignoring the gamepad A press.
openKeyboard() opens the switchs own software keyboard and returns the output.