mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Maintain InputText selection state/active widget after menu usage #622
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#622
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
If I click on a menu bar while a text input widget is active with a selection, that selection is lost after interaction with the menu bar is complete. It also looks like the text input widget is no longer active.
I would expect that interacting with either the window's menu bar or the global menu bar to not modify the active widget or its state.
That's correct. That sort of focusing behavior isn't supported at all yet. It would be a rather non-trivial feature to extend ImGui toward that - compared to IHMO the benefits. But doable. I am adding a note to myself that the enhancement is desirable but it would be rather low in the priority list at the moment.
Quick ideas and thinking aloud.
At the time of stealing focus from a window we could store e.g. a LastActiveId within ImGuiWindow, which could then be restored upon restoring focus when popping from OpenPopupStack. Pretty much that (plus/minus dozen of edge cases).
The problem is that we only store 1 instance of state for InputText(), so restoring focus on a text input after another has been used would lose cursor position, undo stack, etc. It may or not be a problem for you.
The majority of that stored space are the undo buffers (currently hardcoded to be ~3K). We could probably devise a general scheme for storing cursor/selection for all visible InputText(), not as much a problem of storage space there but design (when to store/restore).
Undo buffer is a little more tricky. Keeping undo data when the InputText() isn't active (when it "owns" the text) opens issues and may not play well with end-user code who may have larger-scale undo in place. (It is currently already a problem if you use text input, un-select, mess up with data outside of imgui, select text input again and use redo/undo. I could compare hash of text between last unselect and current time see if undo-buffers are still valid).
We could add options to InputText() to e.g. disable undo-buffer; request persistent undo-buffer for this instance; request semi-persistent undo-buffer for this instance, ditched when id disappear, etc.
So at the end of the day most of the work for this feature wouldn't be maintenance of ActiveId state but rather work on InputText() - unless you don't care about the text selection.
May work on #323 at some point and this would probably requires maintain a stack of focused/selected items when popups are used.