mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-29 23:06:35 +00:00
Internals: Child windows that are clipped or part of a collapsed parent are not marked as collapsed anymore, but just a separate hidden marker set. We distinguish hiding for size measurement vs hiding for other reasons. Cleaned a little the end of Begin.
This commit is contained in:
parent
0b045d8de5
commit
dd0d5debef
51
imgui.cpp
51
imgui.cpp
@ -2120,6 +2120,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
|
|||||||
CollapseToggleWanted = false;
|
CollapseToggleWanted = false;
|
||||||
SkipItems = false;
|
SkipItems = false;
|
||||||
Appearing = false;
|
Appearing = false;
|
||||||
|
Hidden = false;
|
||||||
HasCloseButton = false;
|
HasCloseButton = false;
|
||||||
BeginOrderWithinParent = -1;
|
BeginOrderWithinParent = -1;
|
||||||
BeginOrderWithinContext = -1;
|
BeginOrderWithinContext = -1;
|
||||||
@ -2129,7 +2130,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
|
|||||||
AutoFitOnlyGrows = false;
|
AutoFitOnlyGrows = false;
|
||||||
AutoFitChildAxises = 0x00;
|
AutoFitChildAxises = 0x00;
|
||||||
AutoPosLastDirection = ImGuiDir_None;
|
AutoPosLastDirection = ImGuiDir_None;
|
||||||
HiddenFrames = 0;
|
HiddenFramesRegular = HiddenFramesForResize = 0;
|
||||||
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
|
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
|
||||||
SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX);
|
SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX);
|
||||||
|
|
||||||
@ -3665,7 +3666,7 @@ void ImGui::UpdateMouseMovingWindow()
|
|||||||
|
|
||||||
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
||||||
{
|
{
|
||||||
return (window->HiddenFrames == 0) && (window->Active);
|
return (window->Active) && (!window->Hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui::UpdateMouseInputs()
|
static void ImGui::UpdateMouseInputs()
|
||||||
@ -4340,7 +4341,7 @@ static void AddWindowToDrawData(ImVector<ImDrawList*>* out_render_list, ImGuiWin
|
|||||||
for (int i = 0; i < window->DC.ChildWindows.Size; i++)
|
for (int i = 0; i < window->DC.ChildWindows.Size; i++)
|
||||||
{
|
{
|
||||||
ImGuiWindow* child = window->DC.ChildWindows[i];
|
ImGuiWindow* child = window->DC.ChildWindows[i];
|
||||||
if (child->Active && child->HiddenFrames == 0) // clipped children may have been marked not active
|
if (IsWindowActiveAndVisible(child)) // clipped children may have been marked not active
|
||||||
AddWindowToDrawData(out_render_list, child);
|
AddWindowToDrawData(out_render_list, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4924,7 +4925,7 @@ static void FindHoveredWindow()
|
|||||||
for (int i = g.Windows.Size - 1; i >= 0 && hovered_window == NULL; i--)
|
for (int i = g.Windows.Size - 1; i >= 0 && hovered_window == NULL; i--)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.Windows[i];
|
ImGuiWindow* window = g.Windows[i];
|
||||||
if (!window->Active)
|
if (!window->Active || window->Hidden)
|
||||||
continue;
|
continue;
|
||||||
if (window->Flags & ImGuiWindowFlags_NoInputs)
|
if (window->Flags & ImGuiWindowFlags_NoInputs)
|
||||||
continue;
|
continue;
|
||||||
@ -5251,7 +5252,8 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_
|
|||||||
if (window->Active)
|
if (window->Active)
|
||||||
{
|
{
|
||||||
// Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one.
|
// Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one.
|
||||||
window->HiddenFrames = 1;
|
window->Hidden = true;
|
||||||
|
window->HiddenFramesRegular = 1;
|
||||||
ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount);
|
ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount);
|
||||||
}
|
}
|
||||||
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoNav;
|
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoNav;
|
||||||
@ -6220,7 +6222,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
|
|
||||||
// Update the Appearing flag
|
// Update the Appearing flag
|
||||||
bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on
|
bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on
|
||||||
const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFrames > 0);
|
const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesForResize > 0);
|
||||||
if (flags & ImGuiWindowFlags_Popup)
|
if (flags & ImGuiWindowFlags_Popup)
|
||||||
{
|
{
|
||||||
ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.CurrentPopupStack.Size];
|
ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.CurrentPopupStack.Size];
|
||||||
@ -6316,18 +6318,20 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
|
|
||||||
// Update contents size from last frame for auto-fitting (or use explicit size)
|
// Update contents size from last frame for auto-fitting (or use explicit size)
|
||||||
window->SizeContents = CalcSizeContents(window);
|
window->SizeContents = CalcSizeContents(window);
|
||||||
if (window->HiddenFrames > 0)
|
if (window->HiddenFramesRegular > 0)
|
||||||
window->HiddenFrames--;
|
window->HiddenFramesRegular--;
|
||||||
|
if (window->HiddenFramesForResize > 0)
|
||||||
|
window->HiddenFramesForResize--;
|
||||||
|
|
||||||
// Hide new windows for one frame until they calculate their size
|
// Hide new windows for one frame until they calculate their size
|
||||||
if (window_just_created && (!window_size_x_set_by_api || !window_size_y_set_by_api))
|
if (window_just_created && (!window_size_x_set_by_api || !window_size_y_set_by_api))
|
||||||
window->HiddenFrames = 1;
|
window->HiddenFramesForResize = 1;
|
||||||
|
|
||||||
// Hide popup/tooltip window when re-opening while we measure size (because we recycle the windows)
|
// Hide popup/tooltip window when re-opening while we measure size (because we recycle the windows)
|
||||||
// We reset Size/SizeContents for reappearing popups/tooltips early in this function, so further code won't be tempted to use the old size.
|
// We reset Size/SizeContents for reappearing popups/tooltips early in this function, so further code won't be tempted to use the old size.
|
||||||
if (window_just_activated_by_user && (flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0)
|
if (window_just_activated_by_user && (flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0)
|
||||||
{
|
{
|
||||||
window->HiddenFrames = 1;
|
window->HiddenFramesForResize = 1;
|
||||||
if (flags & ImGuiWindowFlags_AlwaysAutoResize)
|
if (flags & ImGuiWindowFlags_AlwaysAutoResize)
|
||||||
{
|
{
|
||||||
if (!window_size_x_set_by_api)
|
if (!window_size_x_set_by_api)
|
||||||
@ -6432,7 +6436,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->Pos = parent_window->DC.CursorPos;
|
window->Pos = parent_window->DC.CursorPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool window_pos_with_pivot = (window->SetWindowPosVal.x != FLT_MAX && window->HiddenFrames == 0);
|
const bool window_pos_with_pivot = (window->SetWindowPosVal.x != FLT_MAX && window->HiddenFramesForResize == 0);
|
||||||
if (window_pos_with_pivot)
|
if (window_pos_with_pivot)
|
||||||
SetWindowPos(window, ImMax(style.DisplaySafeAreaPadding, window->SetWindowPosVal - window->SizeFull * window->SetWindowPosPivot), 0); // Position given a pivot (e.g. for centering)
|
SetWindowPos(window, ImMax(style.DisplaySafeAreaPadding, window->SetWindowPosVal - window->SizeFull * window->SetWindowPosPivot), 0); // Position given a pivot (e.g. for centering)
|
||||||
else if ((flags & ImGuiWindowFlags_ChildMenu) != 0)
|
else if ((flags & ImGuiWindowFlags_ChildMenu) != 0)
|
||||||
@ -6500,7 +6504,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
PushClipRect(viewport_rect.Min, viewport_rect.Max, true);
|
PushClipRect(viewport_rect.Min, viewport_rect.Max, true);
|
||||||
|
|
||||||
// Draw modal window background (darkens what is behind them, all viewports)
|
// Draw modal window background (darkens what is behind them, all viewports)
|
||||||
const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFrames <= 0;
|
const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFramesForResize <= 0;
|
||||||
const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && (window == g.NavWindowingTargetAnim->RootWindow);
|
const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && (window == g.NavWindowingTargetAnim->RootWindow);
|
||||||
if (dim_bg_for_modal || dim_bg_for_window_list)
|
if (dim_bg_for_modal || dim_bg_for_window_list)
|
||||||
{
|
{
|
||||||
@ -6750,29 +6754,31 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
window->BeginCount++;
|
window->BeginCount++;
|
||||||
g.NextWindowData.Clear();
|
g.NextWindowData.Clear();
|
||||||
|
|
||||||
|
|
||||||
if (flags & ImGuiWindowFlags_ChildWindow)
|
if (flags & ImGuiWindowFlags_ChildWindow)
|
||||||
{
|
{
|
||||||
// Child window can be out of sight and have "negative" clip windows.
|
// Child window can be out of sight and have "negative" clip windows.
|
||||||
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse them because they have no title bar).
|
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse them because they have no title bar).
|
||||||
IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
|
IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0);
|
||||||
window->Collapsed = parent_window && parent_window->Collapsed;
|
|
||||||
|
|
||||||
if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
||||||
window->Collapsed |= (window->OuterRectClipped.Min.x >= window->OuterRectClipped.Max.x || window->OuterRectClipped.Min.y >= window->OuterRectClipped.Max.y);
|
if (window->OuterRectClipped.Min.x >= window->OuterRectClipped.Max.x || window->OuterRectClipped.Min.y >= window->OuterRectClipped.Max.y)
|
||||||
|
window->HiddenFramesRegular = 1;
|
||||||
|
|
||||||
// We also hide the window from rendering because we've already added its border to the command list.
|
// Completely hide along with parent or if parent is collapsed
|
||||||
// (we could perform the check earlier in the function but it is simpler at this point)
|
if (parent_window && (parent_window->Collapsed || parent_window->Hidden))
|
||||||
if (window->Collapsed)
|
window->HiddenFramesRegular = 1;
|
||||||
window->Active = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't render if style alpha is 0.0 at the time of Begin(). This is arbitrary and inconsistent but has been there for a long while (may remove at some point)
|
// Don't render if style alpha is 0.0 at the time of Begin(). This is arbitrary and inconsistent but has been there for a long while (may remove at some point)
|
||||||
if (style.Alpha <= 0.0f)
|
if (style.Alpha <= 0.0f)
|
||||||
window->Active = false;
|
window->HiddenFramesRegular = 1;
|
||||||
|
|
||||||
|
// Update the Hidden flag
|
||||||
|
window->Hidden = (window->HiddenFramesRegular > 0) || (window->HiddenFramesForResize);
|
||||||
|
|
||||||
// Return false if we don't intend to display anything to allow user to perform an early out optimization
|
// Return false if we don't intend to display anything to allow user to perform an early out optimization
|
||||||
window->SkipItems = (window->Collapsed || !window->Active) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0;
|
window->SkipItems = (window->Collapsed || !window->Active || window->Hidden) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesForResize <= 0;
|
||||||
|
|
||||||
return !window->SkipItems;
|
return !window->SkipItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13667,7 +13673,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
|
|||||||
{
|
{
|
||||||
ImGuiWindow* tooltip_window = g.CurrentWindow;
|
ImGuiWindow* tooltip_window = g.CurrentWindow;
|
||||||
tooltip_window->SkipItems = true;
|
tooltip_window->SkipItems = true;
|
||||||
tooltip_window->HiddenFrames = 1;
|
tooltip_window->HiddenFramesRegular = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14073,6 +14079,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
(flags & ImGuiWindowFlags_NoInputs) ? "NoInputs":"", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : "");
|
(flags & ImGuiWindowFlags_NoInputs) ? "NoInputs":"", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : "");
|
||||||
ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window));
|
ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window));
|
||||||
ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1);
|
ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1);
|
||||||
|
ImGui::BulletText("Appearing: %d, Hidden: %d (Reg %d Resize %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesRegular, window->HiddenFramesForResize, window->SkipItems);
|
||||||
ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask);
|
ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask);
|
||||||
ImGui::BulletText("NavLastChildNavWindow: %s", window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL");
|
ImGui::BulletText("NavLastChildNavWindow: %s", window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL");
|
||||||
if (!window->NavRectRel[0].IsInverted())
|
if (!window->NavRectRel[0].IsInverted())
|
||||||
|
@ -982,6 +982,7 @@ struct IMGUI_API ImGuiWindow
|
|||||||
bool CollapseToggleWanted;
|
bool CollapseToggleWanted;
|
||||||
bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed)
|
bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed)
|
||||||
bool Appearing; // Set during the frame where the window is appearing (or re-appearing)
|
bool Appearing; // Set during the frame where the window is appearing (or re-appearing)
|
||||||
|
bool Hidden; // Do not display (== (HiddenFramesForResize > 0) ||
|
||||||
bool HasCloseButton; // Set when the window has a close button (p_open != NULL)
|
bool HasCloseButton; // Set when the window has a close button (p_open != NULL)
|
||||||
int BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0.
|
int BeginOrderWithinParent; // Order within immediate parent window, if we are a child window. Otherwise 0.
|
||||||
int BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues.
|
int BeginOrderWithinContext; // Order within entire imgui context. This is mostly used for debugging submission order related issues.
|
||||||
@ -991,7 +992,8 @@ struct IMGUI_API ImGuiWindow
|
|||||||
bool AutoFitOnlyGrows;
|
bool AutoFitOnlyGrows;
|
||||||
int AutoFitChildAxises;
|
int AutoFitChildAxises;
|
||||||
ImGuiDir AutoPosLastDirection;
|
ImGuiDir AutoPosLastDirection;
|
||||||
int HiddenFrames;
|
int HiddenFramesRegular; // Hide the window for N frames
|
||||||
|
int HiddenFramesForResize; // Hide the window for N frames while allowing items to be submitted so we can measure their size
|
||||||
ImGuiCond SetWindowPosAllowFlags; // store acceptable condition flags for SetNextWindowPos() use.
|
ImGuiCond SetWindowPosAllowFlags; // store acceptable condition flags for SetNextWindowPos() use.
|
||||||
ImGuiCond SetWindowSizeAllowFlags; // store acceptable condition flags for SetNextWindowSize() use.
|
ImGuiCond SetWindowSizeAllowFlags; // store acceptable condition flags for SetNextWindowSize() use.
|
||||||
ImGuiCond SetWindowCollapsedAllowFlags; // store acceptable condition flags for SetNextWindowCollapsed() use.
|
ImGuiCond SetWindowCollapsedAllowFlags; // store acceptable condition flags for SetNextWindowCollapsed() use.
|
||||||
|
Loading…
Reference in New Issue
Block a user