-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
InputText, InputInt, InputFloat: add ImGuiInputTextFlags_NoLiveEdit flag #701
Comments
That's ok. That's how windows and OS X handles it
|
I think live update makes more sense for string/text values than for float/int. |
FYI started working on this but it is hard to accomplish 100% in an imgui context. |
I don't think you should have different defaults depending on the type of values (string or float etc). I think it should be consistent in the API. Maybe make live editing not the default and add a ImGuiTextEditFlags_LiveEdit? |
Putting this on hold until I do a big cleanup to add UTF-8 to stb_textedit and ditch the back and forth conversions. The code before the is too risky and bug-prone. Basically we need to store the data so that when another text widget submitted earlier steals focus and starts editing, the old data is still available for the next recently-been-editing widget to apply back to the user variable. So that means likely we'll need to have two text buffers in memory and alternate their use to avoid extra copying of data. Currently InputText() is too complex because of how it has to work-around limitation of stb_textedit while staying efficient for large text, so I am going to fix that first (not a big big change). |
…stly a workaround to that activation with enter doesn't validate immediately, which is turns triggers an assert in InputScalarAsWidgetReplacement - can't see an issue with changing it this way so trying out) + using local flag clear_active_id to only clear the active id at the end of the frame, which is one of the step that my stash for #701 requires. (#323)
👍 |
same here also for a property editor. what was your work around ? using intermediate buffer with live edit + copying into edited value when focus lost / tab / enter ? |
Is #2034 / the new |
It is relevant as being useful but it doesn't technically solve this issue #701 as the value is still always written back to the user's buffer at the moment. |
+1 Having the same problem. Would be nice to achieve "normal" behavior without workarounds. Live updates are problem for property editors |
Any update on this? |
Hello, I have the same problem with my own property editor. Any update on this? or is there any known workaround to disable Live edit? |
I recently needed this feature as well, mainly due to the usual undo/redo shenanigans where I would like to only get the updated value on enter/focus lost etc. and not edit the actual string (yet). Now I am well aware that implementing this feature properly while keeping edge cases, backwards compatibility etc. in mind is a huge task and I do not want to imply that my hacky solution does that AT ALL. What I did is the following: // Copy result to user buffer. This can currently only happen when (g.ActiveId == id)
if (apply_new_text != NULL && (flags & ImGuiInputTextFlags_NoLiveEdit) == 0)
{
//...
} (Technically there is at least one other place, that could be skipped. Where the internal buffer is compared to the user buffer to detect if any changes have been made. However I didn't bother for now). Now we somehow have to access the changes, once the editing is actually finished. ImGui::InputText("Name", &model->Name, ImGuiInputTextFlags_NoLiveEdit);
if (ImGui::IsItemDeactivatedAfterEdit()) {
auto& state = ImGui::GetCurrentContext()->InputTextDeactivatedState;
//Do something with 'state.TextA.Data'/'state.TextA.Size'
} In my case I neatly hid that admittedly undesired context access into a little wrapper function std::string_view GetLastDeactivatedText()
{
auto& state = ImGui::GetCurrentContext()->InputTextDeactivatedState;
return std::string_view(state.TextA.Data, state.TextA.Size);
} This almost works already, with the exception of pressing 'Esc' which should discard the changes. Currently 'Esc' still triggers the bool update = ImGui::InputText("Name", &model->Name, ImGuiInputTextFlags_NoLiveEdit);
if (ImGui::IsItemDeactivatedAfterEdit() && update) {
auto& state = ImGui::GetCurrentContext()->InputTextDeactivatedState;
//Do something with 'state.TextA.Data'/'state.TextA.Size'
} And that's about it. While it is a little more work in user code than just adding the flag, the code "overhead" of the |
ImGuiInputTextFlags_NoLiveEdit
(tentative name) would only apply the value when pressing Return or intentionally changing focus via Tab, as opposed to the current behaviour of applying the value as it is being edited. How about when unintentionally losing focus?(ref. #700)
The text was updated successfully, but these errors were encountered: