TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_element.h
Go to the documentation of this file.
1#pragma once
2
5
7
9
11
12#include <gui_core/gui_id.h>
14
15#include <functional>
16#include <vector>
17
18namespace tachyon
19{
22
23 class GUIRenderer;
24 class ElementStorage;
26
27 // ------------------------------------------------------------------------
28 // Element - Core element data
29 // ------------------------------------------------------------------------
30
50
51 // ------------------------------------------------------------------------
52 // ElementRect
53 // ------------------------------------------------------------------------
54
84
88 using CustomDrawCallback = std::function<void(CustomDrawContext& ctx)>;
89
91
93 using PostLayoutCallback = std::function<void(PostLayoutContext& ctx)>;
94
95 // ------------------------------------------------------------------------
96 // HierarchyInfo
97 // ------------------------------------------------------------------------
98
100 {
101 inline static constexpr HierarchyInfo Initialize(uint32_t parentIndex)
102 {
103 return HierarchyInfo
104 {
105 .parentIndex = parentIndex,
106 .nextSiblingIndex = HierarchyInfo::kInvalidNextIndex,
107 .childOffset = 0,
108 .childCount = 0
109 };
110 }
111
112 static constexpr uint32_t kInvalidNextIndex = std::numeric_limits<uint32_t>::max();
113
114 uint32_t parentIndex = 0;
116 uint32_t childOffset = 0;
117 uint32_t childCount = 0;
118 };
119
120 // ------------------------------------------------------------------------
121 // ElementRef - Identifies an element by (depth, index)
122 // ------------------------------------------------------------------------
123
126 {
127 uint32_t depth = 0;
128
130 uint32_t index = 0;
131
132 inline constexpr bool IsRoot() const { return depth == 0; }
133 inline constexpr bool IsValid() const { return depth != std::numeric_limits<uint32_t>::max() && index != std::numeric_limits<uint32_t>::max(); }
134 static constexpr ElementRef Invalid() { return ElementRef{ std::numeric_limits<uint32_t>::max() , std::numeric_limits<uint32_t>::max() }; }
135 inline bool operator==(const ElementRef& rhs) const { return depth == rhs.depth && index == rhs.index; }
136 inline bool operator!=(const ElementRef& rhs) const { return !(*this == rhs); }
137
139 inline uint64_t HashCode() const noexcept
140 {
141 return (static_cast<uint64_t>(depth) << 32) | static_cast<uint64_t>(index);
142 }
143 };
144
147 {
148 uint32_t begin = 0;
149 uint32_t end = 0;
150
151 inline bool Empty() const { return end == begin; }
152 inline uint32_t Size() const { return end - begin; }
153
154 bool operator==(const IndexRange& rhs) const = default;
155 bool operator!=(const IndexRange& rhs) const = default;
156 };
157
161 {
162 struct Rotation { uint32_t depth, begin, mid, end; }; // std::rotate(begin, mid, end)
163 std::vector<Rotation> rotations;
164 uint32_t childDepth = 0;
165 uint32_t siblingsBegin = 0;
166 uint32_t siblingsEnd = 0;
167
170 {
171 for (const Rotation& r : rotations)
172 {
173 if (ref.depth != r.depth || ref.index < r.begin || ref.index >= r.end) continue;
174 ref.index = (ref.index < r.mid) ? ref.index + (r.end - r.mid) : ref.index - (r.mid - r.begin);
175 }
176 return ref;
177 }
178 };
179
187
205
207} // namespace tachyon
Passed to custom-draw callbacks (ElementStorage::AddCustomDraw / AddCustomDrawAfter): geometry lookup...
Definition gui_custom_draw_context.h:43
The frame's element tree.
Definition gui_element_storage.h:96
Definition gui_renderer.h:78
Context for post-layout callbacks (AddPostLayout).
Definition gui_custom_draw_context.h:232
std::function< void(PostLayoutContext &ctx)> PostLayoutCallback
Runs after layout, before rendering, with read-only access to final rects/transforms.
Definition gui_element.h:93
IntRect innerRect
Padding box (screen space).
Definition gui_element.h:60
IntRect rect
Computed during layout.
Definition gui_element.h:59
ElementFlags
What an element is and how it behaves, combined with |.
Definition gui_element_flags.h:17
IntRect contentBounds
Bounds of all children (parent-local space).
Definition gui_element.h:62
std::function< void(CustomDrawContext &ctx)> CustomDrawCallback
Render-time callback.
Definition gui_element.h:88
IntRect clipRect
Clip bounds (screen space).
Definition gui_element.h:61
@ None
Definition gui_element_flags.h:18
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
@ Invalid
Definition gui_image.h:99
std::function< bool(ElementEvent &&input)> EventHandler
Element-level input handler used by the immediate-mode dispatcher; returns true when it consumed the ...
Definition gui_input_handler_func.h:35
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
Display
How an element lays out its children (CSS: display).
Definition gui_style.h:226
TextID
Handle for text registered with the text system (ITextSystem::RegisterText and friends).
Definition gui_style_text.h:13
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
ElementState
Interaction state bits of an element; they pick the Style::states variant it draws with.
Definition gui_style.h:42
@ Invalid
Definition gui_style_text.h:13
@ Invalid
Definition gui_style_text.h:15
@ None
Definition gui_style.h:43
Definition gui_logging.h:24
callback fires before the children render; the after-list fires after the whole subtree.
Definition gui_element.h:192
float afterDrawOpacity
how opaque the owner is drawn
Definition gui_element.h:203
CustomDrawCallback callback
fires before this element's children
Definition gui_element.h:193
IntRect afterDrawClipRectScreen
SCREEN-space scissor.
Definition gui_element.h:197
uint32_t afterHead
head of the after-draw list
Definition gui_element.h:194
IntRect afterDrawElementRectLayout
LAYOUT-space border-box.
Definition gui_element.h:198
float3x2 afterDrawRenderTransform
inner-rect-local LAYOUT -> SCREEN pixels
Definition gui_element.h:200
uint32_t afterTail
tail, for O(1) append
Definition gui_element.h:195
float4 afterDrawPixelRect
the element's border box in window pixels
Definition gui_element.h:201
IntRect afterDrawInnerRectLayout
LAYOUT-space padding-box.
Definition gui_element.h:199
IntRect afterDrawSnappedRect
snapped pixel rect custom-draw boxes snap to
Definition gui_element.h:202
Definition gui_element.h:162
uint32_t end
Definition gui_element.h:162
uint32_t mid
Definition gui_element.h:162
uint32_t begin
Definition gui_element.h:162
uint32_t depth
Definition gui_element.h:162
What a MoveChild did: the slot rotations it applied at each depth, so code that stores ElementRefs (e...
Definition gui_element.h:161
ElementRef Remap(ElementRef ref) const
Where ref sits after the move.
Definition gui_element.h:169
uint32_t siblingsEnd
Definition gui_element.h:166
uint32_t siblingsBegin
absolute slot range of the siblings that changed order
Definition gui_element.h:165
std::vector< Rotation > rotations
Definition gui_element.h:163
uint32_t childDepth
depth of the moved siblings
Definition gui_element.h:164
Definition gui_element.h:56
int2 scrollOffset
Definition gui_element.h:64
int16_t minContentWidth
Leaf with visibly overflowing text: the margin box width flex shrink stops at (CSS min-content).
Definition gui_element.h:79
int16_t monitorIndex
window elements only: the monitor the window is on
Definition gui_element.h:73
const LayoutStyle * layoutStyle
Definition gui_element.h:68
LayoutOverride constraints
Definition gui_element.h:66
Display display
Definition gui_element.h:75
uint16_t wrapLineIndex
row-wrap line, set by horizontal and read by vertical positioning
Definition gui_element.h:76
ElementFlags flags
Definition gui_element.h:74
int32_t anchorTargetX
Anchored X: the target's x when X was placed (flipped or clamped to the screen).
Definition gui_element.h:82
float3x2 contentTransform
Applied to children at render/hit-test time; layout ignores it except for scroll clamping.
Definition gui_element.h:71
An element's slot in ElementStorage: its depth and index within that depth.
Definition gui_element.h:126
static constexpr ElementRef Invalid()
Definition gui_element.h:134
bool operator!=(const ElementRef &rhs) const
Definition gui_element.h:136
constexpr bool IsRoot() const
Definition gui_element.h:132
bool operator==(const ElementRef &rhs) const
Definition gui_element.h:135
constexpr bool IsValid() const
Definition gui_element.h:133
uint64_t HashCode() const noexcept
A 64-bit key: depth in the high 32 bits, index in the low 32.
Definition gui_element.h:139
uint32_t depth
Definition gui_element.h:127
uint32_t index
Index into the depth's array, which holds children of many parents.
Definition gui_element.h:130
Definition gui_element.h:32
int16_t monitorIndex
window elements only: the monitor the window is on
Definition gui_element.h:42
EventHandler eventHandler
Per-frame input handler for immediate-mode widgets.
Definition gui_element.h:36
ElementState state
Definition gui_element.h:44
ImageIndex backgroundImage
Definition gui_element.h:46
TextID textID
Definition gui_element.h:38
ElementFlags flags
Definition gui_element.h:43
IconID iconID
Definition gui_element.h:39
VisualColorStyleIndex colorStyleIndex
Background ColorStyle override (solid or gradient); Invalid uses the box style's background.
Definition gui_element.h:48
StyleRef styleRef
Definition gui_element.h:41
Definition gui_element.h:100
uint32_t childOffset
First child index at depth + 1.
Definition gui_element.h:116
uint32_t parentIndex
Parent index at depth - 1.
Definition gui_element.h:114
static constexpr uint32_t kInvalidNextIndex
Definition gui_element.h:112
static constexpr HierarchyInfo Initialize(uint32_t parentIndex)
Definition gui_element.h:101
uint32_t childCount
Definition gui_element.h:117
uint32_t nextSiblingIndex
Next sibling at same depth.
Definition gui_element.h:115
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
A half-open range [begin, end) of indices within one depth.
Definition gui_element.h:147
uint32_t begin
Definition gui_element.h:148
uint32_t Size() const
Definition gui_element.h:152
bool operator!=(const IndexRange &rhs) const =default
bool operator==(const IndexRange &rhs) const =default
bool Empty() const
Definition gui_element.h:151
uint32_t end
exclusive
Definition gui_element.h:149
Definition gui_base_types.h:406
Per-element overrides of style layout properties.
Definition gui_constraints.h:151
The layout part of a registered Style, in pixels; shared by every style with the same values.
Definition gui_style.h:772
Node in the flat post-draw linked list stored in ElementStorage.
Definition gui_element.h:182
CustomDrawCallback callback
Definition gui_element.h:183
uint32_t nextIndex
next entry index, UINT32_MAX = end of list
Definition gui_element.h:185
ElementRef ownerRef
element that registered AddCustomDrawAfter
Definition gui_element.h:184
A registered style, as StyleManager::Register returns it: indices into the shared style pools,...
Definition gui_style_ref.h:25
2D affine transform matrix (2 rows x 3 columns): x' = r0.x*x + r0.y*y + r0.z y' = r1....
Definition gui_base_types.h:218
Definition gui_base_types.h:173
Integer 2D vector.
Definition gui_base_types.h:18