TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_dock_node.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_id.h>
6
7#include <functional>
8#include <initializer_list>
9#include <memory>
10#include <optional>
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace tachyon
16{
19
20 class IDManager;
21
22
31
34 {
36 }
37
39 {
41 }
42
44 enum class DockDropZone : uint8_t
45 {
52 };
53
55 enum class TabBarLayout : uint8_t
56 {
59 };
60
63 struct DockNode
64 {
67
71 bool isLeaf = true;
72
73 // ---- Leaf fields ----
74 std::vector<ID> panelIds;
75 int selectedTab = 0;
78
85
92 std::vector<IntRect> cachedTabRects {};
93
94 // ---- Split fields (only when !isLeaf) ----
99 std::unique_ptr<DockNode> first;
100 std::unique_ptr<DockNode> second;
101 };
102
103 // ---- Factory helpers ----------------------------------------------------
104
106 std::unique_ptr<DockNode> MakeLeaf(std::initializer_list<ID> panelIds = {});
108 std::unique_ptr<DockNode> MakeSplit(DockSplitMode mode,
109 CssPx splitSize,
110 std::unique_ptr<DockNode> first,
111 std::unique_ptr<DockNode> second,
112 CssPx minFirstSize = 80,
113 CssPx minSecondSize = 80);
114
115 // ---- Pure tree operations -----------------------------------------------
116
118 void ReorderLeafTabs(DockNode& node, int from, int to);
119
121 void ReleaseDockTreeIDs(DockNode* node, IDManager* idManager);
122
124 bool CloseLeafTab(DockNode& node, int tabIndex);
125
128 void CollapseEmptyLeaves(std::unique_ptr<DockNode>& rootRef, IDManager* idManager = nullptr);
129
132 bool RemovePanel(std::unique_ptr<DockNode>& rootRef, ID panelId, IDManager* idManager = nullptr);
133
135 DockNode* FindNode(DockNode* root, ID nodeID);
136 const DockNode* FindNode(const DockNode* root, ID nodeID);
137
139 struct SplitSizeRange { int min; int max; };
144 int containerExtent,
145 int sizerThickness);
146
148 int ClampSplitSize(const DockNode& splitNode,
149 int containerExtent,
150 int sizerThickness);
151
153 void AssignMissingNodeIDs(DockNode* root, IDManager& idManager);
154
155 // ---- Drop target result ----------------------------------------------------
156
163
164 // ---- Drop-zone geometry ----------------------------------------------------
165
168 DockDropZone ComputeDropZone(IntRect rect, int2 point, float edgeFraction = 0.25f);
169
170 // ---- Tab drop position -----------------------------------------------------
171
174 int2 TabRowCursor(const DockNode& leaf, int2 cursor);
175
179 int TabInsertionIndex(const DockNode& leaf, int2 cursor);
180
181 // ---- Tree mutation for split-on-drop ---------------------------------------
182
184 std::unique_ptr<DockNode>* FindNodeOwner(std::unique_ptr<DockNode>& rootRef, const DockNode* target);
185
188 DockNode* SplitLeafAtZone(std::unique_ptr<DockNode>& leafRef,
189 ID droppedPanelId,
190 DockDropZone zone,
191 CssPx initialSplitSize = 200);
192
193 // ---- Layout save / restore ---------------------------------------------------
200 std::string SerializeDockTree(const DockNode& root, const std::function<std::string(ID)>& keyOf);
201
208 std::unique_ptr<DockNode> ParseDockTree(std::string_view text,
209 const std::function<std::optional<ID>(std::string_view)>& idOf);
210
213 std::vector<ID> UnplacedPanels(const DockNode& root, const std::vector<ID>& allPanels);
214
216} // namespace tachyon
Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent...
Definition gui_id_manager.h:27
DockNode * SplitLeafAtZone(std::unique_ptr< DockNode > &leafRef, ID droppedPanelId, DockDropZone zone, CssPx initialSplitSize=200)
Replaces the leaf with a split: droppedPanelId goes into a new leaf on the zone side (Left/Right/Top/...
TabBarLayout
How a tab bar lays out tabs that don't fit on one row.
Definition gui_dock_node.h:56
void CollapseEmptyLeaves(std::unique_ptr< DockNode > &rootRef, IDManager *idManager=nullptr)
Collapses empty leaves by promoting their siblings, bottom-up.
int TabInsertionIndex(const DockNode &leaf, int2 cursor)
Where a tab dropped at cursor goes (0 = before the first, count = after the last): after every tab on...
constexpr bool IsHorizontalSplit(DockSplitMode m)
True for LeftPinned / RightPinned (children side by side).
Definition gui_dock_node.h:33
std::vector< ID > UnplacedPanels(const DockNode &root, const std::vector< ID > &allPanels)
Every ID in allPanels that does not appear in the tree, in order.
bool CloseLeafTab(DockNode &node, int tabIndex)
Removes a leaf's tab, clamping selectedTab. Returns true if the leaf is now empty.
void ReorderLeafTabs(DockNode &node, int from, int to)
Moves a tab within a leaf, keeping the selected tab selected. No-op on invalid input.
SplitSizeRange ComputeSplitSizeRange(const DockNode &splitNode, int containerExtent, int sizerThickness)
Allowed splitSize range: min = the pinned child's minimum, max = containerExtent - sizerThickness - t...
void AssignMissingNodeIDs(DockNode *root, IDManager &idManager)
Gives every node (and leaf tab bar) without an ID a static ID. Idempotent.
std::unique_ptr< DockNode > MakeLeaf(std::initializer_list< ID > panelIds={})
A leaf with the given panel tabs.
DockDropZone ComputeDropZone(IntRect rect, int2 point, float edgeFraction=0.25f)
The zone of rect that point is in.
void ReleaseDockTreeIDs(DockNode *node, IDManager *idManager)
Releases a tree's static node and tab-bar IDs; call before destroying it.
DockNode * FindNode(DockNode *root, ID nodeID)
The node with nodeID under root; nullptr when not found (always for an Invalid ID).
std::unique_ptr< DockNode > * FindNodeOwner(std::unique_ptr< DockNode > &rootRef, const DockNode *target)
The unique_ptr that owns target, or nullptr.
int ClampSplitSize(const DockNode &splitNode, int containerExtent, int sizerThickness)
Returns splitSize clamped to that range (doesn't modify the node).
bool RemovePanel(std::unique_ptr< DockNode > &rootRef, ID panelId, IDManager *idManager=nullptr)
Removes the first occurrence of panelId, then collapses empty leaves.
std::unique_ptr< DockNode > MakeSplit(DockSplitMode mode, CssPx splitSize, std::unique_ptr< DockNode > first, std::unique_ptr< DockNode > second, CssPx minFirstSize=80, CssPx minSecondSize=80)
A split node owning first and second; sizes in CSS px.
DockSplitMode
Split direction and which child is pinned to splitSize; the other child flexes.
Definition gui_dock_node.h:25
constexpr bool PinsSecondChild(DockSplitMode m)
True for RightPinned / BottomPinned (splitSize applies to the second child).
Definition gui_dock_node.h:38
std::string SerializeDockTree(const DockNode &root, const std::function< std::string(ID)> &keyOf)
Writes the tree as JSON, naming each panel by keyOf's stable key (a title or type),...
int2 TabRowCursor(const DockNode &leaf, int2 cursor)
The cursor as the tab rows see it: off the rows (above, below, or in a gap between wrapped rows) it m...
std::unique_ptr< DockNode > ParseDockTree(std::string_view text, const std::function< std::optional< ID >(std::string_view)> &idOf)
Rebuilds a tree from SerializeDockTree output.
DockDropZone
Edge zone of a point within a dock content area (drop preview and split-on-drop).
Definition gui_dock_node.h:45
@ Rows
every tab shown, on as many rows as they take
Definition gui_dock_node.h:58
@ OneRow
one row; the tabs that don't fit are listed by a "+N" button after the others
Definition gui_dock_node.h:57
@ LeftPinned
horizontal split: first child (left) pinned, right flexes
Definition gui_dock_node.h:26
@ RightPinned
horizontal split: second child (right) pinned, left flexes
Definition gui_dock_node.h:27
@ BottomPinned
vertical split: second child (bottom) pinned, top flexes
Definition gui_dock_node.h:29
@ TopPinned
vertical split: first child (top) pinned, bottom flexes
Definition gui_dock_node.h:28
@ None
outside the rect entirely
Definition gui_dock_node.h:46
@ None
Definition gui_element_flags.h:19
@ Right
Definition gui_input_enums.h:42
@ Left
Definition gui_input_enums.h:40
@ Bottom
Definition gui_style.h:255
@ Top
Definition gui_style.h:254
@ Center
Center on cross axis.
Definition gui_style.h:185
Definition gui_logging.h:24
A size in CSS px.
Definition gui_units.h:18
A drop location: the leaf under the cursor and the zone within its content area.
Definition gui_dock_node.h:159
DockNode * leaf
null when nothing is under the cursor
Definition gui_dock_node.h:160
DockDropZone zone
an edge zone splits the leaf on drop
Definition gui_dock_node.h:161
Docking tree node: a leaf with panel tabs, or a split with two children where splitSize applies to th...
Definition gui_dock_node.h:64
IntRect cachedTabBarRect
tab bar
Definition gui_dock_node.h:90
CssPx minFirstSize
first child's minimum when dragging the sizer
Definition gui_dock_node.h:97
ID tabBarID
ID of a leaf's tab bar.
Definition gui_dock_node.h:70
IntRect cachedContentRect
Last frame's content rect (screen space), for hit-testing during construction, when this frame's rect...
Definition gui_dock_node.h:88
int selectedTabBeforeDrag
restored on drag-out
Definition gui_dock_node.h:76
ID lastContentPanelID
Panel that lastContentID belongs to.
Definition gui_dock_node.h:84
bool isLeaf
false = a split with first and second
Definition gui_dock_node.h:71
ID nodeID
ID of the node's container element; assigned lazily in BeginDockingContainer.
Definition gui_dock_node.h:66
TabBarLayout tabLayout
picked from the tab bar's context menu; saved
Definition gui_dock_node.h:77
IntRect cachedSplitRect
split container, to clamp the split size
Definition gui_dock_node.h:91
CssPx minSecondSize
second child's minimum when dragging the sizer
Definition gui_dock_node.h:98
IntRect cachedLeafRect
tab bar + content
Definition gui_dock_node.h:89
std::unique_ptr< DockNode > second
right / bottom child
Definition gui_dock_node.h:100
CssPx splitSize
pinned child's size; mode says which child that is
Definition gui_dock_node.h:96
std::vector< ID > panelIds
the leaf's tabs, in order (Panel IDs in the DockingLayout)
Definition gui_dock_node.h:74
DockSplitMode mode
direction and pinned child
Definition gui_dock_node.h:95
std::vector< IntRect > cachedTabRects
per tab, for the insertion preview
Definition gui_dock_node.h:92
int selectedTab
index into panelIds of the visible panel
Definition gui_dock_node.h:75
ID lastContentID
Content element of the visible tab; written during construction, read by SyncDockingScrollOffsets aft...
Definition gui_dock_node.h:81
std::unique_ptr< DockNode > first
left / top child
Definition gui_dock_node.h:99
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Definition gui_base_types.h:407
An inclusive splitSize range, in CSS px.
Definition gui_dock_node.h:139
int max
Definition gui_dock_node.h:139
int min
Definition gui_dock_node.h:139
Integer 2D vector.
Definition gui_base_types.h:19