@@ -3268,7 +3268,6 @@ ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
3268
3268
{
3269
3269
ImGuiID seed = IDStack.back();
3270
3270
ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed);
3271
- ImGui::KeepAliveID(id);
3272
3271
ImGuiContext& g = *GImGui;
3273
3272
if (g.DebugHookIdInfo == id)
3274
3273
ImGui::DebugHookIdInfo(id, ImGuiDataType_String, str, str_end);
@@ -3279,7 +3278,6 @@ ImGuiID ImGuiWindow::GetID(const void* ptr)
3279
3278
{
3280
3279
ImGuiID seed = IDStack.back();
3281
3280
ImGuiID id = ImHashData(&ptr, sizeof(void*), seed);
3282
- ImGui::KeepAliveID(id);
3283
3281
ImGuiContext& g = *GImGui;
3284
3282
if (g.DebugHookIdInfo == id)
3285
3283
ImGui::DebugHookIdInfo(id, ImGuiDataType_Pointer, ptr, NULL);
@@ -3290,7 +3288,6 @@ ImGuiID ImGuiWindow::GetID(int n)
3290
3288
{
3291
3289
ImGuiID seed = IDStack.back();
3292
3290
ImGuiID id = ImHashData(&n, sizeof(n), seed);
3293
- ImGui::KeepAliveID(id);
3294
3291
ImGuiContext& g = *GImGui;
3295
3292
if (g.DebugHookIdInfo == id)
3296
3293
ImGui::DebugHookIdInfo(id, ImGuiDataType_S32, (void*)(intptr_t)n, NULL);
@@ -3333,7 +3330,6 @@ ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs)
3333
3330
ImGuiID seed = IDStack.back();
3334
3331
ImRect r_rel = ImGui::WindowRectAbsToRel(this, r_abs);
3335
3332
ImGuiID id = ImHashData(&r_rel, sizeof(r_rel), seed);
3336
- ImGui::KeepAliveID(id);
3337
3333
return id;
3338
3334
}
3339
3335
@@ -3436,6 +3432,8 @@ ImGuiID ImGui::GetHoveredID()
3436
3432
return g.HoveredId ? g.HoveredId : g.HoveredIdPreviousFrame;
3437
3433
}
3438
3434
3435
+ // This is called by ItemAdd().
3436
+ // Code not using ItemAdd() may need to call this manually otherwise ActiveId will be cleared. In IMGUI_VERSION_NUM < 18717 this was called by GetID().
3439
3437
void ImGui::KeepAliveID(ImGuiID id)
3440
3438
{
3441
3439
ImGuiContext& g = *GImGui;
@@ -5625,6 +5623,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5625
5623
if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
5626
5624
if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
5627
5625
ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID()
5626
+ KeepAliveID(resize_grip_id);
5628
5627
ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
5629
5628
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
5630
5629
if (hovered || held)
@@ -5660,6 +5659,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
5660
5659
bool hovered, held;
5661
5660
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_HOVER_PADDING);
5662
5661
ImGuiID border_id = window->GetID(border_n + 4); // == GetWindowResizeBorderID()
5662
+ KeepAliveID(border_id);
5663
5663
ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
5664
5664
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
5665
5665
if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held)
@@ -8282,6 +8282,8 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
8282
8282
// Directional navigation processing
8283
8283
if (id != 0)
8284
8284
{
8285
+ KeepAliveID(id);
8286
+
8285
8287
// Runs prior to clipping early-out
8286
8288
// (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
8287
8289
// (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests
@@ -11046,6 +11048,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
11046
11048
// We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
11047
11049
// Rely on keeping other window->LastItemXXX fields intact.
11048
11050
source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect);
11051
+ KeepAliveID(source_id);
11049
11052
bool is_hovered = ItemHoverable(g.LastItemData.Rect, source_id);
11050
11053
if (is_hovered && g.IO.MouseClicked[mouse_button])
11051
11054
{
@@ -11212,7 +11215,10 @@ bool ImGui::BeginDragDropTarget()
11212
11215
const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect;
11213
11216
ImGuiID id = g.LastItemData.ID;
11214
11217
if (id == 0)
11218
+ {
11215
11219
id = window->GetIDFromRectangle(display_rect);
11220
+ KeepAliveID(id);
11221
+ }
11216
11222
if (g.DragDropPayload.SourceId == id)
11217
11223
return false;
11218
11224
0 commit comments