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

Closed
opened 2016-09-22 20:17:43 +00:00 by thedmd · 6 comments
thedmd commented 2016-09-22 20:17:43 +00:00 (Migrated from github.com)

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);
`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? ``` cpp static float value = 0.0f; ImGui::InputFloat("Dummy", &value); const bool isActive = ImGui::IsItemActive(); printf("Is Active: %s\n", isActive ? true : false); ```
ocornut commented 2016-09-22 20:31:31 +00:00 (Migrated from github.com)

Definitively a bug, needs to be fixed!

Definitively a bug, needs to be fixed!
thedmd commented 2016-09-22 20:45:39 +00:00 (Migrated from github.com)

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;
 }
This is possible workaround. But `IsItemActive` seems to lag a frame. ``` diff @@ -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 commented 2016-09-25 11:47:47 +00:00 (Migrated from github.com)

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.

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 commented 2016-09-25 12:23:27 +00:00 (Migrated from github.com)

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.

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 commented 2016-09-25 12:32:58 +00:00 (Migrated from github.com)

Fixed the other issue.

Fixed the other issue.
thedmd commented 2016-09-26 10:14:47 +00:00 (Migrated from github.com)

@ocornut Thank you!

@ocornut Thank you!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#840
No description provided.