-
-
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 get both value_changed and enter_pressed events from the same InputText widget #2034
Comments
I believe you can do this via passing
If it's me I'd make a copy of the original |
Have you considered using Lines 1417 to 1443 in 5942c08
|
What I mean is I need to be able to tell value changed from enter_pressed, in other words a solution that adds another ImGuiInputTextFlag that simply makes the return value be 'value_changed | enter_pressed' would not be enough. ImGuiInputTextFlags_ReadOnly does not help me, the widget needs to be editable.
That's inefficient, I was hoping a solution where I wouln't need to manage an extra copy of the string.
Yes, but it's not easy to tell from the callback when the value has been changed, it's not simple and I'm not sure it's feasible to do without keeping an extra copy around and comparing every time. Maybe a bettter patch for imgui here would be a new CallbackData field that has the 'value_changed' information. |
Sorry for misunderstanding your requirement.
This looks like the best solution, which is backward-compatible (modifying the return type will be a breaking change). |
…lags, for an hypothetical IsItemValueChanged() function. (#2034)
I have merged a small internal change from another branch which should make the "value_changed" data available in the internal state. I've been trying to regroup some of those state into a place that can be queried but some of them are particularly tricky to deal with either because their computation is costly (and so we wouldn't want to do it on every item unless request) either they can't be relied on if we also rely on clipping items. At any rate, the particular information you need here is cheap to store/query so I added it now. While it is not exposed just yet, you may create the function in your own helper file (without touching imgui.cpp)
I think this should solve your problem, let me know! I will eventually expose this function in the official API as a followup to the work done in #820, #956, #1875 but I need to verify that it'll work properly in more tricky use cases. |
… was pressed). This is equivalent to the bool returned by most widgets. It is useful in some situation e.g. using InputText() with ImGuiInputTextFlags_EnterReturnsTrue. (#2034)
This has been now added as |
Solution worked for me, thanks! |
I have a need to know (and be able to discriminate) when an InputText widget has it's value changed, and also when enter is pressed.
The need is for along the lines of allowing the user to select an item among a list by typing it in full and pressing enter, but also filter that list as the user types in.
Currently you get one or the other by passing the ImGuiInputTextFlags_EnterReturnsTrue flag.
We have all the information needed by the end of InputTextEx, it's just a matter of choosing which to return because we only return a single bool.
Getting that information through other ways using the api or looking at the internal state directly looks very convoluted, if feasible at all.
So would this be a good case for changing the API to return more information, or do you have a better alternative in mind?
The text was updated successfully, but these errors were encountered: