mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: Docking: More fixes to make DockNodeBeginAmendTabBar() viable (probably some issues left)
This commit is contained in:
parent
b26f1530b7
commit
d3a80d9f1b
60
imgui.cpp
60
imgui.cpp
@ -6747,7 +6747,7 @@ void ImGui::End()
|
|||||||
IM_ASSERT(g.CurrentWindowStack.Size > 0);
|
IM_ASSERT(g.CurrentWindowStack.Size > 0);
|
||||||
|
|
||||||
// Error checking: verify that user doesn't directly call End() on a child window.
|
// Error checking: verify that user doesn't directly call End() on a child window.
|
||||||
if ((window->Flags & ImGuiWindowFlags_ChildWindow) && !window->DockIsActive)
|
if ((window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_DockNodeHost) && !window->DockIsActive)
|
||||||
IM_ASSERT_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!");
|
IM_ASSERT_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!");
|
||||||
|
|
||||||
// Close anything that is open
|
// Close anything that is open
|
||||||
@ -12705,7 +12705,7 @@ static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* s
|
|||||||
IM_ASSERT(src_node && dst_node && dst_node != src_node);
|
IM_ASSERT(src_node && dst_node && dst_node != src_node);
|
||||||
ImGuiTabBar* src_tab_bar = src_node->TabBar;
|
ImGuiTabBar* src_tab_bar = src_node->TabBar;
|
||||||
if (src_tab_bar != NULL)
|
if (src_tab_bar != NULL)
|
||||||
IM_ASSERT(src_node->Windows.Size == src_node->TabBar->Tabs.Size);
|
IM_ASSERT(src_node->Windows.Size <= src_node->TabBar->Tabs.Size);
|
||||||
|
|
||||||
// If the dst_node is empty we can just move the entire tab bar (to preserve selection, scrolling, etc.)
|
// If the dst_node is empty we can just move the entire tab bar (to preserve selection, scrolling, etc.)
|
||||||
bool move_tab_bar = (src_tab_bar != NULL) && (dst_node->TabBar == NULL);
|
bool move_tab_bar = (src_tab_bar != NULL) && (dst_node->TabBar == NULL);
|
||||||
@ -12717,10 +12717,13 @@ static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* s
|
|||||||
|
|
||||||
for (int n = 0; n < src_node->Windows.Size; n++)
|
for (int n = 0; n < src_node->Windows.Size; n++)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n];
|
// DockNode's TabBar may have non-window Tabs manually appended by user
|
||||||
window->DockNode = NULL;
|
if (ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n])
|
||||||
window->DockIsActive = false;
|
{
|
||||||
DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true);
|
window->DockNode = NULL;
|
||||||
|
window->DockIsActive = false;
|
||||||
|
DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src_node->Windows.clear();
|
src_node->Windows.clear();
|
||||||
|
|
||||||
@ -13233,9 +13236,9 @@ static ImGuiID ImGui::DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar*
|
|||||||
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
|
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
|
||||||
{
|
{
|
||||||
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
|
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
|
||||||
if (tab->Window == NULL)
|
if (tab->Flags & ImGuiTabItemFlags_Button)
|
||||||
continue;
|
continue;
|
||||||
if (Selectable(tab->Window->Name, tab->ID == tab_bar->SelectedTabId))
|
if (Selectable(tab_bar->GetTabName(tab), tab->ID == tab_bar->SelectedTabId))
|
||||||
ret_tab_id = tab->ID;
|
ret_tab_id = tab->ID;
|
||||||
SameLine();
|
SameLine();
|
||||||
Text(" ");
|
Text(" ");
|
||||||
@ -13251,6 +13254,8 @@ bool ImGui::DockNodeBeginAmendTabBar(ImGuiDockNode* node)
|
|||||||
{
|
{
|
||||||
if (node->TabBar == NULL || node->HostWindow == NULL)
|
if (node->TabBar == NULL || node->HostWindow == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
if (node->SharedFlags & ImGuiDockNodeFlags_KeepAliveOnly)
|
||||||
|
return false;
|
||||||
Begin(node->HostWindow->Name);
|
Begin(node->HostWindow->Name);
|
||||||
PushOverrideID(node->ID);
|
PushOverrideID(node->ID);
|
||||||
bool ret = BeginTabBarEx(node->TabBar, node->TabBar->BarRect, node->TabBar->Flags, node);
|
bool ret = BeginTabBarEx(node->TabBar, node->TabBar->BarRect, node->TabBar->Flags, node);
|
||||||
@ -13484,7 +13489,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
|
|||||||
|
|
||||||
// Forward moving request to selected window
|
// Forward moving request to selected window
|
||||||
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId))
|
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId))
|
||||||
StartMouseMovingWindowOrNode(tab->Window, node, false);
|
StartMouseMovingWindowOrNode(tab->Window ? tab->Window : node->HostWindow, node, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13500,10 +13505,11 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
|
|||||||
// Apply navigation focus
|
// Apply navigation focus
|
||||||
if (focus_tab_id != 0)
|
if (focus_tab_id != 0)
|
||||||
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id))
|
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id))
|
||||||
{
|
if (tab->Window)
|
||||||
FocusWindow(tab->Window);
|
{
|
||||||
NavInitWindow(tab->Window, false);
|
FocusWindow(tab->Window);
|
||||||
}
|
NavInitWindow(tab->Window, false);
|
||||||
|
}
|
||||||
|
|
||||||
EndTabBar();
|
EndTabBar();
|
||||||
PopID();
|
PopID();
|
||||||
@ -13819,25 +13825,29 @@ static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDock
|
|||||||
|
|
||||||
// Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows)
|
// Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows)
|
||||||
if (root_payload->DockNodeAsHost)
|
if (root_payload->DockNodeAsHost)
|
||||||
IM_ASSERT(root_payload->DockNodeAsHost->Windows.Size == root_payload->DockNodeAsHost->TabBar->Tabs.Size);
|
IM_ASSERT(root_payload->DockNodeAsHost->Windows.Size <= root_payload->DockNodeAsHost->TabBar->Tabs.Size);
|
||||||
const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs.Size : 1;
|
ImGuiTabBar* tab_bar_with_payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar : NULL;
|
||||||
|
const int payload_count = tab_bar_with_payload ? tab_bar_with_payload->Tabs.Size : 1;
|
||||||
for (int payload_n = 0; payload_n < payload_count; payload_n++)
|
for (int payload_n = 0; payload_n < payload_count; payload_n++)
|
||||||
{
|
{
|
||||||
// Calculate the tab bounding box for each payload window
|
// DockNode's TabBar may have non-window Tabs manually appended by user
|
||||||
ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs[payload_n].Window : root_payload;
|
ImGuiWindow* payload_window = tab_bar_with_payload ? tab_bar_with_payload->Tabs[payload_n].Window : root_payload;
|
||||||
if (!DockNodeIsDropAllowedOne(payload, host_window))
|
if (tab_bar_with_payload && payload_window == NULL)
|
||||||
|
continue;
|
||||||
|
if (!DockNodeIsDropAllowedOne(payload_window, host_window))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ImVec2 tab_size = TabItemCalcSize(payload->Name, payload->HasCloseButton);
|
// Calculate the tab bounding box for each payload window
|
||||||
|
ImVec2 tab_size = TabItemCalcSize(payload_window->Name, payload_window->HasCloseButton);
|
||||||
ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y);
|
ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y);
|
||||||
tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x;
|
tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x;
|
||||||
for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
|
for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
|
||||||
{
|
{
|
||||||
ImGuiTabItemFlags tab_flags = ImGuiTabItemFlags_Preview | ((payload->Flags & ImGuiWindowFlags_UnsavedDocument) ? ImGuiTabItemFlags_UnsavedDocument : 0);
|
ImGuiTabItemFlags tab_flags = ImGuiTabItemFlags_Preview | ((payload_window->Flags & ImGuiWindowFlags_UnsavedDocument) ? ImGuiTabItemFlags_UnsavedDocument : 0);
|
||||||
if (!tab_bar_rect.Contains(tab_bb))
|
if (!tab_bar_rect.Contains(tab_bb))
|
||||||
overlay_draw_lists[overlay_n]->PushClipRect(tab_bar_rect.Min, tab_bar_rect.Max);
|
overlay_draw_lists[overlay_n]->PushClipRect(tab_bar_rect.Min, tab_bar_rect.Max);
|
||||||
TabItemBackground(overlay_draw_lists[overlay_n], tab_bb, tab_flags, overlay_col_tabs);
|
TabItemBackground(overlay_draw_lists[overlay_n], tab_bb, tab_flags, overlay_col_tabs);
|
||||||
TabItemLabelAndCloseButton(overlay_draw_lists[overlay_n], tab_bb, tab_flags, g.Style.FramePadding, payload->Name, 0, 0, false);
|
TabItemLabelAndCloseButton(overlay_draw_lists[overlay_n], tab_bb, tab_flags, g.Style.FramePadding, payload_window->Name, 0, 0, false);
|
||||||
if (!tab_bar_rect.Contains(tab_bb))
|
if (!tab_bar_rect.Contains(tab_bb))
|
||||||
overlay_draw_lists[overlay_n]->PopClipRect();
|
overlay_draw_lists[overlay_n]->PopClipRect();
|
||||||
}
|
}
|
||||||
@ -14358,10 +14368,8 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags fla
|
|||||||
// Update the node
|
// Update the node
|
||||||
DockNodeUpdate(node);
|
DockNodeUpdate(node);
|
||||||
|
|
||||||
g.WithinEndChild = true;
|
|
||||||
End();
|
End();
|
||||||
ItemSize(size);
|
ItemSize(size);
|
||||||
g.WithinEndChild = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode!
|
// Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode!
|
||||||
@ -15881,7 +15889,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
for (int tab_n = 0; tab_n < ImMin(tab_bar->Tabs.Size, 3); tab_n++)
|
for (int tab_n = 0; tab_n < ImMin(tab_bar->Tabs.Size, 3); tab_n++)
|
||||||
{
|
{
|
||||||
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
|
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
|
||||||
p += ImFormatString(p, buf_end - p, "%s'%s'", tab_n > 0 ? ", " : "", (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???");
|
p += ImFormatString(p, buf_end - p, "%s'%s'",
|
||||||
|
tab_n > 0 ? ", " : "", (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???");
|
||||||
}
|
}
|
||||||
p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } ");
|
p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } ");
|
||||||
if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); }
|
if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); }
|
||||||
@ -15902,7 +15911,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
|||||||
ImGui::PushID(tab);
|
ImGui::PushID(tab);
|
||||||
if (ImGui::SmallButton("<")) { TabBarQueueReorder(tab_bar, tab, -1); } ImGui::SameLine(0, 2);
|
if (ImGui::SmallButton("<")) { TabBarQueueReorder(tab_bar, tab, -1); } ImGui::SameLine(0, 2);
|
||||||
if (ImGui::SmallButton(">")) { TabBarQueueReorder(tab_bar, tab, +1); } ImGui::SameLine();
|
if (ImGui::SmallButton(">")) { TabBarQueueReorder(tab_bar, tab, +1); } ImGui::SameLine();
|
||||||
ImGui::Text("%02d%c Tab 0x%08X '%s' Offset: %.1f, Width: %.1f/%.1f", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???", tab->Offset, tab->Width, tab->ContentWidth);
|
ImGui::Text("%02d%c Tab 0x%08X '%s' Offset: %.1f, Width: %.1f/%.1f",
|
||||||
|
tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???", tab->Offset, tab->Width, tab->ContentWidth);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
|
@ -7099,7 +7099,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
|||||||
// Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet,
|
// Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet,
|
||||||
// and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window.
|
// and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window.
|
||||||
const char* tab_name = tab_bar->GetTabName(tab);
|
const char* tab_name = tab_bar->GetTabName(tab);
|
||||||
const bool has_close_button = tab->Window ? tab->Window->HasCloseButton : ((tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0);
|
const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0;
|
||||||
tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x;
|
tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x;
|
||||||
|
|
||||||
int section_n = (tab->Flags & ImGuiTabItemFlags_Leading) ? 0 : (tab->Flags & ImGuiTabItemFlags_Trailing) ? 2 : 1;
|
int section_n = (tab->Flags & ImGuiTabItemFlags_Leading) ? 0 : (tab->Flags & ImGuiTabItemFlags_Trailing) ? 2 : 1;
|
||||||
@ -7524,7 +7524,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
|
|||||||
IM_ASSERT_USER_ERROR(tab_bar, "Needs to be called between BeginTabBar() and EndTabBar()!");
|
IM_ASSERT_USER_ERROR(tab_bar, "Needs to be called between BeginTabBar() and EndTabBar()!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IM_ASSERT(!(flags & ImGuiTabItemFlags_Button)); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!
|
IM_ASSERT((flags & ImGuiTabItemFlags_Button) == 0); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!
|
||||||
|
|
||||||
bool ret = TabItemEx(tab_bar, label, p_open, flags, NULL);
|
bool ret = TabItemEx(tab_bar, label, p_open, flags, NULL);
|
||||||
if (ret && !(flags & ImGuiTabItemFlags_NoPushId))
|
if (ret && !(flags & ImGuiTabItemFlags_NoPushId))
|
||||||
|
Loading…
Reference in New Issue
Block a user