Skip to content

Need InputScalar() return true on ImGuiInputTextFlags_EnterReturnsTrue when typing, and return true when stepping #9299

Closed

Description

@lailoken

Version/Branch of Dear ImGui:

imgui branch: docking, version: 1.92.6 WIP (19259)

Back-ends:

imgui_impl_XXX.cpp + imgui_impl_XXX.cpp

Compiler, OS:

clang, linux

Full config/build information:

No response

Details:

Currently the InputScalar() function suggests to use IsItemDeactivatedAfterEdit() , this is cumbersome but does work, however I also have step amounts, adding the "+" and "-" buttons, and these do not trigger.

I can work around this somehow, but it's now reaching the point where I wish the InputScalar() function honored the ImGuiInputTextFlags_EnterReturnsTrue flag.

For instance, the code is used for many different types in our generic config, and some of these don't work with sliders or change-on-edit inputs (like editing the global UI DPI scale... editing this can cause a lot of visual jarring)

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

                    // implies plain input
                    // inputScalar does not support change on enter, so we use IsItemDeactivatedAfterEdit()
                    auto tempFlags = flags;  // remove the change on enter flag
                    if ((tempFlags & ImGuiInputTextFlags_EnterReturnsTrue) != 0)
                    {
                        tempFlags = static_cast<ImGuiInputTextFlags_>(tempFlags & ~ImGuiInputTextFlags_EnterReturnsTrue);
                        tempFlags = static_cast<ImGuiInputTextFlags_>(tempFlags | ImGuiInputTextFlags_LocalizeDecimalPoint);
                    }
                    ImGui::InputScalar("##val", ImGuiDataType_Float, &editing_float, &step, &step_fast, "%.3f", tempFlags);

                    if (hasValidRange)
                    {
                        if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
                        {
                            ImGui::SetTooltip("Allowed range: %g - %g", min_value, max_value);
                        }
                        editing_float = std::clamp(editing_float, min_value, max_value);
                    }
                    if (!isPlainInput || !isChangeOnEnter || ImGui::IsItemDeactivatedAfterEdit())
                    {
                        *value->get() = editing_float;
                    }

Activity

  1. ocornut commented on Mar 13, 2026

    @ocornut
    Owner

    Linking to #8665 #3946 #6284

  2. ocornut commented on Mar 13, 2026

    @ocornut
    Owner

    While I understand there is a separate desire for ImGuiInputTextFlags_EnterReturnsTrue support to be figured out.

    I cannot seem to repro this part:

    IsItemDeactivatedAfterEdit() , this is cumbersome but does work, however I also have step amounts, adding the "+" and "-" buttons, and these do not trigger.

    bool ret = ImGui::InputFloat("test", &f, 0.1f, 1.0f, "%.3f");
    bool deactivated_after_edit = ImGui::IsItemDeactivatedAfterEdit();
    if (ret || deactivated_after_edit)
        IMGUI_DEBUG_LOG("ret %d, deac %d\n", ret, deactivated_after_edit);
    [00226] ret 1, deac 0 // clicked on +
    [00232] ret 0, deac 1 // release mouse
    

    Because the step button are repeating and on Down, the modification doesn't necessarily happen on the same frame as the deactivation. Which is discussed at #8149.

  3. changed the title [-]Need InputScalar() return true on ImGuiInputTextFlags_EnterReturnsTrue when typeing, and return true when stepping[/-] [+]Need InputScalar() return true on ImGuiInputTextFlags_EnterReturnsTrue when typing, and return true when stepping[/+] on Apr 2, 2026
  4. ocornut commented on Apr 24, 2026

    @ocornut
    Owner

    The specific issue with +/- not working if you are not holding on backing data is tracked at #8149.

    Other than that:

    I have reinstated ImGuiInputTextFlags_EnterReturnsTrue for InputInt, InputFloat, InputScalar etc.
    (final commit is the simple 10c378c but it depends on various other changes done previously).

    And fixed various aspects of it:

    • Fixed the fact that it didn't return true when validating same value.
    • Fixed losing underlying value when tabbing out or losing focus.
    • Made it that pressing +/- step buttons also return true, which is in line with 1.91.4 behavior.

    Note:

    • You will not get a signal in the return value when tabbing out or losing focus.
    • So you should probably still use IsItemDeactivatedAfterEdit() in most cases.
    • Reminder, IMHO all of this is a workaround for the fact that we don't have a way to request value write-back to backing-data on validation only, and most people are trying to work around this. THIS SHOULD BE COMING SOON.

    Please open a new Issue if you have an issue with ImGuiInputTextFlags_EnterReturnsTrue.

    AFAIK, the remaining issue with IsItemDeactivatedAfterEdit() is: if intentionally NOT holding on backing data (aka always passing a temporary): the +/- buttons won't work because the IsItemDeactivatedAfterEdit() arrives one frame after writing-back. (#8149) If you think there is another issue with IsItemDeactivatedAfterEdit() please post a new issue 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址