Docking: Creating tab bar and adding window into tab bar immediately (not sure why I didn't do that before). Probably broke something subtle, will find out. *Edit* Initially broke restoring selected tab.

This commit is contained in:
omar 2018-09-17 22:35:30 +02:00
parent 291bfe6841
commit 455dc6e229
2 changed files with 26 additions and 17 deletions

View File

@ -9523,6 +9523,7 @@ void ImGui::EndDragDropTarget()
// Docking: Settings // Docking: Settings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TODO: // TODO:
// Bug: Fix when SelectedTab doesn't exist.
// A~ document root node resizing behavior incorrect // A~ document root node resizing behavior incorrect
// A~ document root node retrieval of ID ? // A~ document root node retrieval of ID ?
// A~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete) // A~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete)
@ -10228,8 +10229,12 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window)
if (node->Windows.Size == 2 && !node->IsExplicitRoot) if (node->Windows.Size == 2 && !node->IsExplicitRoot)
node->InitFromFirstWindow = true; node->InitFromFirstWindow = true;
if (node->TabBar) if (node->TabBar == NULL)
node->TabBar->NextSelectedTabId = window->ID; {
node->TabBar = IM_NEW(ImGuiTabBar)();
node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabID;
}
TabBarAddTab(node->TabBar, window);
DockNodeUpdateVisibleFlag(node); DockNodeUpdateVisibleFlag(node);
@ -10252,18 +10257,29 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window
UpdateWindowParentAndRootLinks(window, window->Flags & ~ImGuiWindowFlags_ChildWindow, NULL); // Update immediately UpdateWindowParentAndRootLinks(window, window->Flags & ~ImGuiWindowFlags_ChildWindow, NULL); // Update immediately
MarkIniSettingsDirty(); MarkIniSettingsDirty();
// Remove window
bool erased = false; bool erased = false;
for (int n = 0; n < node->Windows.Size; n++) for (int n = 0; n < node->Windows.Size; n++)
if (node->Windows[n] == window) if (node->Windows[n] == window)
{ {
node->Windows.erase(node->Windows.Data + n); node->Windows.erase(node->Windows.Data + n);
if (node->TabBar)
TabBarRemoveTab(node->TabBar, window->ID);
erased = true; erased = true;
break; break;
} }
IM_ASSERT(erased); IM_ASSERT(erased);
// Remove tab and possibly tab bar
if (node->TabBar)
{
TabBarRemoveTab(node->TabBar, window->ID);
const int tab_count_threshold_for_tab_bar = node->IsDocumentRoot ? 1 : 2;
if (node->Windows.Size < tab_count_threshold_for_tab_bar)
{
IM_DELETE(node->TabBar);
node->TabBar = NULL;
}
}
if (node->Windows.Size == 0 && !node->IsDocumentRoot && window->DockId != node->ID) if (node->Windows.Size == 0 && !node->IsDocumentRoot && window->DockId != node->ID)
{ {
// Automatic dock node delete themselves if they are not holding at least one tab // Automatic dock node delete themselves if they are not holding at least one tab
@ -10271,9 +10287,6 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window
return; return;
} }
if (node->TabBar)
TabBarRemoveTab(node->TabBar, window->ID);
if (node->Windows.Size == 1 && !node->IsDocumentRoot && node->HostWindow) if (node->Windows.Size == 1 && !node->IsDocumentRoot && node->HostWindow)
{ {
ImGuiWindow* remaining_window = node->Windows[0]; ImGuiWindow* remaining_window = node->Windows[0];
@ -10287,13 +10300,6 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window
remaining_window->Collapsed = node->HostWindow->Collapsed; remaining_window->Collapsed = node->HostWindow->Collapsed;
} }
int tab_count_threshold_for_tab_bar = node->IsDocumentRoot ? 1 : 2;
if (node->Windows.Size < tab_count_threshold_for_tab_bar && node->TabBar)
{
IM_DELETE(node->TabBar);
node->TabBar = NULL;
}
// Update visibility immediately is required so the DockNodeUpdateRemoveInactiveChilds() processing can reflect changes up the tree // Update visibility immediately is required so the DockNodeUpdateRemoveInactiveChilds() processing can reflect changes up the tree
DockNodeUpdateVisibleFlag(node); DockNodeUpdateVisibleFlag(node);
} }
@ -10542,6 +10548,8 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
} }
// Update active node (the one whose title bar is highlight) within a node tree // Update active node (the one whose title bar is highlight) within a node tree
if (node->IsSplitNode())
IM_ASSERT(node->TabBar == NULL);
if (!node->IsSplitNode()) if (!node->IsSplitNode())
node->LastFocusedNodeID = node->ID; // This also ensure on our creation frame we will receive the title screen highlight node->LastFocusedNodeID = node->ID; // This also ensure on our creation frame we will receive the title screen highlight
else if (g.NavWindow && g.NavWindow->RootWindowDockStop->DockNode && g.NavWindow->RootWindowDockStop->ParentWindow == host_window) else if (g.NavWindow && g.NavWindow->RootWindowDockStop->DockNode && g.NavWindow->RootWindowDockStop->ParentWindow == host_window)
@ -10624,7 +10632,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
PushID(node->ID); PushID(node->ID);
ImGuiTabBar* tab_bar = node->TabBar; ImGuiTabBar* tab_bar = node->TabBar;
bool tab_bar_is_new = (tab_bar == NULL); bool tab_bar_is_recreated = (tab_bar == NULL); // Tab bar are automatically destroyed when a node gets hidden
if (tab_bar == NULL) if (tab_bar == NULL)
tab_bar = node->TabBar = IM_NEW(ImGuiTabBar)(); tab_bar = node->TabBar = IM_NEW(ImGuiTabBar)();
@ -10692,7 +10700,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
ImQsort(tab_bar->Tabs.Data + tabs_count_old, tab_bar->Tabs.Size - tabs_count_old, sizeof(ImGuiTabItem), TabItemComparerByDockOrder); ImQsort(tab_bar->Tabs.Data + tabs_count_old, tab_bar->Tabs.Size - tabs_count_old, sizeof(ImGuiTabItem), TabItemComparerByDockOrder);
// Selected newly added tabs, or persistent tab ID if the tab bar was just recreated // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated
if (tab_bar_is_new && TabBarFindTabByID(tab_bar, node->SelectedTabID) != NULL) if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabID) != NULL)
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabID; tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabID;
else if (tab_bar->Tabs.Size > tabs_count_old) else if (tab_bar->Tabs.Size > tabs_count_old)
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID; tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID;

View File

@ -6114,6 +6114,7 @@ void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id)
if (tab_bar->NextSelectedTabId == tab_id) { tab_bar->NextSelectedTabId = 0; } if (tab_bar->NextSelectedTabId == tab_id) { tab_bar->NextSelectedTabId = 0; }
} }
// Called on manual closure attempt
void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab)
{ {
if ((tab_bar->VisibleTabId == tab->ID) && !(tab->Flags & ImGuiTabItemFlags_UnsavedDocument)) if ((tab_bar->VisibleTabId == tab->ID) && !(tab->Flags & ImGuiTabItemFlags_UnsavedDocument))