mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-01 05:10:41 +00:00
Can't change underlying number value when InputText has focus #2881
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#2881
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?
Version: ~1.72b (
a116439)Branch: Docking
Back-ends: imgui_impl_win32.cpp + imgui_impl_dx12.cpp
Operating System: win10
My Issue/Question:
While trying to implement custom interaction with number fields I hit an issue where I need to clear the focus of the control to change the underlying value. To easily repro the issue:
Causes:
Example of controls I was trying to setup:
https://gist.github.com/kudaba/01337c088a0bcef0c2e22a4e846f729c
Hello,
InputFloat/InputText/etc. need to own the master copy of the data when active for several reasons (not getting into details here but it's not an easy thing to change with the current code).I don't know what your input scheme is for that widget, but one possible work-around is to set the
ImGuiInputTextFlags_ReadOnlyflag when using the other form of interaction. This will force InputText to retranslate the source input value into a text buffer (in some edge case this can affect the text cursor).Hello,
InputFloat/InputText/etc. need to own the master copy of the data when active for several reasons (not getting into details here but it's not an easy thing to change with the current code).I don't know what your input scheme is for that widget, but one possible work-around is to set the
ImGuiInputTextFlags_ReadOnlyflag when using the other form of interaction. This will force InputText to retranslate the source input value into a text buffer (in some edge case this can affect the text cursor).I was using that, but it was a bit weird since I had to set that value before, but I was changing the value after since I need to check hover state, etc. I just tried locally adding a new ImGuiInputTextFlags_Dynamic to re-initialize the control if it changes, but floating point precision is making it a bit unstable. I think I'll just have to add a something to ImGuiInputTextState to force it to reset in a nice way. In my case it's for a custom control so that makes sense. I'm not sure if this is a feature we would want to be publicly facing anyway.
I was using that, but it was a bit weird since I had to set that value before, but I was changing the value after since I need to check hover state, etc. I just tried locally adding a new ImGuiInputTextFlags_Dynamic to re-initialize the control if it changes, but floating point precision is making it a bit unstable. I think I'll just have to add a something to ImGuiInputTextState to force it to reset in a nice way. In my case it's for a custom control so that makes sense. I'm not sure if this is a feature we would want to be publicly facing anyway.
I think it would be good to first add that feature as an imgui_internal.h api (calling a function or poking into the state structure), when we redesign
InputText()I would definitively want to take this into account! (along with more important kind-of-opposite change such as #701 !)I think it would be good to first add that feature as an imgui_internal.h api (calling a function or poking into the state structure), when we redesign
InputText()I would definitively want to take this into account! (along with more important kind-of-opposite change such as #701 !)This seems to do the job:
kudaba/imgui@53f90d7c55Unfortunately I'm not in a good state to make a pr for it.
This seems to do the job:
kudaba/imgui@53f90d7c55Unfortunately I'm not in a good state to make a pr for it.
I have a related use case. I'm writing a file dialog and am using
InputTextto let the user type in the name of the next leg of the path. The user can also go back to the parent using backspace when the input field is empty.But this of course requires re-initializing the text of the input field as the user moves down or up the path chain. I get odd behavior in those cases, and it now occurred to me that this must be due to the internal state of the
InputTextnot being updated after I change the content of its buffer from outsideI'm attaching a screenshot just to illustrate what I'm doing.
Is there a proper way to change the content of the buffer from outside? Or should I try to use the
Alwayscallback?EDIT: I made this work using the callback interface, though it was a bit convoluted.
I have a related use case. I'm writing a file dialog and am using
InputTextto let the user type in the name of the next leg of the path. The user can also go back to the parent using backspace when the input field is empty.But this of course requires re-initializing the text of the input field as the user moves down or up the path chain. I get odd behavior in those cases, and it now occurred to me that this must be due to the internal state of the
InputTextnot being updated after I change the content of its buffer from outsideI'm attaching a screenshot just to illustrate what I'm doing.
Is there a proper way to change the content of the buffer from outside? Or should I try to use the
Alwayscallback?EDIT: I made this work using the callback interface, though it was a bit convoluted.
I kept this open as I'm not satisfied of the solution yet and it's not a public API, but FYI in case you stumble on this issue, for years we had: