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

EnterReturnsTrue behavior for SliderFloat etc textbox #3338

Open
Reedbeta opened this issue Jul 6, 2020 · 9 comments
Open

EnterReturnsTrue behavior for SliderFloat etc textbox #3338

Reedbeta opened this issue Jul 6, 2020 · 9 comments

Comments

@Reedbeta
Copy link

Reedbeta commented Jul 6, 2020

Version/Branch of Dear ImGui:
Version: 1.76 WIP
Branch: master

It would be nifty if we had a way to enable ImGuiInputTextFlags_EnterReturnsTrue on the textbox used by SliderFloat and friends when you ctrl+click. I prefer EnterReturnsTrue on most of my text boxes to avoid the value shifting wildly as you type. Currently, I've modified ImGui::TempInputScalar to add this flag. Thanks!

@ocornut
Copy link
Owner

ocornut commented Jul 6, 2020

Hello,

I believe you don't want to be testing the Enter key, rather you can read IsItemDeactivatedAfterEdit().
Testing enter won't handle e.g. case such as tabbing out.
Check Demo>Widgets>Querying Status to see the effect of all IsItemXXX function.

The value shifting as you edit is another task (#701) which is yet undone, will do it eventually, but if you can manage with ImGuiInputTextFlags_EnterReturnsTrue you should manage as well with IsItemDeactivatedAfterEdit().

-Omar

@Reedbeta
Copy link
Author

Reedbeta commented Jul 6, 2020

OK, I'll have a look at IsItemDeactivatedAfterEdit(). Do I just check that instead of the return value from InputText? In any case it would still be nice to have a way to specify that for the text boxes created internally by sliders (or maybe a global setting to have that behavior by default for all text boxes).

@ocornut
Copy link
Owner

ocornut commented Jul 6, 2020

Do I just check that instead of the return value from InputText?

Yes, but I think it should work (and minor: very slightly faster) to first test the return value from InputText() then IsItemDeactivatedAfterEdit()). You might want to wrap the two lines into your own helper function in same or different namespace.

In any case it would still be nice

Maybe, but I prefer to act based on concrete needs and if IsItemDeactivatedAfterEdit() solves your problem we're good?

@Reedbeta
Copy link
Author

Reedbeta commented Jul 6, 2020

I tried IsItemDeactivatedAfterEdit() and it seems to do the job, thanks!

I think it should work (and minor: very slightly faster) to first test the return value from InputText()

This didn't seem to work—I tried gating the call on InputText, like:

if (InputText(...) && IsItemDeactivatedAfterEdit())
{
    // update the value
}

but InputText doesn't return true on the same frame that IsItemDeactivatedAfterEdit does (i.e. InputText returns true as you're typing, then IsItemDeactivatedAfterEdit returns true when you hit enter or tab away, etc). Simply calling InputText and then testing IsItemDeactivatedAfterEdit works as expected though.

Maybe, but I prefer to act based on concrete needs

Maybe I'm misunderstanding something here, but if I am concerned with the behavior of the temporary text boxes created by sliders, there doesn't seem to be a way to implement the IsItemDeactivatedAfterEdit behavior for them unless I either modify ImGui source, or I make my own copy of several layers of the slider code (SliderFloat, SliderScalar, TempInputScalar). Both create some extra work when it comes time to update to a newer version of ImGui.

I am opting to modify ImGui source for now, so I'm fine here, but it is something to consider as you think about new designs for the slider API. 🙂

@Reedbeta Reedbeta closed this as completed Jul 6, 2020
@Reedbeta
Copy link
Author

Reedbeta commented Jul 6, 2020

Actually, I spoke too soon. The IsItemDeactivatedAfterEdit() solution works for general InputText() boxes, sure, but it's not clear if or how it can be applied to the slider temporary text boxes, as they do some tricky stuff with re-using the slider's ID and it doesn't look like simply calling IsItemDeactivatedAfterEdit() works out of the box on those.

@Reedbeta Reedbeta reopened this Jul 6, 2020
@ocornut
Copy link
Owner

ocornut commented Jul 23, 2020

but InputText doesn't return true on the same frame that IsItemDeactivatedAfterEdit does (i.e. InputText returns true as you're typing, then IsItemDeactivatedAfterEdit returns true when you hit enter or tab away, etc). Simply calling InputText and then testing IsItemDeactivatedAfterEdit works as expected though.

You are right, that was a mistake in my earlier comment.

Actually, I spoke too soon. The IsItemDeactivatedAfterEdit() solution works for general InputText() boxes, sure, but it's not clear if or how it can be applied to the slider temporary text boxes, as they do some tricky stuff with re-using the slider's ID and it doesn't look like simply calling IsItemDeactivatedAfterEdit() works out of the box on those.

This seems to work for me, at least it does when I test that value in the demo:

image

@Reedbeta
Copy link
Author

Reedbeta commented Aug 2, 2020

Ah, you can use IsItemDeactivatedAfterEdit and it applies to both the slider and the textbox, but I wanted to apply it only to the textbox (I still want live updates as the slider is dragged).

@arximboldi
Copy link

@Reedbeta I have the same issue. Have you found a workaround?

@arximboldi
Copy link

Oh, I did:

    if (ImGui::DragFloat3(label.c_str(), v.data(), .1) &&
        !ImGui::TempInputIsActive(ImGui::GetActiveID()))
        // ... modify model ...

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

3 participants