Skip to content

Commit

Permalink
Docking: Fix IsWindowAppearing() and ImGuiCond_Appearing on docked wi…
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed May 31, 2021
1 parent 1ad1429 commit 91704b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ Other Changes:
Normally the right way to disable compiling the demo is to set IMGUI_DISABLE_DEMO_WINDOWS, but we want to avoid
implying that the file is required.
- Backends: OpenGL3: Handle GL_CLIP_ORIGIN on <4.5 contexts if "GL_ARB_clip_control" extension is detected. (#4170, #3998)
>>>>>>> master

Docking+Viewports Branch:

- Docking: Fix IsWindowAppearing() and ImGuiCond_Appearing on docked windows. (#4177, #3982, #1497, #1061)


-----------------------------------------------------------------------
Expand Down
20 changes: 15 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6100,8 +6100,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
const bool first_begin_of_the_frame = (window->LastFrameActive != current_frame);
window->IsFallbackWindow = (g.CurrentWindowStack.Size == 0 && g.WithinFrameScopeWithImplicitWindow);

// 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
// Update the Appearing flag (note: the BeginDocked() path may also set this to true later)
bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on
if (flags & ImGuiWindowFlags_Popup)
{
ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size];
Expand Down Expand Up @@ -6136,6 +6136,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
{
bool has_dock_node = (window->DockId != 0 || window->DockNode != NULL);
bool new_auto_dock_node = !has_dock_node && GetWindowAlwaysWantOwnTabBar(window);
bool dock_node_was_visible = window->DockNodeIsVisible;
bool dock_tab_was_visible = window->DockTabIsVisible;
if (has_dock_node || new_auto_dock_node)
{
BeginDocked(window, p_open);
Expand All @@ -6146,6 +6148,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Docking currently override constraints
g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint;
}

// Update the Appearing flag (again)
if (window->DockTabIsVisible && !dock_tab_was_visible && dock_node_was_visible && !window->Appearing)
{
window->Appearing = true;
SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true);
}
}

// Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack
Expand Down Expand Up @@ -12957,7 +12966,7 @@ void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* windo
window->DockId = 0;
window->Collapsed = false;
window->DockIsActive = false;
window->DockTabIsVisible = false;
window->DockNodeIsVisible = window->DockTabIsVisible = false;
window->Size = window->SizeFull = FixLargeWindowsWhenUndocking(window->SizeFull, window->Viewport);

MarkIniSettingsDirty();
Expand Down Expand Up @@ -15503,7 +15512,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
else
{
window->DockIsActive = true;
window->DockTabIsVisible = false;
window->DockNodeIsVisible = window->DockTabIsVisible = false;
}
return;
}
Expand All @@ -15518,7 +15527,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
if (node->HostWindow == NULL)
{
window->DockIsActive = (node->State == ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing);
window->DockTabIsVisible = false;
window->DockNodeIsVisible = window->DockTabIsVisible = false;
if (node->Windows.Size > 1)
DockNodeHideWindowDuringHostWindowCreation(window);
return;
Expand All @@ -15542,6 +15551,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
SetNextWindowSize(node->Size);
g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos()
window->DockIsActive = true;
window->DockNodeIsVisible = true;
window->DockTabIsVisible = false;
if (node->SharedFlags & ImGuiDockNodeFlags_KeepAliveOnly)
return;
Expand Down
1 change: 1 addition & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ struct IMGUI_API ImGuiWindow

// Docking
bool DockIsActive :1; // When docking artifacts are actually visible. When this is set, DockNode is guaranteed to be != NULL. ~~ (DockNode != NULL) && (DockNode->Windows.Size > 1).
bool DockNodeIsVisible :1;
bool DockTabIsVisible :1; // Is our window visible this frame? ~~ is the corresponding tab selected?
bool DockTabWantClose :1;
short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible.
Expand Down

0 comments on commit 91704b7

Please sign in to comment.