-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to unfocus InputText programmatically + IsItemDeactivatedAfterEdit() with ClearActiveID() #8303
Comments
What are you doing this and not simply calling I believe it should then behave 100% normally. Note that nowadays to replace the text you can do: if (ImGuiInputTextState* input_state = ImGui::GetInputTextState(ImGui::GetID("Text"))
input_state-ReloadUserBufAndMoveToEnd(); // or other variant And it will reload from user provided buffer. |
i am also manuallly setting the selection (which has been omitted from the example) // somewhere inside the callback
data->CursorPos = data->SelectionStart = util::imgui::CharIndexToByteIndex(data->Buf, g_SelectionStart);
data->SelectionEnd = util::imgui::CharIndexToByteIndex(data->Buf, g_SelectionEnd);
// public static native void nativeTextDialogChange(String text);
void nativeTextDialogChange(JNIEnv *env, jclass clazz, jstring text)
{
const char *cstr = env->GetStringUTFChars(text, nullptr);
g_InputTextBuf = text;
g_SetInputText = true;
env->ReleaseStringUTFChars(text, cstr);
}
// public static native void nativeTextDialogSelectionChanged(int selStart, int selEnd);
void nativeTextDialogSelectionChanged(JNIEnv *env, jclass clazz, jint selStart, jint selEnd)
{
g_SelectionStart = selStart;
g_SelectionEnd = selEnd;
} i believe that's not possible with
i've seen this function but never understood how and where to use it |
Look at the other functions and how they are implemented... void ImGuiInputTextState::ReloadUserBufAndSelectAll() { WantReloadUserBuf = true; ReloadSelectionStart = 0; ReloadSelectionEnd = INT_MAX; }
void ImGuiInputTextState::ReloadUserBufAndKeepSelection() { WantReloadUserBuf = true; ReloadSelectionStart = Stb->select_start; ReloadSelectionEnd = Stb->select_end; }
void ImGuiInputTextState::ReloadUserBufAndMoveToEnd() { WantReloadUserBuf = true; ReloadSelectionStart = ReloadSelectionEnd = INT_MAX; } |
yes, i've just look at it. if (ImGuiInputTextState *state = ImGui::GetInputTextState(ImGui::GetActiveID()))
{
// how to set the buffer??
state->ReloadUserBufAndKeepSelection();
}
but how can i set the buffer when i don't have access to it? anyway, i don't think this is relevant to what im trying to achieve
|
I can confirm this doesn't seem to work, and I will investigate it. However I also separately think that it is unclear why you can't have your virtual keyboard send only io events and it would work. Can you clarify what you are trying to achieve with this keyboard? |
I did have an implementation that directly sent the keys events to imgui, without the input dialog, but unfortunately this implementation has many limitations that needed to be implemented manually like clipboard & auto completel This is how it looks like using the keyboard with and without the dialog box |
Version/Branch of Dear ImGui:
Version 1.91.3, Branch: docking
Back-ends:
imgui_impl_android.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
ndk, Android
Full config/build information:
No response
Details:
tldr: how to unfocus InputText programmatically and still trigger the
IsItemDeactivatedAfterEdit
?i have a special use-case on how i handle InputText, im using imgui on android devices and my way of handling keyboard is to popup an input dialog, send the value to c++ and then explitly set the InputText buffer inside
ImGuiInputTextCallback
like so (do tell me if there's a better way):now i managed to emulate the behaviour as if user press
Enter
on a real keyboard as seen below, however i fail to emulate the unfocus behaviour, for exampleImGui::IsItemDeactivatedAfterEdit
would not return truethe
isEnter
istrue
if user press theEnter
on their soft-keyboard, otherwise it would befalse
if the popup dialog is closed, i want to unfocus the InputText if the popup dialog is closed, which should triggerIsItemDeactivatedAfterEdit
, but i fail to do so, any help would be appreciatedScreenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
The text was updated successfully, but these errors were encountered: