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

IsItemActive() always return false after calling InputFloat() #840

Closed
thedmd opened this issue Sep 22, 2016 · 6 comments
Closed

IsItemActive() always return false after calling InputFloat() #840

thedmd opened this issue Sep 22, 2016 · 6 comments
Labels

Comments

@thedmd
Copy link
Contributor

thedmd commented Sep 22, 2016

IsItemActive() always return false after calling ImGui::InputFloat(...).

InputFloat is implemented using InputScalerEx which wraps InputText in group. EndGroup() modify window->DC.LastItemId and in g.ActiveId == window->DC.LastItemId in IsItemActive() is always false.

Is this a real issue or expected behavior?

static float value = 0.0f;
ImGui::InputFloat("Dummy", &value);
const bool isActive = ImGui::IsItemActive();
printf("Is Active: %s\n", isActive ? true : false);
@ocornut
Copy link
Owner

ocornut commented Sep 22, 2016 via email

@thedmd
Copy link
Contributor Author

thedmd commented Sep 22, 2016

This is possible workaround. But IsItemActive seems to lag a frame.

@@ -8306,7 +8306,9 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
         RenderText(ImVec2(window->DC.CursorPos.x, window->DC.CursorPos.y + style.FramePadding.y), label);
         ItemSize(label_size, style.FramePadding.y);
     }
+    auto lastItemId = window->DC.LastItemId;
     EndGroup();
+    window->DC.LastItemId = lastItemId;

     return value_changed;
 }

@ocornut
Copy link
Owner

ocornut commented Sep 25, 2016

I don't see any reason for a lag there. IsItemActive() will test those values directly. Did you confirm the lag?

However this need a little adjustment/work-around to also function when the Steps buttons are enabled.

@ocornut
Copy link
Owner

ocornut commented Sep 25, 2016

I have applied the more general fix where if any item within the group is the active id, then IsItemActive() after EndGroup() will report true. This fix similar issue for other widgets using BeginGroup(), and allow removal of similar workaround code in InputTextMultiline().

Repro

ImGui::Begin("Bug #840");
static float value = 0.0f;
ImGui::InputFloat("Dummy", &value, 1);
ImGui::Text("IsActive: %d", ImGui::IsItemActive());
//ImGui::Text("ActiveID: %08X, LastActiveID: %08X", GImGui->ActiveId, GImGui->CurrentWindow->DC.LastItemId);
ImGui::End();

The lag is a different issue, if you are talking about

printf("IsActive: %d, MouseDown[0]: %d\n", ImGui::IsItemActive(), ImGui::IsMouseClicked(0));
//
IsActive: 0, MouseDown[0]: 0
IsActive: 0, MouseDown[0]: 1
IsActive: 1, MouseDown[0]: 0

Looking into that.

@ocornut
Copy link
Owner

ocornut commented Sep 25, 2016

Fixed the other issue.

@ocornut ocornut closed this as completed Sep 25, 2016
@thedmd
Copy link
Contributor Author

thedmd commented Sep 26, 2016

@ocornut Thank you!

ocornut added a commit that referenced this issue Oct 1, 2016
ocornut added a commit that referenced this issue Aug 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants