@geastack/engine 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +29 -0
- package/bitmap_font.cpp +165 -0
- package/canvas.cpp +4608 -0
- package/components/Button.d.ts +4 -0
- package/components/Button.tsx +32 -0
- package/components/Image.d.ts +3 -0
- package/components/Image.tsx +17 -0
- package/components/Text.d.ts +3 -0
- package/components/Text.tsx +9 -0
- package/components/View.d.ts +3 -0
- package/components/View.tsx +24 -0
- package/components/index.d.ts +8 -0
- package/components/index.ts +4 -0
- package/css/animation.h +252 -0
- package/css/declarative.h +131 -0
- package/css/easing.h +160 -0
- package/css/engine.h +223 -0
- package/css/interpolate.h +38 -0
- package/image_store.cpp +807 -0
- package/package.json +62 -0
- package/rasterized_font.cpp +570 -0
- package/touch_runtime.cpp +513 -0
- package/ui/absolute_leaf_refresh.cpp +279 -0
- package/ui/absolute_leaf_refresh.h +12 -0
- package/ui/canvas_element.cpp +2314 -0
- package/ui/canvas_element.h +353 -0
- package/ui/canvas_store.cpp +188 -0
- package/ui/canvas_store.h +59 -0
- package/ui/core.cpp +135 -0
- package/ui/css_atom.cpp +155 -0
- package/ui/css_atom.h +21 -0
- package/ui/dirty_regions.cpp +66 -0
- package/ui/dirty_regions.h +34 -0
- package/ui/display_invalidation.cpp +101 -0
- package/ui/display_invalidation.h +15 -0
- package/ui/document.cpp +356 -0
- package/ui/document.h +101 -0
- package/ui/image.h +16 -0
- package/ui/image_element.cpp +13 -0
- package/ui/image_node.cpp +165 -0
- package/ui/input.cpp +936 -0
- package/ui/input_render.cpp +213 -0
- package/ui/internal.h +567 -0
- package/ui/layout.cpp +2025 -0
- package/ui/layout_snapshot.cpp +82 -0
- package/ui/layout_snapshot.h +12 -0
- package/ui/mirror.h +25 -0
- package/ui/node.cpp +243 -0
- package/ui/node.h +154 -0
- package/ui/node_lifecycle.cpp +137 -0
- package/ui/node_lifecycle.h +13 -0
- package/ui/node_model.h +597 -0
- package/ui/refresh_perf.h +235 -0
- package/ui/refresh_trace.h +68 -0
- package/ui/render.cpp +12097 -0
- package/ui/root_scroll_refresh.cpp +859 -0
- package/ui/root_scroll_refresh.h +30 -0
- package/ui/state_init.h +21 -0
- package/ui/style.cpp +14994 -0
- package/ui/style.h +727 -0
- package/ui/style_values.h +31 -0
- package/ui/text.cpp +2010 -0
- package/ui/text.h +15 -0
- package/ui/text_element.cpp +15 -0
- package/ui/tree_events.cpp +621 -0
- package/ui/tree_events.h +69 -0
- package/ui/tree_internal.h +191 -0
- package/ui/tree_nodes.cpp +628 -0
- package/ui/tree_render.cpp +3138 -0
- package/ui/tree_scroll_mirror.cpp +101 -0
- package/ui/tree_state.cpp +574 -0
- package/ui/tree_state.h +235 -0
- package/ui/tree_style.cpp +698 -0
- package/ui/ui.h +9 -0
- package/ui/view.cpp +2232 -0
- package/ui/view.h +14 -0
- package/ui/view_element.cpp +13 -0
- package/ui/viewport_region.cpp +36 -0
- package/ui/viewport_region.h +12 -0
- package/ui/virtual_keyboard.cpp +908 -0
- package/ui/virtual_keyboard.h +59 -0
- package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
- package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
- package/vendor/stb/stb_image.h +7988 -0
- package/vendor/stb/stb_truetype.h +5079 -0
package/ui/tree_state.h
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "canvas_store.h"
|
|
5
|
+
#include "css_atom.h"
|
|
6
|
+
#include "node_model.h"
|
|
7
|
+
#include "style.h"
|
|
8
|
+
#include "tree_events.h"
|
|
9
|
+
|
|
10
|
+
#include <cstddef>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
namespace gea::embedded::ui {
|
|
16
|
+
|
|
17
|
+
struct NodeClassList {
|
|
18
|
+
static constexpr std::uint8_t kInlineTokenCount = 4;
|
|
19
|
+
static constexpr std::uint16_t kNoOverflow = 0xFFFFu;
|
|
20
|
+
|
|
21
|
+
CssAtomId inlineTokens[kInlineTokenCount]{};
|
|
22
|
+
std::uint16_t overflowHandle = kNoOverflow;
|
|
23
|
+
std::uint8_t count = 0;
|
|
24
|
+
|
|
25
|
+
NodeClassList() = default;
|
|
26
|
+
NodeClassList(const NodeClassList &other);
|
|
27
|
+
NodeClassList &operator=(const NodeClassList &other);
|
|
28
|
+
NodeClassList(NodeClassList &&other) noexcept;
|
|
29
|
+
NodeClassList &operator=(NodeClassList &&other) noexcept;
|
|
30
|
+
~NodeClassList();
|
|
31
|
+
|
|
32
|
+
void clear();
|
|
33
|
+
bool set(const char *className);
|
|
34
|
+
bool set(const std::string &className);
|
|
35
|
+
bool add(const std::string &token);
|
|
36
|
+
bool remove(const std::string &token);
|
|
37
|
+
bool toggle(const std::string &token);
|
|
38
|
+
bool toggle(const std::string &token, bool force);
|
|
39
|
+
bool contains(const std::string &token) const;
|
|
40
|
+
bool containsAtom(CssAtomId token) const;
|
|
41
|
+
std::size_t size() const { return count; }
|
|
42
|
+
CssAtomId at(std::size_t index) const;
|
|
43
|
+
std::string value() const;
|
|
44
|
+
bool empty() const { return count == 0; }
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
struct NodeStyleOverride {
|
|
48
|
+
Property property;
|
|
49
|
+
int value;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
struct NodeStyleOverrideStore {
|
|
53
|
+
static constexpr std::uint8_t kInlineCount = 4;
|
|
54
|
+
NodeStyleOverride inlineValues[kInlineCount]{};
|
|
55
|
+
NodeStyleOverride *spillValues = nullptr;
|
|
56
|
+
std::size_t spillCount = 0;
|
|
57
|
+
std::size_t spillCapacity = 0;
|
|
58
|
+
std::uint8_t inlineCount = 0;
|
|
59
|
+
bool spilled = false;
|
|
60
|
+
|
|
61
|
+
NodeStyleOverrideStore() = default;
|
|
62
|
+
NodeStyleOverrideStore(const NodeStyleOverrideStore &other);
|
|
63
|
+
NodeStyleOverrideStore &operator=(const NodeStyleOverrideStore &other);
|
|
64
|
+
NodeStyleOverrideStore(NodeStyleOverrideStore &&other) noexcept;
|
|
65
|
+
NodeStyleOverrideStore &operator=(NodeStyleOverrideStore &&other) noexcept;
|
|
66
|
+
~NodeStyleOverrideStore();
|
|
67
|
+
|
|
68
|
+
void clear();
|
|
69
|
+
void set(Property property, int value);
|
|
70
|
+
bool remove(Property property);
|
|
71
|
+
std::size_t size() const { return spilled ? spillCount : inlineCount; }
|
|
72
|
+
bool empty() const { return size() == 0; }
|
|
73
|
+
const NodeStyleOverride &at(std::size_t index) const;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
struct NodeCustomProperty {
|
|
77
|
+
CssAtomId nameId = kInvalidCssAtom;
|
|
78
|
+
std::string value;
|
|
79
|
+
CssAtomId valueAtom = kInvalidCssAtom;
|
|
80
|
+
std::int32_t colorStyle = 0;
|
|
81
|
+
std::int32_t colorNative = 0;
|
|
82
|
+
float lengthValue = 0.0f;
|
|
83
|
+
std::uint8_t colorAlpha = 255;
|
|
84
|
+
std::uint8_t lengthUnit = 0;
|
|
85
|
+
std::uint8_t flags = 0;
|
|
86
|
+
|
|
87
|
+
bool hasColor() const { return (flags & 1u) != 0; }
|
|
88
|
+
bool hasLength() const { return (flags & 2u) != 0; }
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
struct NodeCustomPropertyStore {
|
|
92
|
+
std::vector<NodeCustomProperty> values;
|
|
93
|
+
|
|
94
|
+
void clear();
|
|
95
|
+
void set(const std::string &name, const std::string &value);
|
|
96
|
+
void set(CssAtomId nameId, const std::string &value);
|
|
97
|
+
void setColor(CssAtomId nameId,
|
|
98
|
+
const std::string &value,
|
|
99
|
+
std::int32_t styleColor,
|
|
100
|
+
std::int32_t nativeColor,
|
|
101
|
+
std::uint8_t alpha);
|
|
102
|
+
void setLength(CssAtomId nameId,
|
|
103
|
+
const std::string &value,
|
|
104
|
+
float lengthValue,
|
|
105
|
+
std::uint8_t lengthUnit);
|
|
106
|
+
const std::string *get(const std::string &name) const;
|
|
107
|
+
const std::string *get(CssAtomId nameId) const;
|
|
108
|
+
const NodeCustomProperty *getEntry(CssAtomId nameId) const;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Generic windowing state for a <virtual-list>. The element renders a small
|
|
112
|
+
// pool of real child "slot" nodes (the row template, supplied by the app) and
|
|
113
|
+
// scrolls over a virtual content height of itemCount * rowHeight. It carries no
|
|
114
|
+
// app-specific row content: labels, fonts, colours and layout all come from the
|
|
115
|
+
// child slots' own CSS, exactly like any other node.
|
|
116
|
+
struct VirtualListNodeState {
|
|
117
|
+
int32_t itemCount = 0; // total virtual item count (item-count attribute)
|
|
118
|
+
int32_t rowHeight = 0; // derived from the first slot child's CSS layout height
|
|
119
|
+
int32_t scrollTop = 0; // kept in sync with layout.scroll_y
|
|
120
|
+
int32_t previousScrollTop = 0;
|
|
121
|
+
bool framebufferSynced = true;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Blink-style "rare data" block: the cold/optional per-node state that the vast
|
|
125
|
+
// majority of nodes never have — event listeners, attributes, CSS custom
|
|
126
|
+
// properties, and virtual-list windowing state. Stored in a shared pool and
|
|
127
|
+
// referenced by a single int16 handle on the node (Node::rare_data) instead of
|
|
128
|
+
// inlining a fixed slot on every node, so a plain styled node allocates nothing.
|
|
129
|
+
struct NodeRareData {
|
|
130
|
+
NodeAttributeStore attributes;
|
|
131
|
+
NodeEventListeners listeners;
|
|
132
|
+
NodeCustomPropertyStore customProperties;
|
|
133
|
+
NodeStyleOverrideStore defaultStyles;
|
|
134
|
+
NodeStyleOverrideStore inlineStyles;
|
|
135
|
+
VirtualListNodeState virtualList;
|
|
136
|
+
|
|
137
|
+
void clear()
|
|
138
|
+
{
|
|
139
|
+
attributes.clear();
|
|
140
|
+
listeners.clear();
|
|
141
|
+
customProperties.clear();
|
|
142
|
+
defaultStyles.clear();
|
|
143
|
+
inlineStyles.clear();
|
|
144
|
+
virtualList = VirtualListNodeState{};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
struct TreeState {
|
|
149
|
+
Node nodes[kMaxNodes];
|
|
150
|
+
// Attributes and event listeners are no longer dense per-node arrays — they
|
|
151
|
+
// live in the shared NodeRareData pool, referenced by Node::rare_data. The
|
|
152
|
+
// vast majority of nodes have neither (a class-only node allocates nothing),
|
|
153
|
+
// so this reclaims the ~387 KB attribute + ~96 KB listener tables that were
|
|
154
|
+
// inlined-but-empty on every node.
|
|
155
|
+
NodeClassList classLists[kMaxNodes];
|
|
156
|
+
// defaultStyles + inlineStyles now live in the NodeRareData pool too.
|
|
157
|
+
CanvasStore canvases;
|
|
158
|
+
// customProperties + virtualList now live in the shared NodeRareData pool
|
|
159
|
+
// (Node::rare_data) — most nodes have neither.
|
|
160
|
+
uint8_t nodeActive[kMaxNodes]{};
|
|
161
|
+
int nodeCount = 0;
|
|
162
|
+
int mountedRoot = -1;
|
|
163
|
+
int mountedWidth = 0;
|
|
164
|
+
int mountedHeight = 0;
|
|
165
|
+
int lastFrameMs = 0;
|
|
166
|
+
// Monotonic counter bumped on every mount()/refresh() — i.e. whenever the
|
|
167
|
+
// reactive tree is (re)built. Lets native renderers (macOS) skip an entire
|
|
168
|
+
// re-sync when the tree hasn't changed since the last frame, instead of
|
|
169
|
+
// diffing the whole view tree at 60Hz while idle.
|
|
170
|
+
uint64_t refreshSerial = 0;
|
|
171
|
+
uint64_t scrollDirtyNodes[kScrollDirtyWordCount]{};
|
|
172
|
+
bool scrollDirtyAny = false;
|
|
173
|
+
int pendingScrollIntoViewNode = -1;
|
|
174
|
+
bool inputTickRequired = false;
|
|
175
|
+
bool displayListDirty = true;
|
|
176
|
+
// When a rebuild is pending (displayListDirty), this says whether it may have
|
|
177
|
+
// changed draw order / which commands exist (node add/remove/reorder, z-index,
|
|
178
|
+
// display toggle, pixel-spilling filters). If false, the rebuild is
|
|
179
|
+
// appearance-only on existing nodes (e.g. a partial-opacity fade or an
|
|
180
|
+
// absolute-leaf resize) — no draw-order change — so refresh can replay just the
|
|
181
|
+
// dirty-node regions instead of repainting the whole viewport. Set true by
|
|
182
|
+
// markDisplayListDirty(); left untouched by markDisplayListContentDirty().
|
|
183
|
+
bool displayListRebuildStructural = true;
|
|
184
|
+
int styleInvalidationSuppressionDepth = 0;
|
|
185
|
+
uint8_t nodeCommandDirty[kMaxNodes]{};
|
|
186
|
+
uint8_t nodeCommandDirtyBoundsValid[kMaxNodes]{};
|
|
187
|
+
uint8_t nodeCommandDirtyCanOverpaint[kMaxNodes]{};
|
|
188
|
+
// Static-backdrop dynamic-leaf set: frames remaining in which this node counts
|
|
189
|
+
// as "recently changed" (a ticking text badge, a counter). While > 0 the node
|
|
190
|
+
// is EXCLUDED from the backdrop bake, its commands stay recorded, settle
|
|
191
|
+
// tolerates its dirtiness, and content changes on it skip the backdrop
|
|
192
|
+
// invalidation — so a periodic HUD update no longer drops the whole cache.
|
|
193
|
+
// Set saturating by Tree::setText on a real change; decremented once per
|
|
194
|
+
// refresh by LayoutSnapshot::capture; expiry forces one backdrop invalidation
|
|
195
|
+
// so the node folds back into the next bake consistently.
|
|
196
|
+
uint8_t nodeBackdropCooldown[kMaxNodes]{};
|
|
197
|
+
// Whether the last backdrop bake painted this node into the cache. Drives the
|
|
198
|
+
// setText invalidation decision: changing a node whose pixels are NOT in the
|
|
199
|
+
// cache never needs to drop the cache.
|
|
200
|
+
uint8_t nodeInBackdrop[kMaxNodes]{};
|
|
201
|
+
int16_t nodeCommandDirtyX0[kMaxNodes]{};
|
|
202
|
+
int16_t nodeCommandDirtyY0[kMaxNodes]{};
|
|
203
|
+
int16_t nodeCommandDirtyX1[kMaxNodes]{};
|
|
204
|
+
int16_t nodeCommandDirtyY1[kMaxNodes]{};
|
|
205
|
+
|
|
206
|
+
// Gate for the keyframe-3D transform record path. `transformPresent` is true
|
|
207
|
+
// iff some node carries a non-identity transform/perspective this frame or
|
|
208
|
+
// last frame; it is recomputed once per refresh (keyed on refreshSerial) by
|
|
209
|
+
// ViewGeometry::anyTransformPresent(). When false, the per-node ancestor-chain
|
|
210
|
+
// transform walks short-circuit to O(1) — non-3D trees (the common case) pay
|
|
211
|
+
// nothing for the 3D machinery. Defaults coax a recompute before first use.
|
|
212
|
+
uint64_t transformScanSerial = ~0ull;
|
|
213
|
+
bool transformPresent = true;
|
|
214
|
+
// Durable validity for a cached `transformPresent == false`. refreshSerial bumps
|
|
215
|
+
// several times mid-refresh, so the serial-keyed cache above re-scans on each bump.
|
|
216
|
+
// But a transform-free tree CANNOT gain a transform without a setStyle(transform),
|
|
217
|
+
// and both such sites clear this flag — so once we scan and find no transforms, the
|
|
218
|
+
// `false` holds across the bumps with no re-scan. This is what lets mode()/dirty/snap
|
|
219
|
+
// short-circuit the per-node transform reads without paying a scan-per-phase (the
|
|
220
|
+
// old mode-gate regression was that re-scan, not the gate itself). A cached `true`
|
|
221
|
+
// is NOT held here — it still re-scans per refreshSerial so a removal is seen.
|
|
222
|
+
bool transformScanValid = false;
|
|
223
|
+
|
|
224
|
+
// Focus + caret state for `<input>` elements. -1 means no input is
|
|
225
|
+
// focused. caretLastFlipMs/caretVisible drive the blink animation —
|
|
226
|
+
// consulted by InputRenderer::record on the pixel target. The macOS
|
|
227
|
+
// renderer ignores these (NSResponder owns its own caret).
|
|
228
|
+
int activeInputId = -1;
|
|
229
|
+
int caretLastFlipMs = 0;
|
|
230
|
+
bool caretVisible = true;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
TreeState &treeState();
|
|
234
|
+
|
|
235
|
+
} // namespace gea::embedded::ui
|