Docking: Extracted code into a DocknodeUpdateTabListMenu() functions + minor other changes.

This commit is contained in:
omar 2019-02-01 11:12:37 +01:00
parent cbf24a9151
commit 65a2350a5f

View File

@ -10204,6 +10204,7 @@ namespace ImGui
static void DockNodeUpdate(ImGuiDockNode* node); static void DockNodeUpdate(ImGuiDockNode* node);
static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node); static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node);
static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window); static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window);
static ImGuiID DockNodeUpdateTabListMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar);
static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node); static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node);
static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window); static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window);
static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window); static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window);
@ -11370,6 +11371,36 @@ static int IMGUI_CDECL TabItemComparerByDockOrder(const void* lhs, const void* r
return (a->BeginOrderWithinContext - b->BeginOrderWithinContext); return (a->BeginOrderWithinContext - b->BeginOrderWithinContext);
} }
static ImGuiID ImGui::DockNodeUpdateTabListMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar)
{
// Try to position the menu so it is more likely to stays within the same viewport
ImGuiID ret_tab_id = 0;
SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight()));
if (BeginPopup("#TabListMenu"))
{
node->IsFocused = true;
if (tab_bar->Tabs.Size == 1)
{
if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar))
node->WantHiddenTabBarToggle = true;
}
else
{
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
{
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
IM_ASSERT(tab->Window != NULL);
if (Selectable(tab->Window->Name, tab->ID == tab_bar->SelectedTabId))
ret_tab_id = tab->ID;
SameLine();
Text(" ");
}
}
EndPopup();
}
return ret_tab_id;
}
static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window) static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -11423,38 +11454,17 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
tab_bar = node->TabBar = IM_NEW(ImGuiTabBar)(); tab_bar = node->TabBar = IM_NEW(ImGuiTabBar)();
ImGuiID focus_tab_id = 0; ImGuiID focus_tab_id = 0;
node->IsFocused = is_focused;
// Collapse button changes shape and display a list // Collapse button changes shape and display a list
if (IsPopupOpen("#TabListMenu")) if (IsPopupOpen("#TabListMenu"))
{ {
// Try to position the menu so it is more likely to stays within the same viewport if (ImGuiID tab_id = DockNodeUpdateTabListMenu(node, tab_bar))
SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight())); focus_tab_id = tab_bar->NextSelectedTabId = tab_id;
if (BeginPopup("#TabListMenu")) is_focused |= node->IsFocused;
{
is_focused = true;
if (tab_bar->Tabs.Size == 1)
{
if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar))
node->WantHiddenTabBarToggle = true;
}
else
{
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
{
ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
IM_ASSERT(tab->Window != NULL);
if (Selectable(tab->Window->Name, tab->ID == tab_bar->SelectedTabId))
focus_tab_id = tab_bar->NextSelectedTabId = tab->ID;
SameLine();
Text(" ");
}
}
EndPopup();
}
} }
// Title bar // Title bar
node->IsFocused = is_focused;
if (is_focused) if (is_focused)
node->LastFrameFocused = g.FrameCount; node->LastFrameFocused = g.FrameCount;
ImRect title_bar_rect = ImRect(node->Pos, node->Pos + ImVec2(node->Size.x, g.FontSize + style.FramePadding.y * 2.0f)); ImRect title_bar_rect = ImRect(node->Pos, node->Pos + ImVec2(node->Size.x, g.FontSize + style.FramePadding.y * 2.0f));
@ -12156,7 +12166,6 @@ void ImGui::DockNodeTreeUpdateSplitter(ImGuiDockNode* node)
// Lock the size of every node that is a sibling of the node we are touching // Lock the size of every node that is a sibling of the node we are touching
// This might be less desirable if we can merge sibling of a same axis into the same parental level. // This might be less desirable if we can merge sibling of a same axis into the same parental level.
#if 1
for (int side_n = 0; side_n < 2; side_n++) for (int side_n = 0; side_n < 2; side_n++)
for (int touching_node_n = 0; touching_node_n < touching_nodes[side_n].Size; touching_node_n++) for (int touching_node_n = 0; touching_node_n < touching_nodes[side_n].Size; touching_node_n++)
{ {
@ -12176,7 +12185,6 @@ void ImGui::DockNodeTreeUpdateSplitter(ImGuiDockNode* node)
touching_node = touching_node->ParentNode; touching_node = touching_node->ParentNode;
} }
} }
#endif
DockNodeTreeUpdatePosSize(child_0, child_0->Pos, child_0->Size); DockNodeTreeUpdatePosSize(child_0, child_0->Pos, child_0->Size);
DockNodeTreeUpdatePosSize(child_1, child_1->Pos, child_1->Size); DockNodeTreeUpdatePosSize(child_1, child_1->Pos, child_1->Size);
@ -12767,7 +12775,6 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
ImGuiContext& g = *ctx; ImGuiContext& g = *ctx;
const bool auto_dock_node = (g.IO.ConfigDockingTabBarOnSingleWindows) && !(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking)); const bool auto_dock_node = (g.IO.ConfigDockingTabBarOnSingleWindows) && !(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking));
if (auto_dock_node) if (auto_dock_node)
{ {
if (window->DockId == 0) if (window->DockId == 0)
@ -12861,7 +12868,6 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
window->DockTabIsVisible = false; window->DockTabIsVisible = false;
return; return;
} }
IM_ASSERT(node->HostWindow); IM_ASSERT(node->HostWindow);
IM_ASSERT(node->IsLeafNode()); IM_ASSERT(node->IsLeafNode());
@ -12869,7 +12875,6 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
SetNextWindowPos(node->Pos); SetNextWindowPos(node->Pos);
SetNextWindowSize(node->Size); SetNextWindowSize(node->Size);
g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos() g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos()
window->DockIsActive = true; window->DockIsActive = true;
window->DockTabIsVisible = false; window->DockTabIsVisible = false;
if (node->Flags & ImGuiDockNodeFlags_KeepAliveOnly) if (node->Flags & ImGuiDockNodeFlags_KeepAliveOnly)
@ -12931,7 +12936,6 @@ void ImGui::BeginAsDockableDragDropTarget(ImGuiWindow* window)
IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0); IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0);
if (!g.DragDropActive) if (!g.DragDropActive)
return; return;
if (!BeginDragDropTargetCustom(window->Rect(), window->ID)) if (!BeginDragDropTargetCustom(window->Rect(), window->ID))
return; return;
@ -13126,9 +13130,7 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings
buf->appendf("[%s][Data]\n", handler->TypeName); buf->appendf("[%s][Data]\n", handler->TypeName);
for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++) for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++)
{ {
#if IMGUI_DEBUG_DOCKING_INI const int line_start_pos = buf->size(); (void)line_start_pos;
const int line_start_pos = buf->size();
#endif
const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n]; const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n];
buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", node_settings->IsDockSpace ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", node_settings->IsDockSpace ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file
buf->appendf(" ID=0x%08X", node_settings->ID); buf->appendf(" ID=0x%08X", node_settings->ID);