TachyonUI 0.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 <string_view>
22#include <vector>
23
24namespace tachyon
25{
28
29 class GUIApplication;
30
32 enum class ToolbarSide : uint8_t { Top = 0, Right = 1, Bottom = 2, Left = 3 };
33 inline constexpr int kToolbarSideCount = 4;
34
39 {
44
49
50 // Drop overlay animation between sides
51 bool dropAnimHasTarget = false;
54 std::chrono::steady_clock::time_point dropAnimLastTime {};
55 };
56
61
65 {
67 std::string debugName {};
68 std::function<void()> renderBody;
69 };
70
74 {
76 std::function<void(ToolbarSide side, int from, int to)> onReorder;
79 std::function<void(ToolbarSide srcSide, int srcIdx, ToolbarSide tgtSide)> onCrossSideDrop;
82 std::function<void(ToolbarSide srcSide, int srcIdx, int2 mousePos)> onTearOff;
83 };
84
96
102 GUIApplication& app,
103 ToolbarDockState& state,
104 const std::vector<ToolbarItem> (&itemsPerSide)[kToolbarSideCount],
105 const ToolbarDockCallbacks& callbacks,
106 std::function<void()> renderContent);
110 {
115 std::function<void(ID windowID, ToolbarSide tgtSide)> onDockBack;
116 };
117
118 // EmitFloatingToolbarWindows is a GUIApplication member (it needs the protected
119 // BeginWindow / EndWindow): `app.EmitFloatingToolbarWindows(items, opts)`.
120
122} // namespace tachyon
The application: owns the windows, the systems and the frame loop.
Definition gui_application.h:185
void InitializeToolbarDockState(ToolbarDockState &state, GUIApplication &app)
Allocates the state's static IDs; call once before the first RenderToolbarDock.
ToolbarSide
A side of a toolbar dock; indexes the per-side arrays.
Definition controls_toolbar_dock.h:32
constexpr int kToolbarSideCount
number of ToolbarSide values
Definition controls_toolbar_dock.h:33
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:32
@ 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:88
ID windowID
Definition controls_toolbar_dock.h:90
ToolbarItem item
Definition controls_toolbar_dock.h:89
bool positioned
once true, the OS manages the position
Definition controls_toolbar_dock.h:92
ToolbarSide homeSide
where closing the window docks it back
Definition controls_toolbar_dock.h:94
std::string title
Definition controls_toolbar_dock.h:93
int2 spawnPosition
screen pixels, used on the first frame
Definition controls_toolbar_dock.h:91
Enables dragging a floating toolbar back onto a dock side; both fields are required,...
Definition controls_toolbar_dock.h:110
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:115
ToolbarDockState * dockState
Dock whose cachedSideRects are hit-tested on MouseUp (caller-owned; nullptr disables).
Definition controls_toolbar_dock.h:112
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
Callbacks through which RenderToolbarDock changes the caller's data; the dock never touches that data...
Definition controls_toolbar_dock.h:74
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:82
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:79
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:76
Per-instance state for one toolbar dock.
Definition controls_toolbar_dock.h:39
ID groupIDs[kToolbarSideCount]
Definition controls_toolbar_dock.h:40
IntRect dropAnimCurrent
Definition controls_toolbar_dock.h:52
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:47
ID ghostWindowID
Definition controls_toolbar_dock.h:41
bool dropAnimHasTarget
Definition controls_toolbar_dock.h:51
IntRect cachedDockRect
last frame's dock container rect (screen space)
Definition controls_toolbar_dock.h:48
ID dockContainerID
Outer dock container; its rect gives empty (invisible) sides a drop rect.
Definition controls_toolbar_dock.h:43
IntRect dropAnimTarget
Definition controls_toolbar_dock.h:53
std::chrono::steady_clock::time_point dropAnimLastTime
Definition controls_toolbar_dock.h:54
One toolbar item.
Definition controls_toolbar_dock.h:65
std::function< void()> renderBody
Definition controls_toolbar_dock.h:68
std::string debugName
stable name; saved UI state places items by it
Definition controls_toolbar_dock.h:67
Integer 2D vector.
Definition gui_base_types.h:19