TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
controls_toolbar_dock.h
Go to the documentation of this file.
1#pragma once
2
3// ---------------------------------------------------------------------------
4// Toolbar dock - frames a central content area with up to four sides of
5// reorderable toolbar items, which can also be dragged between sides. Drop
6// feedback matches the dock-tab drop indicator (controls_docking.cpp).
7//
8// The caller owns the data model (per-side item lists passed each frame) and
9// applies changes from callbacks. ToolbarDockState holds the IDs, rect cache,
10// ghost window and drop animation.
11//
12// The rect cache exists because the drag visualizer runs during construction,
13// before layout; it reads last frame's rects (like DockNode::cachedLeafRect).
14// ---------------------------------------------------------------------------
15
16#include <gui_core/gui_id.h>
18
19#include <chrono>
20#include <functional>
21#include <span>
22#include <string>
23#include <string_view>
24#include <vector>
25
26namespace tachyon
27{
30
31 class GUIApplication;
32
34 enum class ToolbarSide : uint8_t { Top = 0, Right = 1, Bottom = 2, Left = 3 };
35 inline constexpr int kToolbarSideCount = 4;
36
41 {
48 bool overlay = false;
49
54
55 // Drop overlay animation between sides
56 bool dropAnimHasTarget = false;
59 std::chrono::steady_clock::time_point dropAnimLastTime {};
60 };
61
66
70 {
72 std::string debugName {};
73 std::function<void()> renderBody;
74 };
75
79 {
81 std::function<void(ToolbarSide side, int from, int to)> onReorder;
84 std::function<void(ToolbarSide srcSide, int srcIdx, ToolbarSide tgtSide)> onCrossSideDrop;
87 std::function<void(ToolbarSide srcSide, int srcIdx, int2 mousePos)> onTearOff;
88 };
89
101
107 GUIApplication& app,
108 ToolbarDockState& state,
109 const std::vector<ToolbarItem> (&itemsPerSide)[kToolbarSideCount],
110 const ToolbarDockCallbacks& callbacks,
111 std::function<void()> renderContent);
115 {
120 std::function<void(ID windowID, ToolbarSide tgtSide)> onDockBack;
121 };
122
125 std::string SaveToolbarLayout(std::span<const std::vector<ToolbarItem>, kToolbarSideCount> sides);
128 bool ApplyToolbarLayout(std::span<std::vector<ToolbarItem>, kToolbarSideCount> sides, std::string_view text);
129
130 // EmitFloatingToolbarWindows is a GUIApplication member (it needs the protected
131 // BeginWindow / EndWindow): `app.EmitFloatingToolbarWindows(items, opts)`.
132
134} // namespace tachyon
The application: owns the windows, the systems and the frame loop.
Definition gui_application.h:209
void InitializeToolbarDockState(ToolbarDockState &state, GUIApplication &app)
Allocates the state's static IDs; call once before the first RenderToolbarDock.
std::string SaveToolbarLayout(std::span< const std::vector< ToolbarItem >, kToolbarSideCount > sides)
Each side's items, by debugName, as text: for a dock that saves with something of its own (a panel's ...
bool ApplyToolbarLayout(std::span< std::vector< ToolbarItem >, kToolbarSideCount > sides, std::string_view text)
Puts each item text names on its saved side and place; the rest stay where they are.
ToolbarSide
A side of a toolbar dock; indexes the per-side arrays.
Definition controls_toolbar_dock.h:34
constexpr int kToolbarSideCount
number of ToolbarSide values
Definition controls_toolbar_dock.h:35
void RenderToolbarDock(GUIApplication &app, ToolbarDockState &state, const std::vector< ToolbarItem >(&itemsPerSide)[kToolbarSideCount], const ToolbarDockCallbacks &callbacks, std::function< void()> renderContent)
Renders the 5-zone scaffold (top / left | content | right / bottom) with a reorderable group per side...
void ReleaseToolbarDockState(ToolbarDockState &state, GUIApplication &app)
Releases the IDs allocated by InitializeToolbarDockState.
@ Top
Definition controls_toolbar_dock.h:34
@ 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
Definition gui_logging.h:24
A torn-off toolbar in its own OS window, owned by the caller.
Definition controls_toolbar_dock.h:93
ID windowID
Definition controls_toolbar_dock.h:95
ToolbarItem item
Definition controls_toolbar_dock.h:94
bool positioned
once true, the OS manages the position
Definition controls_toolbar_dock.h:97
ToolbarSide homeSide
where closing the window docks it back
Definition controls_toolbar_dock.h:99
std::string title
Definition controls_toolbar_dock.h:98
int2 spawnPosition
screen pixels, used on the first frame
Definition controls_toolbar_dock.h:96
Enables dragging a floating toolbar back onto a dock side; both fields are required,...
Definition controls_toolbar_dock.h:115
std::function< void(ID windowID, ToolbarSide tgtSide)> onDockBack
Released over tgtSide, or the window closed (tgtSide = its homeSide): the caller moves the item into ...
Definition controls_toolbar_dock.h:120
ToolbarDockState * dockState
Dock whose cachedSideRects are hit-tested on MouseUp (caller-owned; nullptr disables).
Definition controls_toolbar_dock.h:117
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
Callbacks through which RenderToolbarDock changes the caller's data; the dock never touches that data...
Definition controls_toolbar_dock.h:79
std::function< void(ToolbarSide srcSide, int srcIdx, int2 mousePos)> onTearOff
Released outside every side: the caller moves the item to its floating list (new static windowID,...
Definition controls_toolbar_dock.h:87
std::function< void(ToolbarSide srcSide, int srcIdx, ToolbarSide tgtSide)> onCrossSideDrop
Item srcIdx of srcSide was dropped on tgtSide: the caller appends it to tgtSide and erases it from sr...
Definition controls_toolbar_dock.h:84
std::function< void(ToolbarSide side, int from, int to)> onReorder
An item moved within side from index from to to.
Definition controls_toolbar_dock.h:81
Per-instance state for one toolbar dock.
Definition controls_toolbar_dock.h:41
ID groupIDs[kToolbarSideCount]
Definition controls_toolbar_dock.h:42
IntRect dropAnimCurrent
Definition controls_toolbar_dock.h:57
IntRect cachedSideRects[kToolbarSideCount]
Last frame's side rects (screen space), written by SyncToolbarDockRects at the end of the frame; drag...
Definition controls_toolbar_dock.h:52
bool overlay
The toolbars float over the content's edges (a 3D view) instead of taking room beside it; between the...
Definition controls_toolbar_dock.h:48
ID ghostWindowID
Definition controls_toolbar_dock.h:43
bool dropAnimHasTarget
Definition controls_toolbar_dock.h:56
IntRect cachedDockRect
last frame's dock container rect (screen space)
Definition controls_toolbar_dock.h:53
ID dockContainerID
Outer dock container; its rect gives empty (invisible) sides a drop rect.
Definition controls_toolbar_dock.h:45
IntRect dropAnimTarget
Definition controls_toolbar_dock.h:58
std::chrono::steady_clock::time_point dropAnimLastTime
Definition controls_toolbar_dock.h:59
One toolbar item.
Definition controls_toolbar_dock.h:70
std::function< void()> renderBody
Definition controls_toolbar_dock.h:73
std::string debugName
stable name; saved UI state places items by it
Definition controls_toolbar_dock.h:72
Integer 2D vector.
Definition gui_base_types.h:18