TachyonUI 0.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
104 struct Internal
105 {
107 bool enabled = false;
109
113 };
114
126 std::unique_ptr<tachyon::DockNode> root;
127 std::unordered_map<tachyon::ID, Panel> panels;
128
132
134 bool tabsInTitleBar = false;
135 std::function<void()> onDock;
136 };
137
144
149 };
150
156
157 // ---- Floating dock windows ----
158 // A torn-off tab dropped outside every dock area gets its own OS window.
169
170 // ---- Documents ----
171 // The level above panels: each document owns a whole panel layout, and the document bar
172 // swaps the workspace below it.
193
201 struct DocumentSet {
203 std::vector<std::unique_ptr<Document>> documents;
204 int active = 0;
205
207 std::function<void()> onNew;
210 std::function<bool(Document&)> onClose;
214 std::function<void(std::unique_ptr<Document>, tachyon::int2)> onTearOff;
215
217 Document* Active() { return active >= 0 && active < int(documents.size()) ? documents[size_t(active)].get() : nullptr; }
218 const Document* Active() const { return active >= 0 && active < int(documents.size()) ? documents[size_t(active)].get() : nullptr; }
219
229 };
230
236
239 std::string name;
240 std::string extension;
241 std::string kind;
242 std::string layout;
243 };
244
253
256 Document* document = nullptr;
257 DocumentSet* source = nullptr;
258 int32_t tabWidth = 0;
259 int32_t grabOffset = 0;
260 };
261
265 Document* document = nullptr;
266 DocumentSet* source = nullptr;
267 DocumentSet* target = nullptr;
268 int index = 0;
270 };
271
273}
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:152
DockingLayout * layout
Definition gui_docking_types.h:154
tachyon::DockDropTarget target
Definition gui_docking_types.h:153
A drop location: the leaf under the cursor and the zone within its content area.
Definition gui_dock_node.h:159
Result of FindDockLeafAtScreenPos: the leaf and its layout, both null on a miss.
Definition gui_docking_types.h:146
tachyon::DockNode * leaf
Definition gui_docking_types.h:147
DockingLayout * layout
Definition gui_docking_types.h:148
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:140
tachyon::ID containerID
Definition gui_docking_types.h:141
DockingLayout * layout
Definition gui_docking_types.h:142
A docking area: the split/tab tree and the panels its leaves refer to by ID.
Definition gui_docking_types.h:125
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:134
std::unique_ptr< tachyon::DockNode > root
the dock tree; leaves hold panel tabs
Definition gui_docking_types.h:126
std::unordered_map< tachyon::ID, Panel > panels
every panel of this layout, by ID
Definition gui_docking_types.h:127
std::function< void()> onDock
the title bar's Dock button (none when unset)
Definition gui_docking_types.h:135
tachyon::ID hostWindowID
OS window hosting this layout, refreshed each frame.
Definition gui_docking_types.h:131
A document tab being dragged, for the document bars it passes over; internal.
Definition gui_docking_types.h:255
DocumentSet * source
Definition gui_docking_types.h:257
int32_t grabOffset
from the tab's left edge to where it was pressed, pixels
Definition gui_docking_types.h:259
int32_t tabWidth
pixels
Definition gui_docking_types.h:258
Document * document
Definition gui_docking_types.h:256
A document dropped on another bar or torn off, done at the start of the next frame; internal.
Definition gui_docking_types.h:264
tachyon::int2 screenPos
Definition gui_docking_types.h:269
int index
where in the target
Definition gui_docking_types.h:268
DocumentSet * source
Definition gui_docking_types.h:266
Document * document
Definition gui_docking_types.h:265
DocumentSet * target
null: torn off
Definition gui_docking_types.h:267
Kept by the documents; not part of the API.
Definition gui_docking_types.h:222
tachyon::ID hostWindowID
the OS window it's in
Definition gui_docking_types.h:225
tachyon::IntRect barRect
last frame's, in screen pixels
Definition gui_docking_types.h:226
std::vector< tachyon::IntRect > tabRects
by document; empty for one left out
Definition gui_docking_types.h:227
tachyon::ID tabBarID
Definition gui_docking_types.h:224
tachyon::ID barID
the bar, a drop target for documents
Definition gui_docking_types.h:223
The documents one main window shows, in tab order, and which one is active.
Definition gui_docking_types.h:201
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:210
const Document * Active() const
Definition gui_docking_types.h:218
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:217
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:214
std::function< void()> onNew
The "+" after the last tab; none when unset.
Definition gui_docking_types.h:207
int active
index of the shown document
Definition gui_docking_types.h:204
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:203
A main window of documents, for PersistDocuments: its OS window and its documents.
Definition gui_docking_types.h:232
const DocumentSet * documents
Definition gui_docking_types.h:234
tachyon::ID windowID
Definition gui_docking_types.h:233
Kept by the documents; not part of the API.
Definition gui_docking_types.h:188
bool closeAsked
its tab asked to close it; done at the next Documents
Definition gui_docking_types.h:190
tachyon::ID dockID
its docking container
Definition gui_docking_types.h:189
A document: a level, prefab, material graph, ... with its own panels.
Definition gui_docking_types.h:174
tachyon::IconID icon
Definition gui_docking_types.h:182
std::string kind
The type, which picks its colors: the classes .document-tab-<kind>, .document-name-<kind> and ....
Definition gui_docking_types.h:181
std::string name
"Forest"
Definition gui_docking_types.h:176
bool dirty
unsaved changes: a dot on its tab
Definition gui_docking_types.h:183
std::string extension
".level", after the name, muted
Definition gui_docking_types.h:177
DockingLayout layout
its panels
Definition gui_docking_types.h:184
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:160
tachyon::int2 spawnPosition
screen pixels, used on the first frame only
Definition gui_docking_types.h:163
bool dockRequested
Dock clicked; done next frame.
Definition gui_docking_types.h:167
DockingLayout * home
layout Dock returns the panels to
Definition gui_docking_types.h:165
tachyon::ID windowID
static, persists across frames
Definition gui_docking_types.h:161
bool positioned
once true, the OS manages the position
Definition gui_docking_types.h:164
tachyon::ID homeLeafID
leaf the panels were torn from
Definition gui_docking_types.h:166
DockingLayout layout
the window's own dock tree and panels
Definition gui_docking_types.h:162
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
Kept by the docking; not part of the API.
Definition gui_docking_types.h:105
bool enabled
onEnable fired without a matching onDisable.
Definition gui_docking_types.h:107
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:112
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()> 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:246
tachyon::IntRect rect
where it was, screen pixels; empty when not known
Definition gui_docking_types.h:249
WindowMode mode
Definition gui_docking_types.h:250
std::vector< SavedDocument > documents
in tab order
Definition gui_docking_types.h:247
tachyon::IntRect monitor
the monitor it was on; empty when not known
Definition gui_docking_types.h:251
int active
the one shown
Definition gui_docking_types.h:248
A document as SaveUIState kept it: which one it was, and how its panels were laid out.
Definition gui_docking_types.h:238
std::string name
Definition gui_docking_types.h:239
std::string extension
Definition gui_docking_types.h:240
std::string layout
its dock tree (SerializeDockTree), panels by type, else title
Definition gui_docking_types.h:242
std::string kind
Definition gui_docking_types.h:241
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:19