TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_docking_types.h
Go to the documentation of this file.
1#pragma once
2
3#include <gui_core/gui_id.h>
5#include <gui_core/style/gui_style_text.h> // IconID
6
7#include <gui_controls/gui_dock_node.h> // DockNode, DockDropTarget
8#include <gui_core/windows/gui_window_backend.h> // WindowMode
9
10#include <functional>
11#include <memory>
12#include <optional>
13#include <string>
14#include <string_view>
15#include <unordered_map>
16#include <vector>
17
18// Docking + panel data model: Panel, DockingLayout (tree + panel registry),
19// per-frame construction state, hit-test results and floating windows.
20
21namespace tachyon
22{
25
26
27 // ---- TabBar: reorderable tabs ----
30 std::string_view closeLabel = "Close Panel";
33 bool listHidden = true;
34 bool layoutMenu = true;
38 };
39
41 struct TabBarState {
43 int* selectedIndex = nullptr;
44 int nextTabIndex = 0;
45 std::function<void(int)> onClose;
46 std::function<void(int, tachyon::int2)> onDragOut;
47 TabBarLayout* layout = nullptr;
49 std::vector<bool> shown;
50 struct HiddenTab { int index = 0; tachyon::IconID icon = tachyon::IconID::Invalid; std::string text; };
51 std::vector<HiddenTab> hidden;
52 };
53
55 struct TabState {
56 bool open = false;
59 int index = 0;
60 bool selected = false;
61 };
62
65 struct TabBarMemory {
66 int tabCount = 0;
67 int focusIndex = -1;
69
70 std::vector<int32_t> widths;
71 int32_t barWidth = 0;
72 int32_t overflowWidth = 0;
73 int32_t trailingWidth = 0;
74 };
75
76 // ---- Panel + DockingContainer ----
77 // Panel: a unit of UI content, built by onPanelGUI during OnGUI. DockNodes store only
78 // panel IDs; the Panels live in the DockingLayout.
80 struct Panel {
82 std::string title;
84
87 std::string panelType;
88
90 std::function<void()> onPanelGUI;
91
95 std::function<std::optional<uint64_t>()> cacheSignature;
96
98 std::function<void()> onEnable;
101 std::function<void()> onDisable;
102
115 std::function<void()> onChanged;
116
127 std::function<std::string()> saveState;
128 std::function<void(std::string_view)> restoreState;
129
131 struct Internal
132 {
134 bool enabled = false;
137 bool ownsID = false;
139
143 };
144
159 std::unique_ptr<tachyon::DockNode> root;
160 std::unordered_map<tachyon::ID, Panel> panels;
161
165
167 bool tabsInTitleBar = false;
168 std::function<void()> onDock;
169
173 std::function<void(DockingLayout& layout, tachyon::ID leafNodeID)> newTabMenu;
174 };
175
182
187 };
188
194
195 // ---- Floating dock windows ----
196 // A torn-off tab dropped outside every dock area gets its own OS window.
207
208 // ---- Documents ----
209 // The level above panels: each document owns a whole panel layout, and the document bar
210 // swaps the workspace below it.
231
239 struct DocumentSet {
241 std::vector<std::unique_ptr<Document>> documents;
242 int active = 0;
243
245 std::function<void()> onNew;
247 std::function<void(DockingLayout& layout, tachyon::ID leafNodeID)> newTabMenu;
250 std::function<bool(Document&)> onClose;
254 std::function<void(std::unique_ptr<Document>, tachyon::int2)> onTearOff;
255
257 Document* Active() { return active >= 0 && active < int(documents.size()) ? documents[size_t(active)].get() : nullptr; }
258 const Document* Active() const { return active >= 0 && active < int(documents.size()) ? documents[size_t(active)].get() : nullptr; }
259
269 };
270
276
279 std::string name;
280 std::string extension;
281 std::string kind;
282 std::string layout;
285 std::vector<std::pair<std::string, std::string>> panelStates;
286 };
287
296
299 Document* document = nullptr;
300 DocumentSet* source = nullptr;
301 int32_t tabWidth = 0;
302 int32_t grabOffset = 0;
303 };
304
308 Document* document = nullptr;
309 DocumentSet* source = nullptr;
310 DocumentSet* target = nullptr;
311 int index = 0;
313 };
314
316}
TabBarLayout
How a tab bar lays out tabs that don't fit on one row.
Definition gui_dock_node.h:56
@ OneRow
one row; the tabs that don't fit are listed by a "+N" button after the others
Definition gui_dock_node.h:57
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
@ Invalid
Definition gui_style_text.h:15
WindowMode
A window's state (IWindowBackend::SetWindowMode). Any window can go fullscreen.
Definition gui_window_backend.h:60
@ Normal
as placed (restored)
Definition gui_window_backend.h:61
Definition gui_logging.h:24
Result of FindDockDropTargetAtScreenPos: the drop target and its layout.
Definition gui_docking_types.h:190
DockingLayout * layout
Definition gui_docking_types.h:192
tachyon::DockDropTarget target
Definition gui_docking_types.h:191
A drop location: the leaf under the cursor and the zone within its content area.
Definition gui_dock_node.h:163
Result of FindDockLeafAtScreenPos: the leaf and its layout, both null on a miss.
Definition gui_docking_types.h:184
tachyon::DockNode * leaf
Definition gui_docking_types.h:185
DockingLayout * layout
Definition gui_docking_types.h:186
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
Construction state of the current docking container.
Definition gui_docking_types.h:178
tachyon::ID containerID
Definition gui_docking_types.h:179
DockingLayout * layout
Definition gui_docking_types.h:180
A docking area: the split/tab tree and the panels its leaves refer to by ID.
Definition gui_docking_types.h:158
std::function< void(DockingLayout &layout, tachyon::ID leafNodeID)> newTabMenu
Builds the items of a tab group's "+" menu, after its last tab: the panels that can be added there,...
Definition gui_docking_types.h:173
bool tabsInTitleBar
A torn-off window's layout: a root leaf puts its tabs in the window's title bar.
Definition gui_docking_types.h:167
std::unique_ptr< tachyon::DockNode > root
the dock tree; leaves hold panel tabs
Definition gui_docking_types.h:159
std::unordered_map< tachyon::ID, Panel > panels
every panel of this layout, by ID
Definition gui_docking_types.h:160
std::function< void()> onDock
the title bar's Dock button (none when unset)
Definition gui_docking_types.h:168
tachyon::ID hostWindowID
OS window hosting this layout, refreshed each frame.
Definition gui_docking_types.h:164
A document tab being dragged, for the document bars it passes over; internal.
Definition gui_docking_types.h:298
DocumentSet * source
Definition gui_docking_types.h:300
int32_t grabOffset
from the tab's left edge to where it was pressed, pixels
Definition gui_docking_types.h:302
int32_t tabWidth
pixels
Definition gui_docking_types.h:301
Document * document
Definition gui_docking_types.h:299
A document dropped on another bar or torn off, done at the start of the next frame; internal.
Definition gui_docking_types.h:307
tachyon::int2 screenPos
Definition gui_docking_types.h:312
int index
where in the target
Definition gui_docking_types.h:311
DocumentSet * source
Definition gui_docking_types.h:309
Document * document
Definition gui_docking_types.h:308
DocumentSet * target
null: torn off
Definition gui_docking_types.h:310
Kept by the documents; not part of the API.
Definition gui_docking_types.h:262
tachyon::ID hostWindowID
the OS window it's in
Definition gui_docking_types.h:265
tachyon::IntRect barRect
last frame's, in screen pixels
Definition gui_docking_types.h:266
std::vector< tachyon::IntRect > tabRects
by document; empty for one left out
Definition gui_docking_types.h:267
tachyon::ID tabBarID
Definition gui_docking_types.h:264
tachyon::ID barID
the bar, a drop target for documents
Definition gui_docking_types.h:263
The documents one main window shows, in tab order, and which one is active.
Definition gui_docking_types.h:239
std::function< bool(Document &)> onClose
Asked before a document is closed from its tab: false keeps it open (to ask about unsaved changes fir...
Definition gui_docking_types.h:250
const Document * Active() const
Definition gui_docking_types.h:258
struct tachyon::DocumentSet::Internal internal
not part of the API
Document * Active()
The shown document; null when there are none.
Definition gui_docking_types.h:257
std::function< void(DockingLayout &layout, tachyon::ID leafNodeID)> newTabMenu
Every document's tab groups' "+" menu (DockingLayout::newTabMenu); none when unset.
Definition gui_docking_types.h:247
std::function< void(std::unique_ptr< Document >, tachyon::int2)> onTearOff
A tab dropped outside every document bar: the document, taken out of the set, for a new main window (...
Definition gui_docking_types.h:254
std::function< void()> onNew
The "+" after the last tab; none when unset.
Definition gui_docking_types.h:245
int active
index of the shown document
Definition gui_docking_types.h:242
std::vector< std::unique_ptr< Document > > documents
Boxed, so a document's layout keeps its address (torn-off panels refer to it).
Definition gui_docking_types.h:241
A main window of documents, for PersistDocuments: its OS window and its documents.
Definition gui_docking_types.h:272
const DocumentSet * documents
Definition gui_docking_types.h:274
tachyon::ID windowID
Definition gui_docking_types.h:273
Kept by the documents; not part of the API.
Definition gui_docking_types.h:226
bool closeAsked
its tab asked to close it; done at the next Documents
Definition gui_docking_types.h:228
tachyon::ID dockID
its docking container
Definition gui_docking_types.h:227
A document: a level, prefab, material graph, ... with its own panels.
Definition gui_docking_types.h:212
tachyon::IconID icon
Definition gui_docking_types.h:220
std::string kind
The type, which picks its colors: the classes .document-tab-<kind>, .document-name-<kind> and ....
Definition gui_docking_types.h:219
std::string name
"Forest"
Definition gui_docking_types.h:214
bool dirty
unsaved changes: a dot on its tab
Definition gui_docking_types.h:221
std::string extension
".level", after the name, muted
Definition gui_docking_types.h:215
DockingLayout layout
its panels
Definition gui_docking_types.h:222
struct tachyon::Document::Internal internal
not part of the API
A floating OS window holding torn-off panels in its own layout.
Definition gui_docking_types.h:198
tachyon::int2 spawnPosition
screen pixels, used on the first frame only
Definition gui_docking_types.h:201
bool dockRequested
Dock clicked; done next frame.
Definition gui_docking_types.h:205
DockingLayout * home
layout Dock returns the panels to
Definition gui_docking_types.h:203
tachyon::ID windowID
static, persists across frames
Definition gui_docking_types.h:199
bool positioned
once true, the OS manages the position
Definition gui_docking_types.h:202
tachyon::ID homeLeafID
leaf the panels were torn from
Definition gui_docking_types.h:204
DockingLayout layout
the window's own dock tree and panels
Definition gui_docking_types.h:200
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:406
Kept by the docking; not part of the API.
Definition gui_docking_types.h:132
bool ownsID
CreatePanel made its ID: it goes back when the panel is closed.
Definition gui_docking_types.h:137
bool enabled
onEnable fired without a matching onDisable.
Definition gui_docking_types.h:134
A unit of docked UI content: a title, an optional icon, and the callback that builds it.
Definition gui_docking_types.h:80
tachyon::IconID icon
tab icon
Definition gui_docking_types.h:83
tachyon::int2 scrollOffset
Scroll position, kept here so a hidden tab keeps it (ScrollManagement prunes handles of elements not ...
Definition gui_docking_types.h:142
std::function< void()> onChanged
Called after a frame in which the user acted in the panel: pressed, released or dragged the mouse in ...
Definition gui_docking_types.h:115
std::function< void()> onEnable
Called when the panel becomes visible (its leaf's selected tab).
Definition gui_docking_types.h:98
std::string title
tab label
Definition gui_docking_types.h:82
std::string panelType
Optional kind tag that presets serialize to pick a factory on load.
Definition gui_docking_types.h:87
std::function< void()> onDisable
Called when the panel is hidden.
Definition gui_docking_types.h:101
std::function< void(std::string_view)> restoreState
Definition gui_docking_types.h:128
std::function< std::string()> saveState
The panel's own view state, kept with its layout in the saved UI state (a pan and zoom,...
Definition gui_docking_types.h:127
std::function< void()> onPanelGUI
Builds the panel's content (inside the panel's area); not called while hidden.
Definition gui_docking_types.h:90
std::function< std::optional< uint64_t >()> cacheSignature
Docked panels are cached by default (rebuilt on resize and input inside them).
Definition gui_docking_types.h:95
struct tachyon::Panel::Internal internal
not part of the API
A main window of documents as SaveUIState kept it (TakeSavedDocuments).
Definition gui_docking_types.h:289
tachyon::IntRect rect
where it was, screen pixels; empty when not known
Definition gui_docking_types.h:292
WindowMode mode
Definition gui_docking_types.h:293
std::vector< SavedDocument > documents
in tab order
Definition gui_docking_types.h:290
tachyon::IntRect monitor
the monitor it was on; empty when not known
Definition gui_docking_types.h:294
int active
the one shown
Definition gui_docking_types.h:291
A document as SaveUIState kept it: which one it was, and how its panels were laid out.
Definition gui_docking_types.h:278
std::string name
Definition gui_docking_types.h:279
std::string extension
Definition gui_docking_types.h:280
std::string layout
its dock tree (SerializeDockTree), panels by type, else title
Definition gui_docking_types.h:282
std::vector< std::pair< std::string, std::string > > panelStates
Its panels' own view states (Panel::saveState), by panel key; several of one key in the order they're...
Definition gui_docking_types.h:285
std::string kind
Definition gui_docking_types.h:281
What a tab bar keeps across frames (element data store, by bar ID): its keyboard navigation,...
Definition gui_docking_types.h:65
int32_t overflowWidth
the overflow button's width
Definition gui_docking_types.h:72
std::vector< int32_t > widths
by tab index; a hidden tab keeps its last width
Definition gui_docking_types.h:70
TabBarLayout layout
for a bar whose caller doesn't keep one
Definition gui_docking_types.h:68
int tabCount
last frame's
Definition gui_docking_types.h:66
int32_t trailingWidth
what the caller adds after the tabs, always shown
Definition gui_docking_types.h:73
int32_t barWidth
the bar's inner width
Definition gui_docking_types.h:71
int focusIndex
the tab that takes focus as it's built, after an arrow key
Definition gui_docking_types.h:67
What a tab bar offers besides its tabs.
Definition gui_docking_types.h:29
std::string_view closeLabel
the item of a tab's context menu that closes it
Definition gui_docking_types.h:30
bool layoutMenu
the context menus offer Collapse Rows / Multiple Rows
Definition gui_docking_types.h:34
tachyon::ID dropArea
An element around the bar (its row, say) that counts as the bar while a tab is dragged: in it the tab...
Definition gui_docking_types.h:37
bool listHidden
"+N" after the tabs that fit lists the rest.
Definition gui_docking_types.h:33
Definition gui_docking_types.h:50
int index
Definition gui_docking_types.h:50
std::string text
Definition gui_docking_types.h:50
tachyon::IconID icon
Definition gui_docking_types.h:50
Construction state of the current tab bar; internal.
Definition gui_docking_types.h:41
std::function< void(int)> onClose
tab index, when its close button is clicked
Definition gui_docking_types.h:45
std::vector< HiddenTab > hidden
the tabs left out, listed by the overflow button
Definition gui_docking_types.h:51
tachyon::ID barID
Definition gui_docking_types.h:42
int * selectedIndex
Definition gui_docking_types.h:43
std::function< void(int, tachyon::int2)> onDragOut
tab index and mouse release pos
Definition gui_docking_types.h:46
TabBarOptions options
Definition gui_docking_types.h:48
TabBarLayout * layout
the bar's layout, which its context menu sets
Definition gui_docking_types.h:47
int nextTabIndex
Definition gui_docking_types.h:44
std::vector< bool > shown
by tab index; empty: every tab is shown
Definition gui_docking_types.h:49
Construction state of the current tab, between BeginTab and EndTab; internal.
Definition gui_docking_types.h:55
tachyon::ID bodyID
Definition gui_docking_types.h:58
bool open
BeginTab built it (it wasn't left out).
Definition gui_docking_types.h:56
bool selected
Definition gui_docking_types.h:60
int index
Definition gui_docking_types.h:59
Integer 2D vector.
Definition gui_base_types.h:18