TachyonUI 0.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>
15
16#include <functional>
17#include <vector>
18
19namespace tachyon
20{
23
24 class GUIRenderer;
25 class ElementStorage;
27
28 // ------------------------------------------------------------------------
29 // Element - Core element data
30 // ------------------------------------------------------------------------
31
51
52 // ------------------------------------------------------------------------
53 // ElementRect
54 // ------------------------------------------------------------------------
55
85
89 using CustomDrawCallback = std::function<void(CustomDrawContext& ctx)>;
90
92
94 using PostLayoutCallback = std::function<void(PostLayoutContext& ctx)>;
95
96 // ------------------------------------------------------------------------
97 // HierarchyInfo
98 // ------------------------------------------------------------------------
99
101 {
102 inline static constexpr HierarchyInfo Initialize(uint32_t parentIndex)
103 {
104 return HierarchyInfo
105 {
106 .parentIndex = parentIndex,
107 .nextSiblingIndex = HierarchyInfo::kInvalidNextIndex,
108 .childOffset = 0,
109 .childCount = 0
110 };
111 }
112
113 static constexpr uint32_t kInvalidNextIndex = std::numeric_limits<uint32_t>::max();
114
115 uint32_t parentIndex = 0;
117 uint32_t childOffset = 0;
118 uint32_t childCount = 0;
119 };
120
121 // ------------------------------------------------------------------------
122 // ElementRef - Identifies an element by (depth, index)
123 // ------------------------------------------------------------------------
124
127 {
128 uint32_t depth = 0;
129
131 uint32_t index = 0;
132
133 inline constexpr bool IsRoot() const { return depth == 0; }
134 inline constexpr bool IsValid() const { return depth != std::numeric_limits<uint32_t>::max() && index != std::numeric_limits<uint32_t>::max(); }
135 static constexpr ElementRef Invalid() { return ElementRef{ std::numeric_limits<uint32_t>::max() , std::numeric_limits<uint32_t>::max() }; }
136 inline bool operator==(const ElementRef& rhs) const { return depth == rhs.depth && index == rhs.index; }
137 inline bool operator!=(const ElementRef& rhs) const { return !(*this == rhs); }
138
140 inline uint64_t HashCode() const noexcept
141 {
142 return (static_cast<uint64_t>(depth) << 32) | static_cast<uint64_t>(index);
143 }
144 };
145
148 {
149 uint32_t begin = 0;
150 uint32_t end = 0;
151
152 inline bool Empty() const { return end == begin; }
153 inline uint32_t Size() const { return end - begin; }
154
155 bool operator==(const IndexRange& rhs) const = default;
156 bool operator!=(const IndexRange& rhs) const = default;
157 };
158
162 {
163 struct Rotation { uint32_t depth, begin, mid, end; }; // std::rotate(begin, mid, end)
164 std::vector<Rotation> rotations;
165 uint32_t childDepth = 0;
166 uint32_t siblingsBegin = 0;
167 uint32_t siblingsEnd = 0;
168
171 {
172 for (const Rotation& r : rotations)
173 {
174 if (ref.depth != r.depth || ref.index < r.begin || ref.index >= r.end) continue;
175 ref.index = (ref.index < r.mid) ? ref.index + (r.end - r.mid) : ref.index - (r.mid - r.begin);
176 }
177 return ref;
178 }
179 };
180
188
206
208} // 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:100
Definition gui_renderer.h:43
Context for post-layout callbacks (AddPostLayout).
Definition gui_custom_draw_context.h:219
std::function< void(PostLayoutContext &ctx)> PostLayoutCallback
Runs after layout, before rendering, with read-only access to final rects/transforms.
Definition gui_element.h:94
IntRect innerRect
Padding box (screen space).
Definition gui_element.h:61
IntRect rect
Computed during layout.
Definition gui_element.h:60
ElementFlags
What an element is and how it behaves, combined with |.
Definition gui_element_flags.h:18
IntRect contentBounds
Bounds of all children (parent-local space).
Definition gui_element.h:63
std::function< void(CustomDrawContext &ctx)> CustomDrawCallback
Render-time callback.
Definition gui_element.h:89
IntRect clipRect
Clip bounds (screen space).
Definition gui_element.h:62
@ None
Definition gui_element_flags.h:19
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:37
@ Invalid
Definition gui_image.h:37
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:193
float afterDrawOpacity
how opaque the owner is drawn
Definition gui_element.h:204
CustomDrawCallback callback
fires before this element's children
Definition gui_element.h:194
IntRect afterDrawClipRectScreen
SCREEN-space scissor.
Definition gui_element.h:198
uint32_t afterHead
head of the after-draw list
Definition gui_element.h:195
IntRect afterDrawElementRectLayout
LAYOUT-space border-box.
Definition gui_element.h:199
float3x2 afterDrawRenderTransform
inner-rect-local LAYOUT -> SCREEN pixels
Definition gui_element.h:201
uint32_t afterTail
tail, for O(1) append
Definition gui_element.h:196
float4 afterDrawPixelRect
the element's border box in window pixels
Definition gui_element.h:202
IntRect afterDrawInnerRectLayout
LAYOUT-space padding-box.
Definition gui_element.h:200
IntRect afterDrawSnappedRect
snapped pixel rect custom-draw boxes snap to
Definition gui_element.h:203
Definition gui_element.h:163
uint32_t end
Definition gui_element.h:163
uint32_t mid
Definition gui_element.h:163
uint32_t begin
Definition gui_element.h:163
uint32_t depth
Definition gui_element.h:163
What a MoveChild did: the slot rotations it applied at each depth, so code that stores ElementRefs (e...
Definition gui_element.h:162
ElementRef Remap(ElementRef ref) const
Where ref sits after the move.
Definition gui_element.h:170
uint32_t siblingsEnd
Definition gui_element.h:167
uint32_t siblingsBegin
absolute slot range of the siblings that changed order
Definition gui_element.h:166
std::vector< Rotation > rotations
Definition gui_element.h:164
uint32_t childDepth
depth of the moved siblings
Definition gui_element.h:165
Definition gui_element.h:57
int2 scrollOffset
Definition gui_element.h:65
int16_t minContentWidth
Leaf with visibly overflowing text: the margin box width flex shrink stops at (CSS min-content).
Definition gui_element.h:80
int16_t monitorIndex
window elements only: the monitor the window is on
Definition gui_element.h:74
const LayoutStyle * layoutStyle
Definition gui_element.h:69
LayoutOverride constraints
Definition gui_element.h:67
Display display
Definition gui_element.h:76
uint16_t wrapLineIndex
row-wrap line, set by horizontal and read by vertical positioning
Definition gui_element.h:77
ElementFlags flags
Definition gui_element.h:75
int32_t anchorTargetX
Anchored X: the target's x when X was placed (flipped or clamped to the screen).
Definition gui_element.h:83
float3x2 contentTransform
Applied to children at render/hit-test time; layout ignores it except for scroll clamping.
Definition gui_element.h:72
An element's slot in ElementStorage: its depth and index within that depth.
Definition gui_element.h:127
static constexpr ElementRef Invalid()
Definition gui_element.h:135
bool operator!=(const ElementRef &rhs) const
Definition gui_element.h:137
constexpr bool IsRoot() const
Definition gui_element.h:133
bool operator==(const ElementRef &rhs) const
Definition gui_element.h:136
constexpr bool IsValid() const
Definition gui_element.h:134
uint64_t HashCode() const noexcept
A 64-bit key: depth in the high 32 bits, index in the low 32.
Definition gui_element.h:140
uint32_t depth
Definition gui_element.h:128
uint32_t index
Index into the depth's array, which holds children of many parents.
Definition gui_element.h:131
Definition gui_element.h:33
int16_t monitorIndex
window elements only: the monitor the window is on
Definition gui_element.h:43
EventHandler eventHandler
Per-frame input handler for immediate-mode widgets.
Definition gui_element.h:37
ElementState state
Definition gui_element.h:45
ImageIndex backgroundImage
Definition gui_element.h:47
TextID textID
Definition gui_element.h:39
ElementFlags flags
Definition gui_element.h:44
IconID iconID
Definition gui_element.h:40
VisualColorStyleIndex colorStyleIndex
Background ColorStyle override (solid or gradient); Invalid uses the box style's background.
Definition gui_element.h:49
StyleRef styleRef
Definition gui_element.h:42
Definition gui_element.h:101
uint32_t childOffset
First child index at depth + 1.
Definition gui_element.h:117
uint32_t parentIndex
Parent index at depth - 1.
Definition gui_element.h:115
static constexpr uint32_t kInvalidNextIndex
Definition gui_element.h:113
static constexpr HierarchyInfo Initialize(uint32_t parentIndex)
Definition gui_element.h:102
uint32_t childCount
Definition gui_element.h:118
uint32_t nextSiblingIndex
Next sibling at same depth.
Definition gui_element.h:116
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:148
uint32_t begin
Definition gui_element.h:149
uint32_t Size() const
Definition gui_element.h:153
bool operator!=(const IndexRange &rhs) const =default
bool operator==(const IndexRange &rhs) const =default
bool Empty() const
Definition gui_element.h:152
uint32_t end
exclusive
Definition gui_element.h:150
Definition gui_base_types.h:407
Per-element overrides of style layout properties.
Definition gui_constraints.h:150
The layout part of a registered Style, in pixels; shared by every style with the same values.
Definition gui_style.h:755
Node in the flat post-draw linked list stored in ElementStorage.
Definition gui_element.h:183
CustomDrawCallback callback
Definition gui_element.h:184
uint32_t nextIndex
next entry index, UINT32_MAX = end of list
Definition gui_element.h:186
ElementRef ownerRef
element that registered AddCustomDrawAfter
Definition gui_element.h:185
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:219
Definition gui_base_types.h:174
Integer 2D vector.
Definition gui_base_types.h:19