mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-01 05:10:41 +00:00
Modifying text contents of active InputText #3878
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#3878
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?
I have a use case where I want to be able to modify the currently active
InputText. You already proposed a workaround in ocornut/imgui#3290, callingClearActiveID()(see workaround 2 below), which I think is sort of a counterpart toSetKeyboardFocusHere().I also came up with another (ugly) workaround, just blinking a temporary
InputTextfor the sake of switching the focus (see workaround 1 below).I know either is currently necessary since you internally buffer the text in
InputText, but nevertheless they both feel like workarounds to me. What do you think about adding an internaldirtyflag toTextBuffer(comparable to the ones you have for theInputTextcallbacks anyway), which would be set by anyTextBuffermodification and consumed on the nextInputTextrendering..? This might be more intuitive to use and also match better the stateless GUI philosophy.If this is not an option to you - would you consider making the
ClearActiveID()public (since it's on the same level asSetKeyboardFocusHere(), which is public)? :)(Crystal again, sorry)
Would #2890 solve your problem?
Been considering merging this but also add a InputText flags to temporary "trigger" this behavior as well.
Have you considered modifying the buffer inside the InputText callback, by using
ImGuiInputTextCallbackData::InsertChars()etc?Although not perfect this is the currently officially supported way or modifying an active buffer.
There are three callbacks:
ImGuiInputTextFlags_CallbackAlways,ImGuiInputTextFlags_CallbackCompletion,ImGuiInputTextFlags_CallbackHistory, the two later ones are hardcoded to trigger on certain keys (TAB, Up/Down) while Always can be used for your own check? I think there are certainly ways to improve this system but I need to know if you tried using it.I think this is a XY Problem. We don't need to make all internals public, but you may need to figure a path for your language bindings (generated or not) to allow you to access internals when needed.
I understand the proposal is to extend
InputTextby a flag to allow re-initialization. This would work for me with a but: I need a helper variable since I need to take the decision at another place in the code, not during drawing of the widget (as in my sample code). From my point of view a more elegant solution would be what I proposed: imgui keeps track transparently if theTextBufferwas modified and reinitializesInputTextautomatically once in this case.Indeed this is what I've currently implemented, but this feels quite awkward for my use case since I'm not interested in the entered characters in the first place.
:) I was not familiar with that term, but it also was my understanding. I really want to have a
TextBufferchange have automatic effect on it'sInputText, independent of its active state (this is my X). MakingClearActiveID()public is one possible Y.