-
-
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
BeginPopupContextItem forcing InputText to lose focus #4275
Comments
Hello, There are many aspects to your question: 1. Selection is not lost until another InputText is activated. Using imgui_internal.h you can access it:
2. Selection is not rendered when inactive 3. Popups is stealing focus ImGui::OpenPopupOnItemClick("popup");
if (ImGui::BeginPopup("popup", ImGuiWindowFlags_NoFocusOnAppearing)) So that the popup doesn't take focus. But it doesn't work because of how we currently handle closing popups (the fact that the underlying window keeps focus will currently make the popup automatically close. Whereas this is a bug or not I don't know, would need to investigate this more thoroughly. #718 is generally devoted to workaround for this: either use a normal window e.g. |
…ocks so badly. Add helper in internal's ImGuiInputTextState. (#4275)
I really appreciate your input, I managed to find a solution for my specific case based on that. Now, while trying to find a solution myself, I noticed that there are a pair of
|
Would it be easier if |
Hello, I'm resuming this conversation in hopes that there has been a solution in later versions. I am implementing a cut/copy/paste menu that performs actions based on the selection. My code looks like the example at the top. I can work around storing the selection so that the operations will work, but I can't render the selection while the context menu is open. The TextInput callback is not called while the ContextMenu is open due to the loss of focus. This means I can't do operations like ImGuiInputTextCallbackData::DeleteChars and InsertChars. Functions that are ideal when manipulating the input string as they keep the history for undo/redo operations, which is something I lose when I work around this by manipulating my input string variable outside of ImGui::InputText instead, UPDATE: In hopes that this helps someone in a similar situation, here is a basic example that should work. (I use openframeworks, replace the clipboard function with one that suits you). What's missing now is that the selection won't render when the menu is open and that the cursor resets to the beginning. You could change RENDER_SELECTION_WHEN_INACTIVE to true. But since this affects all inputs in the app it's not a viable solution for me. I might just draw a custom selection when the menu is open. UPDATE 2
Since IsItemDeactivated won't return true when the contextmenu is open, the selection will stay only in this scenario when I need it to. I also had to add a "setActiveID" when refocusing the input to fully restore the state. (I've updated the example below) ImGui 1.90.1
|
I came up with a solution for a context menu that simply modifies InputTextEx() and used it for my game engine, here is the code.
2024-08-27_11-17-02.mov |
Consider the following simple example:
Whenever the BeginPopupContextItem() is called the focus is immediately switched from the InputText to the newly spawned window. This causes the text selection to disappear along with the data for the SelectionStart / SelectionEnd.
One possible workaround is to save the SelectionStart / SelectionEnd whenever the popup is not opened but still the text highlight on the selection would disappear. Is there any way to keep the focus whenever a context menu is spawned above an InputText or maybe even get the focus back as soon as the popup is opened?
The text was updated successfully, but these errors were encountered: