Skip to content
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 a slider or input field to only return results once the user stops editing? #820

Closed
ekmett opened this issue Sep 8, 2016 · 7 comments

Comments

@ekmett
Copy link

ekmett commented Sep 8, 2016

I have a direction in my editor that when edited takes something like half a second of background processing to adjust.

I'd like to have imgui change the value in place only once upon finishing edit, rather than as the user types, as otherwise my world stutters to a halt.

I can't quite figure out how to do this through the current API.

@ocornut
Copy link
Owner

ocornut commented Sep 8, 2016

Sorry it's not possible right now. The feature is planned and listed in #701 but surprisingly more work than expected for some widgets (perhaps easier for regular Slider).

For text input you can however use ImGuiInputTextFlags_EnterReturnsTrue and check return value, but your underlying value will still be edited. You may work around with temporaries.

@ekmett
Copy link
Author

ekmett commented Sep 8, 2016

I'm trying to figure out the right workflow to work around it with temporaries at least for the sun direction, which is a vec3.

Right now I do something like:

gui::InputFloat3("sun", &uniforms.sun_dir.x, 2);

I can make a temporary_sun_dir or something, but it isn't clear to me how to know when to copy from the uniforms into the new temporary. Copying out seems straightforward enough.

@ekmett
Copy link
Author

ekmett commented Sep 8, 2016

I think I have a hack.

@ekmett ekmett closed this as completed Sep 8, 2016
@ocornut
Copy link
Owner

ocornut commented Sep 8, 2016

The hack I've been using recently is:

#include <imgui_internal.h>

bool ImGuiEx::IsItemActiveLastFrame()
{
    ImGuiContext& g = *GImGui;
    if (g.ActiveIdPreviousFrame)
        return g.ActiveIdPreviousFrame == g.CurrentWindow->DC.LastItemId;
    return false;
}

bool ImGuiEx::IsItemJustReleased()
{
    return IsItemActiveLastFrame() && !ImGui::IsItemActive();
}
ImGui::SliderFloat(..);
if (ImGuiEx::IsItemJustReleased()) ...

I might add and expose that function publicly to facilitate that sort of thing.

@ekmett
Copy link
Author

ekmett commented Sep 8, 2016

That is a fair bit cleaner than my hack =)

@ocornut
Copy link
Owner

ocornut commented Apr 2, 2018

Reopening this issue as I would like to like to provide an official public implementation of it.

@ocornut ocornut reopened this Apr 2, 2018
ocornut added a commit that referenced this issue Jun 12, 2018
…usly but isn't anymore. Useful for Undo/Redo patterns. (#820, #956, #1875)
ocornut added a commit that referenced this issue Jun 12, 2018
…iously, isn't anymore, and during its active state modified a value. Note that you may still get false positive. (#820, #956, #1875)
@ocornut
Copy link
Owner

ocornut commented Jun 12, 2018

@ekmett Reviving this old request, we now have a much better solution. See there:
#1875 (comment)
(Closing this topic as now redundant of 1875)

@ocornut ocornut closed this as completed Jun 12, 2018
ocornut added a commit that referenced this issue Aug 16, 2018
…n a group, affecting ColorPicker (broken in 1.62). Made ActiveIdIsAlive track the actual ID to avoid incorrect polling in BeginGroup/EndGroup when the ID changes within the group. (#2023, #820, #956, #1875).
ocornut added a commit that referenced this issue Aug 23, 2018
…) for consistency with new IsItemEdited() API. Kept redirection function (will obsolete fast as IsItemDeactivatedAfterChange() is very recent). (#820, #956, #1875, #2034)
ocornut added a commit that referenced this issue Feb 6, 2019
…emDeactivatedAfterEdit functions which are useful to implement variety of undo patterns. (#820, #956, #1875)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants