@geastack/engine 0.1.6 → 0.1.8

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/ui/tree_state.h CHANGED
@@ -7,8 +7,10 @@
7
7
  #include "style.h"
8
8
  #include "tree_events.h"
9
9
 
10
+ #include <array>
10
11
  #include <cstddef>
11
12
  #include <cstdint>
13
+ #include <cstdlib>
12
14
  #include <string>
13
15
  #include <memory>
14
16
  #include <vector>
@@ -16,11 +18,15 @@
16
18
  namespace gea::embedded::ui {
17
19
 
18
20
  struct NodeClassList {
19
- static constexpr std::uint8_t kInlineTokenCount = 4;
21
+ static constexpr std::uint8_t kInlineTokenCount = GEA_UI_CLASS_INLINE_TOKENS;
20
22
  static constexpr std::uint16_t kNoOverflow = 0xFFFFu;
21
23
 
22
24
  CssAtomId inlineTokens[kInlineTokenCount]{};
25
+ #if GEA_UI_CLASS_OVERFLOW
23
26
  std::uint16_t overflowHandle = kNoOverflow;
27
+ #else
28
+ static constexpr std::uint16_t overflowHandle = kNoOverflow;
29
+ #endif
24
30
  std::uint8_t count = 0;
25
31
 
26
32
  NodeClassList() = default;
@@ -51,13 +57,8 @@ struct NodeStyleOverride {
51
57
  };
52
58
 
53
59
  struct NodeStyleOverrideStore {
54
- static constexpr std::uint8_t kInlineCount = 4;
55
- NodeStyleOverride inlineValues[kInlineCount]{};
56
- NodeStyleOverride *spillValues = nullptr;
57
- std::size_t spillCount = 0;
58
- std::size_t spillCapacity = 0;
59
- std::uint8_t inlineCount = 0;
60
- bool spilled = false;
60
+ struct Block;
61
+ Block *block = nullptr;
61
62
 
62
63
  NodeStyleOverrideStore() = default;
63
64
  NodeStyleOverrideStore(const NodeStyleOverrideStore &other);
@@ -68,10 +69,23 @@ struct NodeStyleOverrideStore {
68
69
 
69
70
  void clear();
70
71
  void set(Property property, int value);
72
+ void setCssPixels(Property property, float value);
73
+ bool getCssPixels(Property property, float &value) const;
71
74
  bool remove(Property property);
72
- std::size_t size() const { return spilled ? spillCount : inlineCount; }
75
+ std::size_t size() const;
73
76
  bool empty() const { return size() == 0; }
74
77
  const NodeStyleOverride &at(std::size_t index) const;
78
+ StorageUsage storageUsage() const;
79
+ };
80
+
81
+ // This empty owner is selected only by a complete source/native reachability
82
+ // proof. A violated mutation contract fails loudly instead of dropping styles.
83
+ struct EmptyNodeStyleOverrideStore {
84
+ void clear() {}
85
+ void set(Property, int) { std::abort(); }
86
+ std::size_t size() const { return 0; }
87
+ const NodeStyleOverride &at(std::size_t) const { std::abort(); }
88
+ StorageUsage storageUsage() const { return {}; }
75
89
  };
76
90
 
77
91
  // CSS ::first-line painting is uncommon and line fragments are useful only
@@ -105,22 +119,42 @@ struct InlineStaticPosition {
105
119
 
106
120
  struct NodeCustomProperty {
107
121
  CssAtomId nameId = kInvalidCssAtom;
108
- std::string value;
109
122
  CssAtomId valueAtom = kInvalidCssAtom;
110
- std::int32_t colorStyle = 0;
111
- std::int32_t colorNative = 0;
123
+ // Most values already live in the atom table: alias its stable immutable
124
+ // string without a control block. A full atom table uses owned storage.
125
+ std::shared_ptr<const std::string> value{std::shared_ptr<const std::string>{}, &cssAtomString(kInvalidCssAtom)};
126
+ // Both caches hold packed target colors: RGB565/gray fit 16 bits;
127
+ // full-color targets retain all 32 bits and their signed carrier.
128
+ using ColorValue = std::conditional_t<GEA_PIXEL_FORMAT_IS_8888, std::int32_t, std::uint16_t>;
129
+ ColorValue colorStyle = 0;
130
+ ColorValue colorNative = 0;
131
+ #if GEA_CSS_CUSTOM_PROPERTY_LENGTHS
112
132
  float lengthValue = 0.0f;
133
+ #else
134
+ static constexpr float lengthValue = 0.0f;
135
+ #endif
113
136
  std::uint8_t colorAlpha = 255;
137
+ #if GEA_CSS_CUSTOM_PROPERTY_LENGTHS
114
138
  std::uint8_t lengthUnit = 0;
139
+ #else
140
+ static constexpr std::uint8_t lengthUnit = 0;
141
+ #endif
115
142
  std::uint8_t flags = 0;
116
143
 
117
144
  bool hasColor() const { return (flags & 1u) != 0; }
118
- bool hasLength() const { return (flags & 2u) != 0; }
145
+ bool hasLength() const { return GEA_CSS_CUSTOM_PROPERTY_LENGTHS && (flags & 2u) != 0; }
119
146
  };
120
147
 
121
148
  struct NodeCustomPropertyStore {
122
- std::vector<NodeCustomProperty> values;
149
+ #if GEA_CSS_CUSTOM_PROPERTIES
150
+ using Values = std::vector<NodeCustomProperty>;
151
+ Values values;
152
+ #else
153
+ using Values = std::array<NodeCustomProperty, 0>;
154
+ inline static constexpr Values values{};
155
+ #endif
123
156
 
157
+ #if GEA_CSS_CUSTOM_PROPERTIES
124
158
  void clear();
125
159
  void set(const std::string &name, const std::string &value);
126
160
  void set(CssAtomId nameId, const std::string &value);
@@ -136,6 +170,16 @@ struct NodeCustomPropertyStore {
136
170
  const std::string *get(const std::string &name) const;
137
171
  const std::string *get(CssAtomId nameId) const;
138
172
  const NodeCustomProperty *getEntry(CssAtomId nameId) const;
173
+ #else
174
+ void clear() {}
175
+ void set(const std::string &, const std::string &) {}
176
+ void set(CssAtomId, const std::string &) {}
177
+ void setColor(CssAtomId, const std::string &, std::int32_t, std::int32_t, std::uint8_t) {}
178
+ void setLength(CssAtomId, const std::string &, float, std::uint8_t) {}
179
+ const std::string *get(const std::string &) const { return nullptr; }
180
+ const std::string *get(CssAtomId) const { return nullptr; }
181
+ const NodeCustomProperty *getEntry(CssAtomId) const { return nullptr; }
182
+ #endif
139
183
  };
140
184
 
141
185
  // Generic windowing state for a <virtual-list>. The element renders a small
@@ -162,20 +206,42 @@ struct GridTrackLayout {
162
206
  };
163
207
 
164
208
  struct NodeRareData {
165
- NodeAttributeStore attributes;
166
- NodeEventListeners listeners;
167
- NodeCustomPropertyStore customProperties;
209
+ // Reuse the listener record's tail padding for inline-position metadata.
210
+ // Both members remain ordinary embedded fields with fixed-offset access.
211
+ [[no_unique_address]] NodeEventListeners listeners;
212
+ InlineStaticPosition inlineStaticPosition;
213
+ [[no_unique_address]] NodeAttributeStore attributes;
214
+ [[no_unique_address]] NodeCustomPropertyStore customProperties;
168
215
  // Authored inline values survive rebuilding the computed custom-property map.
169
- NodeCustomPropertyStore inlineCustomProperties;
216
+ [[no_unique_address]] NodeCustomPropertyStore inlineCustomProperties;
217
+ #if GEA_UI_DEFAULT_STYLES
170
218
  NodeStyleOverrideStore defaultStyles;
219
+ #else
220
+ [[no_unique_address]] EmptyNodeStyleOverrideStore defaultStyles;
221
+ #endif
171
222
  NodeStyleOverrideStore inlineStyles;
223
+ #if GEA_CSS_GRID
172
224
  CssAtomId inlineGridTemplates[2] = {kInvalidCssAtom, kInvalidCssAtom};
173
225
  uint8_t inlineGridShorthandMask = 0;
174
226
  std::unique_ptr<GridTrackLayout> gridLayout;
175
- VirtualListNodeState virtualList;
227
+ #endif
228
+ #if GEA_CSS_SCROLLING
229
+ std::unique_ptr<VirtualListNodeState> virtualList;
230
+ VirtualListNodeState &ensureVirtualList()
231
+ {
232
+ if (!virtualList) virtualList = std::make_unique<VirtualListNodeState>();
233
+ return *virtualList;
234
+ }
235
+ #else
236
+ static constexpr const VirtualListNodeState *virtualList = nullptr;
237
+ #endif
238
+ #if GEA_CSS_FIRST_LINE
176
239
  FirstLineBackground firstLineBackground;
177
240
  FirstLineFragment firstLineFragment;
178
- InlineStaticPosition inlineStaticPosition;
241
+ #else
242
+ inline static constexpr FirstLineBackground firstLineBackground{};
243
+ inline static constexpr FirstLineFragment firstLineFragment{};
244
+ #endif
179
245
 
180
246
  void clear()
181
247
  {
@@ -185,16 +251,29 @@ struct NodeRareData {
185
251
  inlineCustomProperties.clear();
186
252
  defaultStyles.clear();
187
253
  inlineStyles.clear();
254
+ #if GEA_CSS_GRID
188
255
  inlineGridTemplates[0] = inlineGridTemplates[1] = kInvalidCssAtom;
189
256
  inlineGridShorthandMask = 0;
190
257
  gridLayout.reset();
191
- virtualList = VirtualListNodeState{};
258
+ #endif
259
+ #if GEA_CSS_SCROLLING
260
+ virtualList.reset();
261
+ #endif
262
+ #if GEA_CSS_FIRST_LINE
192
263
  firstLineBackground = FirstLineBackground{};
193
264
  firstLineFragment = FirstLineFragment{};
265
+ #endif
194
266
  inlineStaticPosition = InlineStaticPosition{};
195
267
  }
196
268
  };
197
269
 
270
+ struct NodeAuxiliaryStorageUsage {
271
+ StorageUsage tree, text, rare, overrides, dependencies;
272
+ };
273
+ StorageUsage treeStorageUsage();
274
+ StorageUsage styleDependencyStorageUsage();
275
+ NodeAuxiliaryStorageUsage nodeAuxiliaryStorageUsage();
276
+
198
277
  struct TreeState {
199
278
  Node nodes[kMaxNodes];
200
279
  // Attributes and event listeners are no longer dense per-node arrays — they
@@ -221,9 +300,14 @@ struct TreeState {
221
300
  // re-sync when the tree hasn't changed since the last frame, instead of
222
301
  // diffing the whole view tree at 60Hz while idle.
223
302
  uint64_t refreshSerial = 0;
303
+ #if GEA_CSS_SCROLLING
224
304
  uint64_t scrollDirtyNodes[kScrollDirtyWordCount]{};
225
305
  bool scrollDirtyAny = false;
226
306
  int pendingScrollIntoViewNode = -1;
307
+ #else
308
+ static constexpr bool scrollDirtyAny = false;
309
+ static constexpr int pendingScrollIntoViewNode = -1;
310
+ #endif
227
311
  bool inputTickRequired = false;
228
312
  bool displayListDirty = true;
229
313
  // When a rebuild is pending (displayListDirty), this says whether it may have
@@ -262,6 +346,7 @@ struct TreeState {
262
346
  // ViewGeometry::anyTransformPresent(). When false, the per-node ancestor-chain
263
347
  // transform walks short-circuit to O(1) — non-3D trees (the common case) pay
264
348
  // nothing for the 3D machinery. Defaults coax a recompute before first use.
349
+ #if GEA_CSS_TRANSFORMS
265
350
  uint64_t transformScanSerial = ~0ull;
266
351
  bool transformPresent = true;
267
352
  // Durable validity for a cached `transformPresent == false`. refreshSerial bumps
@@ -273,15 +358,26 @@ struct TreeState {
273
358
  // old mode-gate regression was that re-scan, not the gate itself). A cached `true`
274
359
  // is NOT held here — it still re-scans per refreshSerial so a removal is seen.
275
360
  bool transformScanValid = false;
361
+ #else
362
+ static constexpr uint64_t transformScanSerial = ~0ull;
363
+ static constexpr bool transformPresent = false;
364
+ static constexpr bool transformScanValid = true;
365
+ #endif
276
366
 
277
367
  // Focus + caret state for `<input>` elements. -1 means no input is
278
368
  // focused. caretLastFlipMs/caretVisible drive the blink animation —
279
369
  // consulted by InputRenderer::record on the pixel target. The macOS
280
370
  // renderer ignores these (NSResponder owns its own caret).
371
+ #if GEA_UI_INPUT_NODES
281
372
  int activeInputId = -1;
282
- int hoveredNodeId = -1;
283
373
  int caretLastFlipMs = 0;
284
374
  bool caretVisible = true;
375
+ #else
376
+ static constexpr int activeInputId = -1;
377
+ static constexpr int caretLastFlipMs = 0;
378
+ static constexpr bool caretVisible = false;
379
+ #endif
380
+ int hoveredNodeId = -1;
285
381
  };
286
382
 
287
383
  TreeState &treeState();