@@ -3930,9 +3930,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
39303930 ActiveIdSource = ImGuiInputSource_None;
39313931 ActiveIdMouseButton = -1;
39323932 ActiveIdPreviousFrame = 0;
3933- ActiveIdPreviousFrameIsAlive = false;
3934- ActiveIdPreviousFrameHasBeenEditedBefore = false;
3935- ActiveIdPreviousFrameWindow = NULL;
3933+ memset(&DeactivatedItemData, 0, sizeof(DeactivatedItemData));
39363934 memset(&ActiveIdValueOnActivation, 0, sizeof(ActiveIdValueOnActivation));
39373935 LastActiveId = 0;
39383936 LastActiveIdTimer = 0.0f;
@@ -4175,7 +4173,7 @@ void ImGui::Shutdown()
41754173 g.WindowsById.Clear();
41764174 g.NavWindow = NULL;
41774175 g.HoveredWindow = g.HoveredWindowUnderMovingWindow = NULL;
4178- g.ActiveIdWindow = g.ActiveIdPreviousFrameWindow = NULL;
4176+ g.ActiveIdWindow = NULL;
41794177 g.MovingWindow = NULL;
41804178
41814179 g.KeysRoutingTable.Clear();
@@ -4359,6 +4357,13 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
43594357 g.MovingWindow = NULL;
43604358 }
43614359
4360+ // Store deactivate data
4361+ ImGuiDeactivatedItemData* deactivated_data = &g.DeactivatedItemData;
4362+ deactivated_data->ID = g.ActiveId;
4363+ deactivated_data->ElapseFrame = (g.LastItemData.ID == g.ActiveId) ? g.FrameCount : g.FrameCount + 1; // FIXME: OK to use LastItemData?
4364+ deactivated_data->HasBeenEditedBefore = g.ActiveIdHasBeenEditedBefore;
4365+ deactivated_data->IsAlive = (g.ActiveIdIsAlive == g.ActiveId);
4366+
43624367 // This could be written in a more general way (e.g associate a hook to ActiveId),
43634368 // but since this is currently quite an exception we'll leave it as is.
43644369 // One common scenario leading to this is: pressing Key ->NavMoveRequestApplyResult() -> ClearActiveID()
@@ -5189,11 +5194,8 @@ void ImGui::NewFrame()
51895194 g.ActiveIdTimer += g.IO.DeltaTime;
51905195 g.LastActiveIdTimer += g.IO.DeltaTime;
51915196 g.ActiveIdPreviousFrame = g.ActiveId;
5192- g.ActiveIdPreviousFrameWindow = g.ActiveIdWindow;
5193- g.ActiveIdPreviousFrameHasBeenEditedBefore = g.ActiveIdHasBeenEditedBefore;
51945197 g.ActiveIdIsAlive = 0;
51955198 g.ActiveIdHasBeenEditedThisFrame = false;
5196- g.ActiveIdPreviousFrameIsAlive = false;
51975199 g.ActiveIdIsJustActivated = false;
51985200 if (g.TempInputId != 0 && g.ActiveId != g.TempInputId)
51995201 g.TempInputId = 0;
@@ -5202,6 +5204,9 @@ void ImGui::NewFrame()
52025204 g.ActiveIdUsingNavDirMask = 0x00;
52035205 g.ActiveIdUsingAllKeyboardKeys = false;
52045206 }
5207+ if (g.DeactivatedItemData.ElapseFrame < g.FrameCount)
5208+ g.DeactivatedItemData.ID = 0;
5209+ g.DeactivatedItemData.IsAlive = false;
52055210
52065211 // Record when we have been stationary as this state is preserved while over same item.
52075212 // FIXME: The way this is expressed means user cannot alter HoverStationaryDelay during the frame to use varying values.
@@ -5833,13 +5838,13 @@ bool ImGui::IsItemDeactivated()
58335838 ImGuiContext& g = *GImGui;
58345839 if (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDeactivated)
58355840 return (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Deactivated) != 0;
5836- return (g.ActiveIdPreviousFrame == g.LastItemData.ID && g.ActiveIdPreviousFrame != 0 && g.ActiveId ! = g.LastItemData.ID );
5841+ return (g.DeactivatedItemData.ID == g.LastItemData.ID && g.LastItemData.ID != 0 && g.DeactivatedItemData.ElapseFrame > = g.FrameCount );
58375842}
58385843
58395844bool ImGui::IsItemDeactivatedAfterEdit()
58405845{
58415846 ImGuiContext& g = *GImGui;
5842- return IsItemDeactivated() && (g.ActiveIdPreviousFrameHasBeenEditedBefore || (g.ActiveId == 0 && g.ActiveIdHasBeenEditedBefore)) ;
5847+ return IsItemDeactivated() && g.DeactivatedItemData.HasBeenEditedBefore ;
58435848}
58445849
58455850// == (GetItemID() == GetFocusID() && GetFocusID() != 0)
@@ -10443,8 +10448,8 @@ void ImGui::KeepAliveID(ImGuiID id)
1044310448 ImGuiContext& g = *GImGui;
1044410449 if (g.ActiveId == id)
1044510450 g.ActiveIdIsAlive = id;
10446- if (g.ActiveIdPreviousFrame == id)
10447- g.ActiveIdPreviousFrameIsAlive = true;
10451+ if (g.DeactivatedItemData.ID == id)
10452+ g.DeactivatedItemData.IsAlive = true;
1044810453}
1044910454
1045010455// Declare item bounding box for clipping and interaction.
@@ -10529,6 +10534,9 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
1052910534 // window->DrawList->AddRect(g.LastItemData.NavRect.Min, g.LastItemData.NavRect.Max, IM_COL32(255,255,0,255)); // [DEBUG]
1053010535#endif
1053110536
10537+ if (id != 0 && g.DeactivatedItemData.ID == id)
10538+ g.DeactivatedItemData.ElapseFrame = g.FrameCount;
10539+
1053210540 // We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
1053310541 if (is_rect_visible)
1053410542 g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_Visible;
@@ -10888,7 +10896,7 @@ void ImGui::BeginGroup()
1088810896 group_data.BackupActiveIdIsAlive = g.ActiveIdIsAlive;
1088910897 group_data.BackupHoveredIdIsAlive = g.HoveredId != 0;
1089010898 group_data.BackupIsSameLine = window->DC.IsSameLine;
10891- group_data.BackupActiveIdPreviousFrameIsAlive = g.ActiveIdPreviousFrameIsAlive ;
10899+ group_data.BackupDeactivatedIdIsAlive = g.DeactivatedItemData.IsAlive ;
1089210900 group_data.EmitItem = true;
1089310901
1089410902 window->DC.GroupOffset.x = window->DC.CursorPos.x - window->Pos.x - window->DC.ColumnsOffset.x;
@@ -10939,11 +10947,11 @@ void ImGui::EndGroup()
1093910947 // Also if you grep for LastItemId you'll notice it is only used in that context.
1094010948 // (The two tests not the same because ActiveIdIsAlive is an ID itself, in order to be able to handle ActiveId being overwritten during the frame.)
1094110949 const bool group_contains_curr_active_id = (group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId;
10942- const bool group_contains_prev_active_id = (group_data.BackupActiveIdPreviousFrameIsAlive == false) && (g.ActiveIdPreviousFrameIsAlive == true);
10950+ const bool group_contains_deactivated_id = (group_data.BackupDeactivatedIdIsAlive == false) && (g.DeactivatedItemData.IsAlive == true);
1094310951 if (group_contains_curr_active_id)
1094410952 g.LastItemData.ID = g.ActiveId;
10945- else if (group_contains_prev_active_id )
10946- g.LastItemData.ID = g.ActiveIdPreviousFrame ;
10953+ else if (group_contains_deactivated_id )
10954+ g.LastItemData.ID = g.DeactivatedItemData.ID ;
1094710955 g.LastItemData.Rect = group_bb;
1094810956
1094910957 // Forward Hovered flag
@@ -10957,7 +10965,7 @@ void ImGui::EndGroup()
1095710965
1095810966 // Forward Deactivated flag
1095910967 g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HasDeactivated;
10960- if (group_contains_prev_active_id && g.ActiveId != g.ActiveIdPreviousFrame )
10968+ if (group_contains_deactivated_id )
1096110969 g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_Deactivated;
1096210970
1096310971 g.GroupStack.pop_back();
0 commit comments