Skip to content

Added ImGuiItemFlags_LiveEditXXX flags to enable/disable applying edits to backing variable while typing. #9476

Description

@ocornut

(cc: #701, #9476 and #3936, #3946, #5904, #6284, #8149, #8065, #8665, #9117, #9299, #700, #1351, #1875, #2060, #2215, #2380, #2550, #3083, #3338, #3556, #4373, #4714, #4885, #5184, #5777, #6707, #6766, #8004, #8303, #8915, #9308)

Added ImGuiItemFlags_LiveEditOnInputText and ImGuiItemFlags_LiveEditOnInputScalar flags to configure the timing of applying edits of backing variables when typing values using a keyboard.

Both flags currently defaults to enabled, which matches previous behavior.
The short-term intent is to change ImGuiItemFlags_LiveEditOnInputScalar to default to being disabled, as soon as I get more feedback from users (VERY SOON)
👌 ImGuiItemFlags_LiveEditOnInputScalar is now disabled by default.

Image

Until now:

  • Edits where always applied immediately to backing variable, which is equivalent to the ImGuiItemFlags_LiveEditXXX flags being enabled.
  • Typing '123' in an integer field would output successively 1, 12 then 123.
  • Most uses of IsItemDeactivatedAfterEdit() or ImGuiInputTextFlags_EnterReturnsTrue were actually workarounds for this issue. Advanced applications would typically use IsItemDeactivatedAfterEdit() to distinguish transactions. Workarounds often required a backing store for scalar values, and there were also a few niggles related to IsItemDeactivatedAfterEdit() when using +/- buttons of an InputInt() widgets. Many of those situations can now be naturally simplified by disabling ImGuiItemFlags_LiveEditOnInputScalar, which is expected to become the default.

The new flags allows disabling this behavior selectively for strings fields such as InputText() vs scalar fields: SliderInt(), InputFloat(), etc.

  • When LiveEdit is disabled, edits are applied when pressing enter, tabbing out, clearing a field or deactivating due to a focus loss.
  • The flag may be altered programmatically:
PushItemFlag(ImGuiItemFlags_LiveEditOnInputScalar, false); // Disable for scalars
SliderInt(...);
PopItemFlag();
PushItemFlag(ImGuiItemFlags_LiveEditOnInput, true);        // Enable for all
SliderInt(...);
PopItemFlag();
  • But with upcoming new defaults it is expected you shouldn't touch them much.

Both flags currently defaults to true, which matches previous behavior.

  • The expectation is that for strings/text, enabling LiveEdit is a better default.
  • The expectation is that for scalars, disable LiveEdit is a better default.
  • 📣 The short-term intent is to change ImGuiItemFlags_LiveEditOnInputScalar to default to being disabled, as soon as we get more feedback from users (VERY SOON).

We intentionally are not adding io.ConfigLiveEditXXX fields to dictate the default value of each ImGuiItemFlags_LiveEditXXX, because this is not expected to be a user preference but a programmer/widget preferences. Also, we strive to make the toolkit consistent.

Feedback wanted!

(1) Try the new code.
(2) Try enabling what is expected to soon be the default:

ImGui::NewFrame();
ImGui::PushItemFlag(ImGuiItemFlags_LiveEditOnInputScalar, false);

(3) Challenge the design or ask questions about this here.
(4) Post feedback or anything here!

PS: Fun fact:
Image

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions