1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-09 23:54:20 +00:00

Tooltips: made BeginTooltipEx() not hide nested tooltips.

It's not typically possible to nest tooltips since BeginTooltipEx() imply ImGuiWindowFlags_NoInputs + following mouse pos + most tooltips would be triggered on hover. But BeginErrorTooltip() bypass that.
This commit is contained in:
ocornut 2025-11-13 13:44:21 +01:00
parent de917ebb95
commit 613cfaf0b4
2 changed files with 18 additions and 7 deletions

View file

@ -8261,6 +8261,15 @@ bool ImGui::IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent,
return false; return false;
} }
bool ImGui::IsWindowInBeginStack(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
for (int n = g.CurrentWindowStack.Size - 1; n >= 0; n--)
if (g.CurrentWindowStack[n].Window == window)
return true;
return false;
}
bool ImGui::IsWindowWithinBeginStackOf(ImGuiWindow* window, ImGuiWindow* potential_parent) bool ImGui::IsWindowWithinBeginStackOf(ImGuiWindow* window, ImGuiWindow* potential_parent)
{ {
if (window->RootWindow == potential_parent) if (window->RootWindow == potential_parent)
@ -11916,16 +11925,17 @@ bool ImGui::BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags ext
tooltip_flags |= ImGuiTooltipFlags_OverridePrevious; tooltip_flags |= ImGuiTooltipFlags_OverridePrevious;
} }
// Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one.
if ((tooltip_flags & ImGuiTooltipFlags_OverridePrevious) && g.TooltipPreviousWindow != NULL && g.TooltipPreviousWindow->Active && !IsWindowInBeginStack(g.TooltipPreviousWindow))
{
//IMGUI_DEBUG_LOG("[tooltip] '%s' already active, using +1 for this frame\n", window_name);
SetWindowHiddenAndSkipItemsForCurrentFrame(g.TooltipPreviousWindow);
g.TooltipOverrideCount++;
}
const char* window_name_template = is_dragdrop_tooltip ? "##Tooltip_DragDrop_%02d" : "##Tooltip_%02d"; const char* window_name_template = is_dragdrop_tooltip ? "##Tooltip_DragDrop_%02d" : "##Tooltip_%02d";
char window_name[32]; char window_name[32];
ImFormatString(window_name, IM_ARRAYSIZE(window_name), window_name_template, g.TooltipOverrideCount); ImFormatString(window_name, IM_ARRAYSIZE(window_name), window_name_template, g.TooltipOverrideCount);
if ((tooltip_flags & ImGuiTooltipFlags_OverridePrevious) && g.TooltipPreviousWindow != NULL && g.TooltipPreviousWindow->Active)
{
// Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one.
//IMGUI_DEBUG_LOG("[tooltip] '%s' already active, using +1 for this frame\n", window_name);
SetWindowHiddenAndSkipItemsForCurrentFrame(g.TooltipPreviousWindow);
ImFormatString(window_name, IM_ARRAYSIZE(window_name), window_name_template, ++g.TooltipOverrideCount);
}
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize; ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize;
Begin(window_name, NULL, flags | extra_window_flags); Begin(window_name, NULL, flags | extra_window_flags);
// 2023-03-09: Added bool return value to the API, but currently always returning true. // 2023-03-09: Added bool return value to the API, but currently always returning true.

View file

@ -3136,6 +3136,7 @@ namespace ImGui
IMGUI_API void UpdateWindowSkipRefresh(ImGuiWindow* window); IMGUI_API void UpdateWindowSkipRefresh(ImGuiWindow* window);
IMGUI_API ImVec2 CalcWindowNextAutoFitSize(ImGuiWindow* window); IMGUI_API ImVec2 CalcWindowNextAutoFitSize(ImGuiWindow* window);
IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent, bool popup_hierarchy); IMGUI_API bool IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent, bool popup_hierarchy);
IMGUI_API bool IsWindowInBeginStack(ImGuiWindow* window);
IMGUI_API bool IsWindowWithinBeginStackOf(ImGuiWindow* window, ImGuiWindow* potential_parent); IMGUI_API bool IsWindowWithinBeginStackOf(ImGuiWindow* window, ImGuiWindow* potential_parent);
IMGUI_API bool IsWindowAbove(ImGuiWindow* potential_above, ImGuiWindow* potential_below); IMGUI_API bool IsWindowAbove(ImGuiWindow* potential_above, ImGuiWindow* potential_below);
IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window); IMGUI_API bool IsWindowNavFocusable(ImGuiWindow* window);