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

Trouble detecting the end of editing a drag float when pressing Tab #1351

Closed
onqtam opened this issue Oct 3, 2017 · 2 comments
Closed

Trouble detecting the end of editing a drag float when pressing Tab #1351

onqtam opened this issue Oct 3, 2017 · 2 comments

Comments

@onqtam
Copy link
Contributor

onqtam commented Oct 3, 2017

So I've written these helper functions to determine when dragging starts and ends for float drags (so I can implement undo/redo with the values from before starting the dragging and after the dragging stops)

static bool IsItemActiveLastFrame() {
    ImGuiContext& g = *GImGui;

    if(g.ActiveIdPreviousFrame)
        return g.ActiveIdPreviousFrame == g.CurrentWindow->DC.LastItemId;
    return false;
}

static bool IsItemJustReleased() { return IsItemActiveLastFrame() && !ImGui::IsItemActive(); }
static bool IsItemJustActivated() { return !IsItemActiveLastFrame() && ImGui::IsItemActive(); }

This works like a charm.

When I edit the float drag by entering a number (so not dragging) and I press Return - IsItemJustReleased() again returns true as expected.

My problem is when I press Tab (to move the focus on the next field) - then this doesn't return true and I don't detect the change of the value.

Does anyone have any idea what the problem might be?

@onqtam
Copy link
Contributor Author

onqtam commented Oct 5, 2017

I managed to fix my problem by changing this piece of code (using the latest version of ImGui):

else if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !io.KeyCtrl && !io.KeyShift && !io.KeyAlt && is_editable)
{
    unsigned int c = '\t'; // Insert TAB
    if (InputTextFilterCharacter(&c, flags, callback, user_data))
        edit_state.OnKeyPressed((int)c);
}

to this:

else if (IsKeyPressedMap(ImGuiKey_Tab))
{
    if (window->FocusIdxTabRequestNext != INT_MAX)
        clear_active_id = true;

    if ((flags & ImGuiInputTextFlags_AllowTabInput) && !io.KeyCtrl && !io.KeyShift && !io.KeyAlt && is_editable)
    {
        unsigned int c = '\t'; // Insert TAB
        if (InputTextFilterCharacter(&c, flags, callback, user_data))
            edit_state.OnKeyPressed((int)c);
    }
}

Basically I clear the active id - just like when enter is pressed (10 lines above that).

Tabbing still works through fields properly - so far this doesn't seem to break anything but I bet I'm missing something. Any feedback?

@ocornut
Copy link
Owner

ocornut commented Aug 27, 2020

Hello @onqtam, apologies for never answering this.

This has been solved as discussed in #1875 and other topics.
You can use IsItemDeactivated() or IsItemDeactivatedAfterEdit() added in 1.62, for the purpose you mention, and it works with tabbing out as well (the fix for tabbing out was part of 1.69),

@ocornut ocornut closed this as completed Aug 27, 2020
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