Docking: Comments + maiintain LastFrameFocused per node + using bitfiield for docking bools.

This commit is contained in:
omar 2018-11-27 12:05:30 +01:00
parent 3f51c831de
commit 4575354bc0
3 changed files with 35 additions and 26 deletions

View File

@ -133,7 +133,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- dock: B- single visible node part of a hidden split hierarchy (OnlyNodeWithWindows != NULL) should show a normal title bar (not a tab bar) - dock: B- single visible node part of a hidden split hierarchy (OnlyNodeWithWindows != NULL) should show a normal title bar (not a tab bar)
- dock: B~ SetNextWindowDock() calls (with conditional) -> defer everything to DockContextUpdate (repro: Documents->[X]Windows->Dock 1 elsewhere->Click Redock All - dock: B~ SetNextWindowDock() calls (with conditional) -> defer everything to DockContextUpdate (repro: Documents->[X]Windows->Dock 1 elsewhere->Click Redock All
- dock: B~ tidy up tab list popup buttons features (available with manual tab-bar, see ImGuiTabBarFlags_NoTabListPopupButton code, not used by docking nodes) - dock: B~ tidy up tab list popup buttons features (available with manual tab-bar, see ImGuiTabBarFlags_NoTabListPopupButton code, not used by docking nodes)
- dock: B- DockSpace() border issues - dock: B- SetNextWindowDockId(0) with a second Begin() in the frame will asserts
- dock: B- inconsistent clipping/border 1-pixel issue (#2) - dock: B- inconsistent clipping/border 1-pixel issue (#2)
- dock: B- fix/disable auto-resize grip on split host nodes (~#2) - dock: B- fix/disable auto-resize grip on split host nodes (~#2)
- dock: B- SetNextWindowFocus() doesn't seem to apply if the window is hidden this frame, need repro (#4) - dock: B- SetNextWindowFocus() doesn't seem to apply if the window is hidden this frame, need repro (#4)

View File

@ -10351,7 +10351,7 @@ ImGuiDockNode::ImGuiDockNode(ImGuiID id)
HostWindow = VisibleWindow = NULL; HostWindow = VisibleWindow = NULL;
CentralNode = OnlyNodeWithWindows = NULL; CentralNode = OnlyNodeWithWindows = NULL;
LastFrameAlive = LastFrameActive = -1; LastFrameAlive = LastFrameActive = LastFrameFocused = -1;
LastFocusedNodeID = 0; LastFocusedNodeID = 0;
SelectedTabID = 0; SelectedTabID = 0;
WantCloseTabID = 0; WantCloseTabID = 0;
@ -10568,7 +10568,7 @@ struct ImGuiDockNodeUpdateScanResults
ImGuiDockNode* CentralNode; ImGuiDockNode* CentralNode;
ImGuiDockNode* FirstNodeWithWindows; ImGuiDockNode* FirstNodeWithWindows;
int CountNodesWithWindows; int CountNodesWithWindows;
ImGuiDockFamily DockFamilyForMerges; //ImGuiDockFamily DockFamilyForMerges;
ImGuiDockNodeUpdateScanResults() { CentralNode = FirstNodeWithWindows = NULL; CountNodesWithWindows = 0; } ImGuiDockNodeUpdateScanResults() { CentralNode = FirstNodeWithWindows = NULL; CountNodesWithWindows = 0; }
}; };
@ -10594,6 +10594,8 @@ static void DockNodeUpdateScanRec(ImGuiDockNode* node, ImGuiDockNodeUpdateScanRe
DockNodeUpdateScanRec(node->ChildNodes[1], results); DockNodeUpdateScanRec(node->ChildNodes[1], results);
} }
// - Remove inactive windows/nodes.
// - Update visibility flag.
static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node) static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -10679,7 +10681,9 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
{ {
DockNodeUpdateVisibleFlagAndInactiveChilds(node); DockNodeUpdateVisibleFlagAndInactiveChilds(node);
// Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!) // FIXME-DOCK: Merge this scan into the one above.
// - Setup central node pointers
// - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!)
ImGuiDockNodeUpdateScanResults results; ImGuiDockNodeUpdateScanResults results;
DockNodeUpdateScanRec(node, &results); DockNodeUpdateScanRec(node, &results);
node->CentralNode = results.CentralNode; node->CentralNode = results.CentralNode;
@ -10756,7 +10760,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
node->HasCollapseButton = (node->Windows.Size > 0); node->HasCollapseButton = (node->Windows.Size > 0);
for (int window_n = 0; window_n < node->Windows.Size; window_n++) for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{ {
// FIXME: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call. // FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call.
ImGuiWindow* window = node->Windows[window_n]; ImGuiWindow* window = node->Windows[window_n];
window->DockIsActive = (node->Windows.Size > 1); window->DockIsActive = (node->Windows.Size > 1);
node->HasCloseButton |= window->HasCloseButton; node->HasCloseButton |= window->HasCloseButton;
@ -10938,6 +10942,8 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
{ {
node->VisibleWindow = (node->Windows.Size > 0) ? node->Windows[0] : NULL; node->VisibleWindow = (node->Windows.Size > 0) ? node->Windows[0] : NULL;
node->IsFocused = is_focused; node->IsFocused = is_focused;
if (is_focused)
node->LastFrameFocused = g.FrameCount;
// Notify root of visible window (used to display title in OS task bar) // Notify root of visible window (used to display title in OS task bar)
if (node->VisibleWindow) if (node->VisibleWindow)
@ -10997,6 +11003,8 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
// Title bar // Title bar
node->IsFocused = is_focused; node->IsFocused = is_focused;
if (is_focused)
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));
ImU32 title_bar_col = GetColorU32(host_window->Collapsed ? ImGuiCol_TitleBgCollapsed : is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg); ImU32 title_bar_col = GetColorU32(host_window->Collapsed ? ImGuiCol_TitleBgCollapsed : is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
host_window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, host_window->WindowRounding, ImDrawCornerFlags_Top); host_window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, host_window->WindowRounding, ImDrawCornerFlags_Top);
@ -11850,15 +11858,15 @@ ImGuiID ImGui::DockSpaceOverViewport(ImGuiViewport* viewport, ImGuiDockNodeFlags
char label[32]; char label[32];
ImFormatString(label, IM_ARRAYSIZE(label), "DockspaceViewport_%08X", viewport->ID); ImFormatString(label, IM_ARRAYSIZE(label), "DockspaceViewport_%08X", viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin(label, NULL, host_window_flags); Begin(label, NULL, host_window_flags);
ImGui::PopStyleVar(3); PopStyleVar(3);
ImGuiID dockspace_id = ImGui::GetID("Dockspace"); ImGuiID dockspace_id = GetID("Dockspace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, dock_family); DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, dock_family);
ImGui::End(); End();
return dockspace_id; return dockspace_id;
} }

View File

@ -752,7 +752,7 @@ struct ImGuiTabBarSortItem
float Width; float Width;
}; };
// sizeof() 108~144 // sizeof() 116~160
struct ImGuiDockNode struct ImGuiDockNode
{ {
ImGuiID ID; ImGuiID ID;
@ -773,6 +773,7 @@ struct ImGuiDockNode
ImGuiDockNode* OnlyNodeWithWindows; // [Root node only] Set when there is a single visible node within the hierarchy. ImGuiDockNode* OnlyNodeWithWindows; // [Root node only] Set when there is a single visible node within the hierarchy.
int LastFrameAlive; // Last frame number the node was updated or kept alive explicitly with DockSpace() + ImGuiDockNodeFlags_KeepAliveOnly int LastFrameAlive; // Last frame number the node was updated or kept alive explicitly with DockSpace() + ImGuiDockNodeFlags_KeepAliveOnly
int LastFrameActive; // Last frame number the node was updated. int LastFrameActive; // Last frame number the node was updated.
int LastFrameFocused; // Last frame number the node was focused.
ImGuiID LastFocusedNodeID; // [Root node only] Which of our child node (any ancestor in the hierarchy) was last focused. ImGuiID LastFocusedNodeID; // [Root node only] Which of our child node (any ancestor in the hierarchy) was last focused.
ImGuiID SelectedTabID; // [Tab node only] Which of our tab is selected. ImGuiID SelectedTabID; // [Tab node only] Which of our tab is selected.
ImGuiID WantCloseTabID; // [Tab node only] Set when closing a specific tab. ImGuiID WantCloseTabID; // [Tab node only] Set when closing a specific tab.
@ -1274,9 +1275,9 @@ struct IMGUI_API ImGuiWindow
ImGuiItemStatusFlags DockTabItemStatusFlags; ImGuiItemStatusFlags DockTabItemStatusFlags;
ImRect DockTabItemRect; ImRect DockTabItemRect;
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. 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.
bool DockIsActive; // =~ (DockNode != NULL) && (DockNode->Windows.Size > 1) bool DockIsActive :1; // =~ (DockNode != NULL) && (DockNode->Windows.Size > 1)
bool DockTabIsVisible; // Is the window visible this frame? =~ is the corresponding tab selected? bool DockTabIsVisible :1; // Is the window visible this frame? =~ is the corresponding tab selected?
bool DockTabWantClose; bool DockTabWantClose :1;
public: public:
ImGuiWindow(ImGuiContext* context, const char* name); ImGuiWindow(ImGuiContext* context, const char* name);