@geastack/engine 0.1.5 → 0.1.7

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.
Files changed (45) hide show
  1. package/README.md +70 -0
  2. package/canvas.cpp +86 -30
  3. package/css/animation.h +64 -0
  4. package/css/declarative.h +6 -0
  5. package/css/engine.h +25 -1
  6. package/image_store.cpp +136 -33
  7. package/package.json +2 -2
  8. package/ui/CSS_FEATURES.md +261 -0
  9. package/ui/absolute_leaf_refresh.cpp +42 -39
  10. package/ui/core.cpp +32 -1
  11. package/ui/css_atom.cpp +6 -0
  12. package/ui/css_atom.h +2 -0
  13. package/ui/css_features.h +282 -0
  14. package/ui/display_invalidation.cpp +29 -0
  15. package/ui/flex_balance.h +73 -0
  16. package/ui/image_node.cpp +33 -28
  17. package/ui/input.cpp +88 -38
  18. package/ui/input_render.cpp +17 -13
  19. package/ui/internal.h +51 -5
  20. package/ui/layout.cpp +2601 -441
  21. package/ui/layout_snapshot.cpp +49 -6
  22. package/ui/node_features.h +18 -0
  23. package/ui/node_lifecycle.cpp +204 -71
  24. package/ui/node_lifecycle.h +1 -0
  25. package/ui/node_model.h +930 -70
  26. package/ui/node_text.h +82 -0
  27. package/ui/render.cpp +793 -352
  28. package/ui/renderer_features.h +19 -0
  29. package/ui/root_scroll_refresh.cpp +46 -24
  30. package/ui/style.cpp +4155 -1073
  31. package/ui/style.h +143 -6
  32. package/ui/style_values.h +16 -0
  33. package/ui/text.cpp +401 -106
  34. package/ui/tree_events.cpp +138 -95
  35. package/ui/tree_events.h +28 -19
  36. package/ui/tree_inspection.h +15 -0
  37. package/ui/tree_internal.h +19 -0
  38. package/ui/tree_nodes.cpp +38 -4
  39. package/ui/tree_render.cpp +119 -40
  40. package/ui/tree_scroll_mirror.cpp +26 -0
  41. package/ui/tree_state.cpp +261 -114
  42. package/ui/tree_state.h +121 -16
  43. package/ui/tree_style.cpp +609 -82
  44. package/ui/view.cpp +720 -299
  45. package/ui/virtual_keyboard.cpp +10 -3
package/ui/node_model.h CHANGED
@@ -2,11 +2,17 @@
2
2
  #pragma once
3
3
 
4
4
  #include "pixel.h"
5
+ #include "css_features.h"
6
+ #include "renderer_features.h"
7
+ #include "node_text.h"
8
+ #include "node_features.h"
5
9
 
10
+ #include <algorithm>
6
11
  #include <cstdint>
7
12
  #include <cstddef>
8
13
  #include <deque>
9
14
  #include <string>
15
+ #include <type_traits>
10
16
 
11
17
  namespace gea::embedded::ui {
12
18
 
@@ -28,6 +34,18 @@ using style_color_t = gea::framework::graphics::pixel::native_t;
28
34
  #endif
29
35
  inline constexpr int kMaxNodes = GEA_EMBEDDED_MAX_NODES;
30
36
  inline constexpr int kUnset = -32768;
37
+ // Internal value carrier for CSS z-index:auto; numeric stack levels stay int16.
38
+ inline constexpr int kZIndexAuto = INT32_MIN;
39
+ // Dimension expression slots use nonnegative values for pooled expressions,
40
+ // -1 for no expression, and these tags for intrinsic sizing keywords.
41
+ inline constexpr int kSizeMinContent = -2;
42
+ inline constexpr int kSizeMaxContent = -3;
43
+ inline constexpr int kSizeFitContent = -4;
44
+
45
+ inline bool isIntrinsicSizeExpression(int value)
46
+ {
47
+ return value >= kSizeFitContent && value <= kSizeMinContent;
48
+ }
31
49
  inline constexpr int kScrollDirtyWordCount = (kMaxNodes + 63) / 64;
32
50
  inline constexpr int kMaxGridTracks = 8;
33
51
  // Layout-time track capacity: IMPLICIT rows (an auto-flowing grid of N
@@ -37,6 +55,7 @@ inline constexpr int kMaxGridTracks = 8;
37
55
  // Template-declared tracks stay capped at kMaxGridTracks; rows beyond the
38
56
  // template are implicit (auto-sized), so only the layout locals grow.
39
57
  inline constexpr int kMaxGridLayoutTracks = 96;
58
+ inline constexpr int kGridLineSpan = 65536;
40
59
 
41
60
  #ifndef GEA_EMBEDDED_RARE_STYLE_SRAM_POOL_ENTRIES
42
61
  #define GEA_EMBEDDED_RARE_STYLE_SRAM_POOL_ENTRIES 0
@@ -54,8 +73,47 @@ inline constexpr int8_t kDisplayBlock = 0;
54
73
  inline constexpr int8_t kDisplayNone = 1;
55
74
  inline constexpr int8_t kDisplayGrid = 2;
56
75
  inline constexpr int8_t kDisplayFlex = 3;
76
+ inline constexpr int kPositionFixed = 3;
77
+ inline bool isOutOfFlowPosition(int position) { return position == 1 || position == kPositionFixed; }
78
+ // Existing alignment values occupy the low nibble. Overflow-position is
79
+ // independent of the alignment keyword and fits in the existing int8 fields.
80
+ inline constexpr int kAlignSafe = 16;
81
+ inline constexpr int kAlignUnsafe = 32;
82
+ inline constexpr int kAlignStart = 7;
83
+ inline constexpr int kAlignEnd = 8;
84
+ inline constexpr int kAlignLastBaseline = 9;
85
+ inline constexpr int kAlignSelfStart = 10;
86
+ inline constexpr int kAlignSelfEnd = 11;
87
+ inline constexpr int kAlignLeft = 12;
88
+ inline constexpr int kAlignRight = 13;
89
+ inline constexpr int kAlignSpaceEvenly = 14;
90
+ inline bool isDistributedAlignment(int alignment)
91
+ {
92
+ const int keyword = alignment & 15;
93
+ return keyword == 3 || keyword == 4 || keyword == kAlignSpaceEvenly;
94
+ }
95
+ inline int distributedAlignmentOffset(int alignment, int free, int index, int count)
96
+ {
97
+ // Cumulative division keeps rounding error from accumulating across gaps.
98
+ // Distributed alignment falls back to safe start/center on overflow.
99
+ if (free <= 0 || count <= 0) return 0;
100
+ switch (alignment & 15) {
101
+ case 3: return count > 1 ? free * index / (count - 1) : 0;
102
+ case 4: return free * (2 * index + 1) / (2 * count);
103
+ case kAlignSpaceEvenly: return free * (index + 1) / (count + 1);
104
+ default: return 0;
105
+ }
106
+ }
107
+ inline int usedAlignment(int alignment, int freeSpace, bool reversed = false)
108
+ {
109
+ if (alignment < 0) return alignment;
110
+ const int keyword = (alignment & kAlignSafe) && freeSpace < 0 ? kAlignStart : alignment & 15;
111
+ if (keyword == kAlignStart) return reversed ? 2 : 6;
112
+ if (keyword == kAlignEnd) return reversed ? 6 : 2;
113
+ return keyword;
114
+ }
57
115
 
58
- enum class NodeType : int8_t {
116
+ enum class NodeType : uint8_t {
59
117
  View = 0,
60
118
  Text = 1,
61
119
  Image = 2,
@@ -80,7 +138,72 @@ inline bool isNativeButtonNodeType(NodeType type)
80
138
  // or embedded inline in ComputedStyle when GEA_EMBEDDED_RARE_STYLE_INLINE is set (defined
81
139
  // BEFORE ComputedStyle so it can be a by-value member).
82
140
  struct RareStyle {
141
+ // Logical edges: block-start/end, inline-start/end.
142
+ #if GEA_CSS_MARGIN_TRIM
143
+ uint8_t margin_trim = 0;
144
+ #else
145
+ static constexpr uint8_t margin_trim = 0;
146
+ #endif
147
+ // IEEE float bits travel through the existing integer style-value transport.
148
+ // Negative ratios mean `auto <ratio>` (prefer a replaced element's natural ratio).
149
+ #if GEA_CSS_ASPECT_RATIO
150
+ int32_t aspect_ratio = 0;
151
+ #else
152
+ static constexpr int32_t aspect_ratio = 0;
153
+ #endif
154
+ #if GEA_CSS_FLEX_LINE_COUNT
155
+ int32_t flex_line_count = 1;
156
+ #else
157
+ static constexpr int32_t flex_line_count = 1;
158
+ #endif
159
+ #if GEA_CSS_FLEX_BASIS_EXPRESSIONS
160
+ int32_t flex_basis_expression = -1;
161
+ #else
162
+ static constexpr int32_t flex_basis_expression = -1;
163
+ #endif
164
+ #if GEA_CSS_LINE_HEIGHT_EXPRESSIONS
165
+ int32_t line_height_expression = -1;
166
+ #else
167
+ static constexpr int32_t line_height_expression = -1;
168
+ #endif
169
+ // Individual grid item alignment; auto defers to the parent's justify-items.
170
+ #if GEA_CSS_JUSTIFY_SELF
171
+ int8_t justify_self = -1;
172
+ #else
173
+ static constexpr int8_t justify_self = -1;
174
+ #endif
175
+ // Computed contain flags: size, inline-size, layout, style, paint.
176
+ // Currently consumed by document background propagation.
177
+ #if GEA_CSS_CONTAINMENT
178
+ uint8_t containment = 0;
179
+ #else
180
+ static constexpr uint8_t containment = 0;
181
+ #endif
182
+ #if GEA_CSS_BACKGROUND_LAYERS
183
+ uint16_t bg_clip = 0; // Interned clip list; zero is border-box.
184
+ #else
185
+ static constexpr uint16_t bg_clip = 0; // Interned clip list; zero is border-box.
186
+ #endif
187
+ // row-start, column-start, row-end, column-end; zero is auto. Positive
188
+ // spans carry kGridLineSpan, while signed integers retain explicit lines.
189
+ #if GEA_CSS_GRID
190
+ int32_t grid_line[4] = {};
191
+ #else
192
+ static constexpr int32_t grid_line[4] = {};
193
+ #endif
194
+ // Deferred box edges; absent expressions do not allocate a rare-style record.
195
+ #if GEA_CSS_BOX_EXPRESSIONS
196
+ int32_t margin_expression[4] = {-1, -1, -1, -1};
197
+ #else
198
+ static constexpr int32_t margin_expression[4] = {-1, -1, -1, -1};
199
+ #endif
200
+ #if GEA_CSS_BOX_EXPRESSIONS
201
+ int32_t padding_expression[4] = {-1, -1, -1, -1};
202
+ #else
203
+ static constexpr int32_t padding_expression[4] = {-1, -1, -1, -1};
204
+ #endif
83
205
  // --- grid (display:grid track templates) ---
206
+ #if GEA_CSS_GRID
84
207
  int8_t grid_column_count = 0;
85
208
  int8_t grid_row_count = 0;
86
209
  int8_t grid_column_type[kMaxGridTracks] = {};
@@ -88,8 +211,31 @@ struct RareStyle {
88
211
  int16_t grid_column_value[kMaxGridTracks] = {};
89
212
  int16_t grid_row_value[kMaxGridTracks] = {};
90
213
 
214
+ #else
215
+ static constexpr int8_t grid_column_count = 0;
216
+ static constexpr int8_t grid_row_count = 0;
217
+ static constexpr int8_t grid_column_type[kMaxGridTracks] = {};
218
+ static constexpr int8_t grid_row_type[kMaxGridTracks] = {};
219
+ static constexpr int16_t grid_column_value[kMaxGridTracks] = {};
220
+ static constexpr int16_t grid_row_value[kMaxGridTracks] = {};
221
+
222
+ #endif
223
+
91
224
  // --- transform / perspective (defaults must match NodeLifecycle::init:
92
225
  // scale 1000 = 1.0x, origins 500 = 50% center; the rest 0) ---
226
+ // Authored identity effects still establish positioning containing blocks.
227
+ #if GEA_CSS_TRANSFORMS
228
+ uint8_t transform_present = 0;
229
+ uint8_t transform_preserve_3d = 0;
230
+ uint8_t rotate_present = 0;
231
+ int16_t rotate_angle = 0;
232
+ int32_t rotate_axis_x = 0, rotate_axis_y = 0, rotate_axis_z = 1000000;
233
+ int16_t scale_x = 1000, scale_y = 1000, scale_z = 1000;
234
+ uint8_t scale_present = 0;
235
+ uint8_t translate_present = 0;
236
+ uint8_t transform_translate_outer_axes = 0;
237
+ int16_t translate_x = 0, translate_y = 0, translate_z = 0;
238
+ int16_t translate_x_percent = 0, translate_y_percent = 0;
93
239
  int16_t transform_rotate = 0;
94
240
  int16_t transform_rotate_x = 0;
95
241
  int16_t transform_rotate_y = 0;
@@ -100,25 +246,104 @@ struct RareStyle {
100
246
  int16_t transform_translate_y_percent = 0;
101
247
  int16_t transform_scale_x = 1000;
102
248
  int16_t transform_scale_y = 1000;
249
+ int16_t transform_scale_z = 1000;
103
250
  int16_t transform_origin_x = 500;
104
251
  int16_t transform_origin_y = 500;
105
252
  int16_t perspective = 0;
106
253
  int16_t perspective_origin_x = 500;
107
254
  int16_t perspective_origin_y = 500;
108
255
 
256
+ #else
257
+ static constexpr uint8_t transform_present = 0;
258
+ static constexpr uint8_t transform_preserve_3d = 0;
259
+ static constexpr uint8_t rotate_present = 0;
260
+ static constexpr int16_t rotate_angle = 0;
261
+ static constexpr int32_t rotate_axis_x = 0, rotate_axis_y = 0, rotate_axis_z = 1000000;
262
+ static constexpr int16_t scale_x = 1000, scale_y = 1000, scale_z = 1000;
263
+ static constexpr uint8_t scale_present = 0;
264
+ static constexpr uint8_t translate_present = 0;
265
+ static constexpr uint8_t transform_translate_outer_axes = 0;
266
+ static constexpr int16_t translate_x = 0, translate_y = 0, translate_z = 0;
267
+ static constexpr int16_t translate_x_percent = 0, translate_y_percent = 0;
268
+ static constexpr int16_t transform_rotate = 0;
269
+ static constexpr int16_t transform_rotate_x = 0;
270
+ static constexpr int16_t transform_rotate_y = 0;
271
+ static constexpr int16_t transform_translate_x = 0;
272
+ static constexpr int16_t transform_translate_y = 0;
273
+ static constexpr int16_t transform_translate_z = 0;
274
+ static constexpr int16_t transform_translate_x_percent = 0;
275
+ static constexpr int16_t transform_translate_y_percent = 0;
276
+ static constexpr int16_t transform_scale_x = 1000;
277
+ static constexpr int16_t transform_scale_y = 1000;
278
+ static constexpr int16_t transform_scale_z = 1000;
279
+ static constexpr int16_t transform_origin_x = 500;
280
+ static constexpr int16_t transform_origin_y = 500;
281
+ static constexpr int16_t perspective = 0;
282
+ static constexpr int16_t perspective_origin_x = 500;
283
+ static constexpr int16_t perspective_origin_y = 500;
284
+ #endif
285
+ #if GEA_CSS_FILTERS
286
+ uint8_t filter_present = 0;
287
+ #else
288
+ static constexpr uint8_t filter_present = 0;
289
+ #endif
290
+
109
291
  // --- filter / box-shadow (all default 0 = no effect) ---
292
+ #if GEA_CSS_FILTERS
110
293
  int16_t filter_blur_radius = 0;
294
+ #else
295
+ static constexpr int16_t filter_blur_radius = 0;
296
+ #endif
297
+ #if GEA_CSS_BOX_SHADOW
111
298
  uint8_t box_shadow_inset = 0;
299
+ #else
300
+ static constexpr uint8_t box_shadow_inset = 0;
301
+ #endif
302
+ #if GEA_CSS_BOX_SHADOW
112
303
  int16_t box_shadow_offset_x = 0;
304
+ #else
305
+ static constexpr int16_t box_shadow_offset_x = 0;
306
+ #endif
307
+ #if GEA_CSS_BOX_SHADOW
113
308
  int16_t box_shadow_offset_y = 0;
309
+ #else
310
+ static constexpr int16_t box_shadow_offset_y = 0;
311
+ #endif
312
+ #if GEA_CSS_BOX_SHADOW
114
313
  int16_t box_shadow_blur_radius = 0;
314
+ #else
315
+ static constexpr int16_t box_shadow_blur_radius = 0;
316
+ #endif
317
+ #if GEA_CSS_BOX_SHADOW
115
318
  int16_t box_shadow_spread = 0;
319
+ #else
320
+ static constexpr int16_t box_shadow_spread = 0;
321
+ #endif
322
+ #if GEA_CSS_BOX_SHADOW
116
323
  style_color_t box_shadow_color = 0;
324
+ #else
325
+ static constexpr style_color_t box_shadow_color = 0;
326
+ #endif
327
+ #if GEA_CSS_BOX_SHADOW
117
328
  uint8_t box_shadow_alpha = 0;
329
+ #else
330
+ static constexpr uint8_t box_shadow_alpha = 0;
331
+ #endif
118
332
 
119
333
  // --- per-side borders (default white/opaque, matching NodeLifecycle::init;
120
334
  // only relevant when a side width > 0, which is rare) ---
335
+ #if GEA_CSS_SIDE_BORDERS
121
336
  int16_t border_side_width[4] = {};
337
+ #else
338
+ static constexpr int16_t border_side_width[4] = {};
339
+ #endif
340
+ // 0: flat; 1: groove; 2: ridge; 3: inset; 4: outset.
341
+ #if GEA_CSS_BORDER_RELIEF
342
+ uint8_t border_relief[4] = {};
343
+ #else
344
+ static constexpr uint8_t border_relief[4] = {};
345
+ #endif
346
+ #if GEA_CSS_SIDE_BORDERS
122
347
  style_color_t border_side_color[4] = {
123
348
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
124
349
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
@@ -126,11 +351,32 @@ struct RareStyle {
126
351
  gea::framework::graphics::pixel::nativeColor(255, 255, 255),
127
352
  };
128
353
 
129
- uint8_t border_side_alpha[4] = {255, 255, 255, 255};
354
+ uint8_t border_side_alpha[4] = {255, 255, 255, 255};
355
+ #else
356
+ static constexpr style_color_t border_side_color[4] = {
357
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
358
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
359
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
360
+ gea::framework::graphics::pixel::nativeColor(255, 255, 255),
361
+ };
362
+
363
+ static constexpr uint8_t border_side_alpha[4] = {255, 255, 255, 255};
364
+ #endif
130
365
 
131
366
  // --- linear / overlay / radial gradients + background grid (defaults match
132
367
  // NodeLifecycle::init: alphas 255, stops 500/1000, angle 1800, radial
133
368
  // center/extent 500/1000) ---
369
+ #if GEA_CSS_BACKGROUND_LAYERS
370
+ uint16_t bg_image_layer_count = 1; // Includes none layers.
371
+ int32_t bg_size_list = -1, bg_position_list = -1, bg_repeat_list = -1;
372
+ int32_t bg_attachment_list = -1, bg_origin_list = -1;
373
+ #else
374
+ static constexpr uint16_t bg_image_layer_count = 1; // Includes none layers.
375
+ static constexpr int32_t bg_size_list = -1, bg_position_list = -1, bg_repeat_list = -1;
376
+ static constexpr int32_t bg_attachment_list = -1, bg_origin_list = -1;
377
+ #endif
378
+ #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS
379
+ uint16_t bg_gradient_layer = 0, bg_overlay_gradient_layer = 0, bg_radial_gradient_layer = 0;
134
380
  style_color_t bg_gradient_from_color = 0;
135
381
  style_color_t bg_gradient_mid_color = 0;
136
382
  style_color_t bg_gradient_to_color = 0;
@@ -169,8 +415,65 @@ struct RareStyle {
169
415
  uint16_t bg_grid_step_y = 0;
170
416
  uint8_t bg_grid_line_x = 0;
171
417
  uint8_t bg_grid_line_y = 0;
418
+ #else
419
+ static constexpr uint16_t bg_gradient_layer = 0, bg_overlay_gradient_layer = 0, bg_radial_gradient_layer = 0;
420
+ static constexpr style_color_t bg_gradient_from_color = 0;
421
+ static constexpr style_color_t bg_gradient_mid_color = 0;
422
+ static constexpr style_color_t bg_gradient_to_color = 0;
423
+ static constexpr uint8_t bg_gradient_from_alpha = 255;
424
+ static constexpr uint8_t bg_gradient_mid_alpha = 255;
425
+ static constexpr uint8_t bg_gradient_to_alpha = 255;
426
+ static constexpr uint16_t bg_gradient_mid_stop = 500;
427
+ static constexpr uint16_t bg_gradient_to_stop = 1000;
428
+ static constexpr uint8_t bg_gradient_has_mid = 0;
429
+ static constexpr int16_t bg_gradient_angle = 1800;
430
+ static constexpr uint8_t bg_overlay_gradient = 0;
431
+ static constexpr style_color_t bg_overlay_gradient_from_color = 0;
432
+ static constexpr style_color_t bg_overlay_gradient_mid_color = 0;
433
+ static constexpr style_color_t bg_overlay_gradient_to_color = 0;
434
+ static constexpr uint8_t bg_overlay_gradient_from_alpha = 255;
435
+ static constexpr uint8_t bg_overlay_gradient_mid_alpha = 255;
436
+ static constexpr uint8_t bg_overlay_gradient_to_alpha = 255;
437
+ static constexpr uint16_t bg_overlay_gradient_mid_stop = 500;
438
+ static constexpr uint16_t bg_overlay_gradient_to_stop = 1000;
439
+ static constexpr uint8_t bg_overlay_gradient_has_mid = 0;
440
+ static constexpr int16_t bg_overlay_gradient_angle = 1800;
441
+ static constexpr uint8_t bg_radial_gradient = 0;
442
+ static constexpr style_color_t bg_radial_gradient_from_color = 0;
443
+ static constexpr style_color_t bg_radial_gradient_to_color = 0;
444
+ static constexpr uint8_t bg_radial_gradient_from_alpha = 255;
445
+ static constexpr uint8_t bg_radial_gradient_to_alpha = 255;
446
+ static constexpr uint16_t bg_radial_gradient_stop = 1000;
447
+ static constexpr int16_t bg_radial_gradient_cx = 500;
448
+ static constexpr int16_t bg_radial_gradient_cy = 500;
449
+ static constexpr int16_t bg_radial_gradient_rx = 1000;
450
+ static constexpr int16_t bg_radial_gradient_ry = 1000;
451
+ static constexpr uint8_t bg_grid_axes = 0;
452
+ static constexpr style_color_t bg_grid_color = 0;
453
+ static constexpr uint8_t bg_grid_alpha = 255;
454
+ static constexpr uint16_t bg_grid_step_x = 0;
455
+ static constexpr uint16_t bg_grid_step_y = 0;
456
+ static constexpr uint8_t bg_grid_line_x = 0;
457
+ static constexpr uint8_t bg_grid_line_y = 0;
458
+ #endif
172
459
  };
173
460
 
461
+ // Individual translation is applied outside the transform list. Its translation
462
+ // therefore adds to the list translation, while authored values stay independent.
463
+ inline bool hasIndividualLinearTransform(const RareStyle &s)
464
+ {
465
+ return ((s.rotate_angle % 3600) != 0 && (s.rotate_axis_x || s.rotate_axis_y || s.rotate_axis_z)) ||
466
+ s.scale_x != 1000 || s.scale_y != 1000 || s.scale_z != 1000;
467
+ }
468
+ inline int composedTranslateX(const RareStyle &s) { return int(s.transform_translate_x) + s.translate_x; }
469
+ inline int composedTranslateY(const RareStyle &s) { return int(s.transform_translate_y) + s.translate_y; }
470
+ inline int composedTranslateZ(const RareStyle &s) { return int(s.transform_translate_z) + s.translate_z; }
471
+ inline int composedTranslateXPercent(const RareStyle &s) { return int(s.transform_translate_x_percent) + s.translate_x_percent; }
472
+ inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transform_translate_y_percent) + s.translate_y_percent; }
473
+
474
+ #define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS)
475
+ static_assert(GEA_CSS_RARE_STYLE || std::is_empty<RareStyle>::value, "An unguarded rare field requires a reachability family");
476
+
174
477
  struct ComputedStyle {
175
478
  int8_t display;
176
479
  // True iff the `display` property was explicitly authored (a CSS rule or
@@ -182,103 +485,347 @@ struct ComputedStyle {
182
485
  int8_t display_explicit;
183
486
  int8_t flex_direction;
184
487
  int8_t flex_direction_explicit;
488
+ #if GEA_CSS_FLEX_WRAP
185
489
  int8_t flex_wrap;
490
+ #else
491
+ static constexpr int8_t flex_wrap = 0;
492
+ #endif // low bits: 0 nowrap, 1 wrap, 2 wrap-reverse; bit 2: balance
186
493
  int8_t justify_content;
187
494
  int8_t align_items;
495
+ #if GEA_CSS_JUSTIFY_ITEMS
188
496
  int8_t justify_items;
497
+ #else
498
+ static constexpr int8_t justify_items = 0;
499
+ #endif
500
+ #if GEA_CSS_ALIGN_CONTENT
189
501
  int8_t align_content;
502
+ #else
503
+ static constexpr int8_t align_content = 0;
504
+ #endif
505
+ #if GEA_CSS_ALIGN_SELF
190
506
  int8_t align_self;
507
+ #else
508
+ static constexpr int8_t align_self = -1;
509
+ #endif
510
+ #if !GEA_CSS_U8_GAP
191
511
  int16_t gap;
512
+ #endif
513
+ int8_t box_sizing; // 0: content-box (CSS initial), 1: border-box
514
+ #if GEA_CSS_FLOATS
515
+ int8_t float_side;
516
+ #else
517
+ static constexpr int8_t float_side = 0;
518
+ #endif // 0: none, 1: left, 2: right
519
+ #if GEA_CSS_FLOATS
520
+ int8_t clear_side;
521
+ #else
522
+ static constexpr int8_t clear_side = 0;
523
+ #endif // 0: none, 1: left, 2: right, 3: both
524
+ #if GEA_CSS_WRITING_MODE
525
+ int8_t writing_mode;
526
+ #else
527
+ static constexpr int8_t writing_mode = 0;
528
+ #endif // -1: inherit, 0: horizontal-tb, 1: vertical-lr, 2: vertical-rl, 3: sideways-rl, 4: sideways-lr
529
+ #if GEA_CSS_WRITING_MODE
530
+ int8_t direction;
531
+ #else
532
+ static constexpr int8_t direction = 0;
533
+ #endif // -1: inherit, 0: ltr, 1: rtl
534
+ uint8_t margin_auto; // TRBL bit mask; numeric margins remain zero for auto
535
+ #if GEA_CSS_AXIS_GAP
536
+ int16_t row_gap, column_gap; // kUnset falls back to native gap
537
+ #else
538
+ static constexpr int16_t row_gap = kUnset, column_gap = kUnset;
539
+ #endif
540
+ #if GEA_CSS_PERCENT_GAP
541
+ int16_t row_gap_percent, column_gap_percent;
542
+ #else
543
+ static constexpr int16_t row_gap_percent = kUnset, column_gap_percent = kUnset;
544
+ #endif
545
+ // Fits the alignment gap before the 32-bit fields. A literal common border
546
+ // color must not allocate a rare-style record merely for its binding flags.
547
+ // Bits 0..3: explicit side colors; bit 4: literal common color;
548
+ // bits 5..8: explicit side currentColor. Unspecified colors use currentColor.
549
+ #if !GEA_CSS_U8_BORDER_FLAGS
550
+ uint16_t border_color_flags = 0;
551
+ #endif
552
+ #if GEA_CSS_ORDER
553
+ int32_t order; // Stable ordering of flex/grid items; never changes tree order.
554
+ #else
555
+ static constexpr int32_t order = 0;
556
+ #endif
557
+ // Inherited unitless line-height number as IEEE float bits; -1 means length/normal.
558
+ // Keep this common inherited value out of the much larger rare-style allocation.
559
+ int32_t line_height_multiplier;
192
560
 
561
+ int32_t width_expression;
562
+ #if GEA_CSS_HEIGHT_EXPRESSIONS
563
+ int32_t height_expression;
564
+ #else
565
+ static constexpr int32_t height_expression = -1;
566
+ #endif
193
567
  int16_t width, height;
194
568
  int16_t width_percent, height_percent;
195
- int16_t min_width, min_height;
196
- int16_t max_width, max_height;
569
+ #if GEA_CSS_MIN_WIDTH
570
+ int16_t min_width;
571
+ #else
572
+ static constexpr int16_t min_width = kUnset;
573
+ #endif
574
+ int16_t min_height;
575
+ int16_t max_width;
576
+ #if GEA_CSS_MAX_HEIGHT
577
+ int16_t max_height;
578
+ #else
579
+ static constexpr int16_t max_height = kUnset;
580
+ #endif
581
+ #if !GEA_CSS_U8_FLEX
197
582
  int16_t flex;
198
583
  int16_t flex_shrink;
584
+ #endif
199
585
  // CSS `flex-basis` as a definite main-axis length in px, or kUnset for `auto`
200
586
  // (the default — main size comes from content / flex-grow). When definite, the
201
587
  // flex item's main-axis size is set to this basis before grow/shrink, so
202
588
  // `flex: 0 0 26px` yields a 26px item instead of stretching to fill or sizing
203
589
  // to content. Percentage and `auto` bases resolve to kUnset (content-sized).
590
+ #if GEA_CSS_FLEX_BASIS
204
591
  int16_t flex_basis;
592
+ #else
593
+ static constexpr int16_t flex_basis = kUnset;
594
+ #endif
205
595
 
596
+ #if !GEA_CSS_U8_PADDING
206
597
  int16_t padding[4];
598
+ #endif
207
599
  int16_t margin[4];
208
600
 
601
+ #if GEA_CSS_Z_INDEX
209
602
  int8_t position;
603
+ int8_t z_index_auto;
604
+ #else
605
+ static constexpr int8_t z_index_auto = 1;
606
+ #endif
607
+ #if GEA_CSS_POSITION_PX_ALL
210
608
  int16_t pos_offsets[4];
609
+ #else
610
+ #if GEA_CSS_POSITION_TOP
611
+ int16_t pos_top;
612
+ #else
613
+ static constexpr int16_t pos_top = kUnset;
614
+ #endif
615
+ #if GEA_CSS_POSITION_RIGHT
616
+ int16_t pos_right;
617
+ #else
618
+ static constexpr int16_t pos_right = kUnset;
619
+ #endif
620
+ #if GEA_CSS_POSITION_BOTTOM
621
+ int16_t pos_bottom;
622
+ #else
623
+ static constexpr int16_t pos_bottom = kUnset;
624
+ #endif
625
+ #if GEA_CSS_POSITION_LEFT
626
+ int16_t pos_left;
627
+ #else
628
+ static constexpr int16_t pos_left = kUnset;
629
+ #endif
630
+ #endif
631
+ #if GEA_CSS_POSITION_PERCENT_ALL
211
632
  int16_t pos_offset_percent[4];
633
+ #else
634
+ #if GEA_CSS_POSITION_TOP_PERCENT
635
+ int16_t pos_percent_top;
636
+ #else
637
+ static constexpr int16_t pos_percent_top = kUnset;
638
+ #endif
639
+ #if GEA_CSS_POSITION_RIGHT_PERCENT
640
+ int16_t pos_percent_right;
641
+ #else
642
+ static constexpr int16_t pos_percent_right = kUnset;
643
+ #endif
644
+ #if GEA_CSS_POSITION_BOTTOM_PERCENT
645
+ int16_t pos_percent_bottom;
646
+ #else
647
+ static constexpr int16_t pos_percent_bottom = kUnset;
648
+ #endif
649
+ #if GEA_CSS_POSITION_LEFT_PERCENT
650
+ int16_t pos_percent_left;
651
+ #else
652
+ static constexpr int16_t pos_percent_left = kUnset;
653
+ #endif
654
+ #endif
655
+ #if GEA_CSS_Z_INDEX
212
656
  int16_t z_index;
657
+ #else
658
+ static constexpr int16_t z_index = 0;
659
+ #endif
213
660
 
214
- style_color_t bg_color;
661
+ // Group byte-sized paint flags before native colours. Keep natural alignment
662
+ // without paying padding between each RGB565 colour and its flags.
215
663
  int8_t has_bg;
216
664
  uint8_t bg_alpha;
665
+ #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
217
666
  int8_t bg_fill;
667
+ #else
668
+ static constexpr int8_t bg_fill = 0;
669
+ #endif
670
+ int8_t has_active_bg;
671
+ #if GEA_CSS_TEXT_ALPHA
672
+ uint8_t text_alpha;
673
+ #else
674
+ static constexpr uint8_t text_alpha = 255;
675
+ #endif
676
+ #if GEA_CSS_BORDER_ALPHA
677
+ uint8_t border_alpha;
678
+ #else
679
+ static constexpr uint8_t border_alpha = 255;
680
+ #endif
681
+ #if !GEA_CSS_Z_INDEX
682
+ // Without the paired stacking flag, position fills the paint-byte group
683
+ // instead of leaving a hole before the 16-bit offset array.
684
+ int8_t position;
685
+ #endif
686
+ style_color_t bg_color;
218
687
  // linear/overlay/radial gradients + background-grid moved to RareStyle (rare).
219
688
  style_color_t active_bg_color;
220
- int8_t has_active_bg;
221
689
  style_color_t text_color;
222
- uint8_t text_alpha;
690
+ #if GEA_CSS_OPACITY
223
691
  uint8_t opacity;
692
+ #else
693
+ static constexpr uint8_t opacity = 255;
694
+ #endif
695
+ #if GEA_CSS_BLINK
224
696
  int16_t blink_interval_ms;
225
697
  int32_t blink_started_ms;
226
698
  uint8_t blink_visible;
699
+ #else
700
+ static constexpr int16_t blink_interval_ms = 0;
701
+ static constexpr int32_t blink_started_ms = 0;
702
+ static constexpr uint8_t blink_visible = 1;
703
+ #endif
227
704
 
705
+ #if !GEA_CSS_U8_BORDER
228
706
  int16_t border_width;
707
+ #endif
229
708
  style_color_t border_color;
230
- uint8_t border_alpha;
231
709
  // per-side border width/color/alpha moved to RareStyle (rare); border_radius
232
710
  // stays here (rounded rects are common).
233
- int16_t border_radius[4];
234
- int16_t border_radius_percent[4];
711
+ #if !GEA_CSS_U8_RADIUS
712
+ int16_t border_radius[GEA_CSS_RADIUS_COUNT];
713
+ #endif
714
+ #if GEA_CSS_PERCENT_RADIUS
715
+ int16_t border_radius_percent[GEA_CSS_RADIUS_COUNT];
716
+ #else
717
+ static constexpr int16_t border_radius_percent[4] = {kUnset, kUnset, kUnset, kUnset};
718
+ #endif
235
719
 
236
720
  // transform / perspective / filter / box-shadow moved to RareStyle (rare).
237
721
 
238
722
  int16_t font_id;
723
+ #if !GEA_CSS_U8_FONT
239
724
  int16_t font_size;
725
+ #endif
240
726
  int16_t font_weight;
727
+ #if !GEA_CSS_U8_LINE_HEIGHT
241
728
  int16_t line_height;
729
+ #endif
242
730
  int8_t text_align;
243
731
  int8_t overflow;
732
+ #if GEA_CSS_OVERFLOW_AXES
244
733
  int8_t overflow_x;
245
734
  int8_t overflow_y;
735
+ #else
736
+ static constexpr int8_t overflow_x = 0, overflow_y = 0;
737
+ #endif
738
+ #if GEA_CSS_MASK
246
739
  int16_t mask_right_fade_width;
740
+ #else
741
+ static constexpr int16_t mask_right_fade_width = 0;
742
+ #endif
743
+ #if GEA_CSS_IMAGE_FIT
247
744
  int8_t image_fit;
745
+ #else
746
+ static constexpr int8_t image_fit = 0;
747
+ #endif
248
748
  // CSS `backface-visibility`: 0 = visible (default), 1 = hidden. When hidden, a
249
- // transformed face/text whose projected winding points away from the viewer is
250
- // culled — a closed opaque shape's back faces are occluded anyway, and this skips
251
- // the wasted overdraw. Default 0 = never culled (lone/visible quads stay drawn).
749
+ // flat element's entire painted subtree is culled when its back faces the viewer.
750
+ // A preserve-3d element keeps its descendants' individual visibility.
751
+ #if GEA_CSS_TRANSFORMS
252
752
  int8_t backface_hidden;
753
+ #else
754
+ static constexpr int8_t backface_hidden = 0;
755
+ #endif
756
+ #if GEA_CSS_VISIBILITY
757
+ int8_t visibility;
758
+ #else
759
+ static constexpr int8_t visibility = 0;
760
+ #endif // 0 visible, 1 hidden, 2 collapse (inherited)
253
761
  // CSS `text-decoration` — 0 = none (default), 1 = underline, 2 =
254
762
  // line-through. The text renderer paints a font-size-relative line at
255
763
  // the appropriate y-offset for each decorated run.
764
+ #if GEA_CSS_TEXT_DECORATION
256
765
  int8_t text_decoration;
766
+ #else
767
+ static constexpr int8_t text_decoration = 0;
768
+ #endif
257
769
  // CSS `text-transform` — 0 = none, 1 = uppercase, 2 = lowercase,
258
770
  // 3 = capitalize. Rendering applies this without mutating Node::text.
771
+ #if GEA_CSS_TEXT_TRANSFORM
259
772
  int8_t text_transform;
260
- // CSS `white-space` — 0 = normal (text wraps to fit the content width,
261
- // the default), 1 = nowrap (the run is laid out as a single line and is
262
- // never broken on the available width). Inherited, matching CSS. nowrap is
263
- // the precondition for `text-overflow: ellipsis` to do anything.
773
+ #else
774
+ static constexpr int8_t text_transform = 0;
775
+ #endif
776
+ // CSS `white-space`: 0 normal, 1 nowrap, 2 pre, 3 pre-wrap, 4 pre-line,
777
+ // 5 break-spaces. Inherited; space preservation and soft wrapping differ.
264
778
  int8_t white_space;
265
779
  // CSS `text-overflow` — 0 = clip (default), 1 = ellipsis. Only consulted
266
780
  // when the line cannot wrap (white-space: nowrap): an overflowing single
267
781
  // line is truncated at a glyph boundary and an ASCII "..." is appended so
268
782
  // the visible run fits within the content width. Not inherited.
269
783
  int8_t text_overflow;
784
+ // Compiler-proven unsigned ranges need one byte load, with no unpacking.
785
+ // Group these bytes so narrowing does not merely create alignment holes.
786
+ #if GEA_CSS_U8_BORDER_FLAGS
787
+ uint8_t border_color_flags = 0;
788
+ #endif
789
+ #if GEA_CSS_U8_GAP
790
+ uint8_t gap;
791
+ #endif
792
+ #if GEA_CSS_U8_FLEX
793
+ uint8_t flex, flex_shrink;
794
+ #endif
795
+ #if GEA_CSS_U8_PADDING
796
+ uint8_t padding[4];
797
+ #endif
798
+ #if GEA_CSS_U8_BORDER
799
+ uint8_t border_width;
800
+ #endif
801
+ #if GEA_CSS_U8_RADIUS
802
+ uint8_t border_radius[GEA_CSS_RADIUS_COUNT];
803
+ #endif
804
+ #if GEA_CSS_U8_FONT
805
+ uint8_t font_size;
806
+ #endif
807
+ #if GEA_CSS_U8_LINE_HEIGHT
808
+ uint8_t line_height;
809
+ #endif
810
+
270
811
  // CSS `pointer-events` — 0 = auto (default), 1 = none. A `none` node is never
271
812
  // the target of a pointer event and its subtree is skipped in hit-testing, so
272
813
  // clicks pass through to whatever is painted behind it (e.g. a decorative
273
814
  // overlay image over interactive controls). Default 0 via zero-init.
815
+ #if GEA_CSS_POINTER_EVENTS
274
816
  int8_t pointer_events;
817
+ #else
818
+ static constexpr int8_t pointer_events = 0;
819
+ #endif
275
820
 
276
821
  // Handle into the shared RareStyle pool for cold/rarely-used style fields
277
822
  // (grid tracks, gradients, transforms, shadows, …) that most nodes never set.
278
823
  // -1 = none, so a plain styled node pays 2 bytes instead of inlining ~200 B.
279
824
  // Read via rstyle(style), write via rstyleMut(style). Aggregate-friendly: this
280
825
  // is the only member with a default initializer; the rest stay zero-init.
281
- #if GEA_EMBEDDED_RARE_STYLE_INLINE
826
+ #if !GEA_CSS_RARE_STYLE
827
+ static constexpr int16_t rare_style = -1;
828
+ #elif GEA_EMBEDDED_RARE_STYLE_INLINE
282
829
  // Compiler-driven hot placement: the rare fields live inline (direct load, same cache
283
830
  // line — spine's access pattern), no rstyle() pool indirection per node. rare_style is
284
831
  // kept but vestigial (always -1) so pool-handle call sites compile as harmless no-ops;
@@ -362,7 +909,10 @@ struct ComputedStyle {
362
909
  // RareStyle split moved transform/gradient fields off the hot ComputedStyle struct, so
363
910
  // every `style.transform_*` read became a function call. The static local is one shared
364
911
  // instance across TUs (inline-function rule); rstyleMut/release/reset (style.cpp) use it.
365
- #if GEA_EMBEDDED_RARE_STYLE_INLINE
912
+ #if !GEA_CSS_RARE_STYLE
913
+ inline constexpr RareStyle kRareStyleZero{};
914
+ inline const RareStyle &rstyle(const ComputedStyle &style) { (void)style; return kRareStyleZero; }
915
+ #elif GEA_EMBEDDED_RARE_STYLE_INLINE
366
916
  // Inline-embedded rare fields: rstyle() is a direct member access — no pool, no branch, no
367
917
  // separate cache line (spine's access pattern). rstyleMut/release/reset are still defined
368
918
  // out-of-line in style.cpp (their bodies #if'd) because rstyleMut also invalidates the
@@ -387,6 +937,178 @@ RareStyle &rstyleMut(ComputedStyle &style);
387
937
  void releaseRareStyle(int16_t &handle); // frees the entry (or no-op when embedded)
388
938
  void resetRareStylePool(); // drops all entries (or no-op when embedded)
389
939
 
940
+ inline bool styleHasBackgroundImage(const ComputedStyle &style)
941
+ {
942
+ const auto &rare = rstyle(style);
943
+ return style.bg_fill != 0 || rare.bg_radial_gradient || rare.bg_overlay_gradient || rare.bg_grid_axes;
944
+ }
945
+
946
+ // Authored inheritance stays in the property override; ComputedStyle always
947
+ // contains resolved device-pixel widths, so descendants never re-evaluate em.
948
+ inline constexpr int kInheritedBorderWidth = -1;
949
+ inline int computedBorderWidth(const ComputedStyle &style, int side)
950
+ {
951
+ #if GEA_CSS_SIDE_BORDERS
952
+ const int specific = rstyle(style).border_side_width[side];
953
+ return specific > style.border_width ? specific : style.border_width;
954
+ #else
955
+ (void)side;
956
+ return style.border_width;
957
+ #endif
958
+ }
959
+
960
+ inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, const ComputedStyle *parent)
961
+ {
962
+ #if GEA_CSS_SIDE_BORDERS
963
+ int widths[4];
964
+ for (int i = 0; i < 4; ++i) {
965
+ widths[i] = computedBorderWidth(style, i);
966
+ if (side < 0 || side == i)
967
+ widths[i] = value == kInheritedBorderWidth ? (parent ? computedBorderWidth(*parent, i) : 0) : value;
968
+ }
969
+ const bool uniform = side < 0 && widths[0] == widths[1] && widths[0] == widths[2] && widths[0] == widths[3];
970
+ // A side can override a wider common border with a narrower or zero edge.
971
+ // Materialize the other sides before clearing that common width.
972
+ const int common = side < 0 ? (uniform ? widths[0] : 0) : (widths[side] < style.border_width ? 0 : style.border_width);
973
+ bool changed = common != style.border_width;
974
+ int stored[4];
975
+ for (int i = 0; i < 4; ++i) {
976
+ stored[i] = side < 0 ? (uniform ? 0 : widths[i]) : (common != style.border_width || side == i ? widths[i] : rstyle(style).border_side_width[i]);
977
+ changed |= stored[i] != rstyle(style).border_side_width[i];
978
+ }
979
+ if (!changed) return false;
980
+ style.border_width = common;
981
+ bool needsRare = false;
982
+ for (int i = 0; i < 4; ++i) needsRare |= stored[i] != rstyle(style).border_side_width[i];
983
+ if (needsRare) {
984
+ auto &rare = rstyleMut(style);
985
+ for (int i = 0; i < 4; ++i) rare.border_side_width[i] = stored[i];
986
+ }
987
+ return true;
988
+ #else
989
+ if (side >= 0) return false;
990
+ const int width = value == kInheritedBorderWidth ? (parent ? parent->border_width : 0) : value;
991
+ if (width == style.border_width) return false;
992
+ style.border_width = width;
993
+ return true;
994
+ #endif
995
+ }
996
+
997
+ inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
998
+ {
999
+ #if GEA_CSS_SIDE_BORDERS
1000
+ const unsigned previous = style.border_color_flags;
1001
+ unsigned next;
1002
+ if (side < 0) next = current ? 0u : 16u; // shorthand resets every side
1003
+ else {
1004
+ next = previous | (1u << side);
1005
+ if (current) next |= 1u << (side + 5);
1006
+ else next &= ~(1u << (side + 5));
1007
+ }
1008
+ if (next == previous) return false;
1009
+ style.border_color_flags = static_cast<uint16_t>(next);
1010
+ return true;
1011
+ #else
1012
+ if (side >= 0) return false;
1013
+ const unsigned next = current ? 0u : 16u;
1014
+ if (next == style.border_color_flags) return false;
1015
+ style.border_color_flags = static_cast<uint16_t>(next);
1016
+ return true;
1017
+ #endif
1018
+ }
1019
+
1020
+ inline bool borderColorIsCurrent(const ComputedStyle &style, int side = -1)
1021
+ {
1022
+ #if GEA_CSS_SIDE_BORDERS
1023
+ const unsigned flags = style.border_color_flags;
1024
+ if (side >= 0 && (flags & (1u << side))) return flags & (1u << (side + 5));
1025
+ return !(flags & 16u);
1026
+ #else
1027
+ (void)side;
1028
+ return !(style.border_color_flags & 16u);
1029
+ #endif
1030
+ }
1031
+
1032
+ inline style_color_t borderPaintColor(const ComputedStyle &style, int side = -1)
1033
+ {
1034
+ #if GEA_CSS_SIDE_BORDERS
1035
+ if (borderColorIsCurrent(style, side)) return style.text_color;
1036
+ return side >= 0 && (style.border_color_flags & (1u << side))
1037
+ ? rstyle(style).border_side_color[side] : style.border_color;
1038
+ #else
1039
+ return borderColorIsCurrent(style, side) ? style.text_color : style.border_color;
1040
+ #endif
1041
+ }
1042
+
1043
+ inline uint8_t borderPaintAlpha(const ComputedStyle &style, int side = -1)
1044
+ {
1045
+ #if GEA_CSS_SIDE_BORDERS
1046
+ if (borderColorIsCurrent(style, side)) return style.text_alpha;
1047
+ return side >= 0 && (style.border_color_flags & (1u << side))
1048
+ ? rstyle(style).border_side_alpha[side] : style.border_alpha;
1049
+ #else
1050
+ return borderColorIsCurrent(style, side) ? style.text_alpha : style.border_alpha;
1051
+ #endif
1052
+ }
1053
+
1054
+ inline bool borderColorsDiffer(const ComputedStyle &style)
1055
+ {
1056
+ #if GEA_CSS_SIDE_BORDERS
1057
+ for (int side = 1; side < 4; ++side)
1058
+ if (borderPaintColor(style, side) != borderPaintColor(style, 0) ||
1059
+ borderPaintAlpha(style, side) != borderPaintAlpha(style, 0)) return true;
1060
+ return false;
1061
+ #else
1062
+ (void)style;
1063
+ return false;
1064
+ #endif
1065
+ }
1066
+
1067
+ inline bool borderUsesCurrentColor(const ComputedStyle &style)
1068
+ {
1069
+ #if GEA_CSS_SIDE_BORDERS
1070
+ for (int side = 0; side < 4; ++side)
1071
+ if ((style.border_width > 0 || rstyle(style).border_side_width[side] > 0) && borderColorIsCurrent(style, side)) return true;
1072
+ return false;
1073
+ #else
1074
+ return style.border_width > 0 && borderColorIsCurrent(style);
1075
+ #endif
1076
+ }
1077
+
1078
+ // Layout boxes include padding and borders. CSS width/height can select either
1079
+ // the content box or border box, but child origins always use these insets.
1080
+ inline int boxInset(const ComputedStyle &style, int side)
1081
+ {
1082
+ #if GEA_CSS_SIDE_BORDERS
1083
+ const int sideWidth = rstyle(style).border_side_width[side];
1084
+ return style.padding[side] + (sideWidth > style.border_width ? sideWidth : style.border_width);
1085
+ #else
1086
+ return style.padding[side] + style.border_width;
1087
+ #endif
1088
+ }
1089
+ inline int boxInsets(const ComputedStyle &style, bool horizontal)
1090
+ {
1091
+ return horizontal ? boxInset(style, 1) + boxInset(style, 3) : boxInset(style, 0) + boxInset(style, 2);
1092
+ }
1093
+ inline int contentSizeToBorderSize(const ComputedStyle &style, int size, bool horizontal)
1094
+ {
1095
+ const int insets = boxInsets(style, horizontal);
1096
+ const int result = size + (style.box_sizing == 0 ? insets : 0);
1097
+ return result < insets ? insets : result;
1098
+ }
1099
+
1100
+ inline int clampBorderBoxSize(const ComputedStyle &style, int size, bool horizontal)
1101
+ {
1102
+ const int minSize = horizontal ? style.min_width : style.min_height;
1103
+ const int maxSize = horizontal ? style.max_width : style.max_height;
1104
+ if (maxSize != kUnset) {
1105
+ const int limit = contentSizeToBorderSize(style, maxSize, horizontal);
1106
+ if (size > limit) size = limit;
1107
+ }
1108
+ const int floor = contentSizeToBorderSize(style, minSize == kUnset ? 0 : minSize, horizontal);
1109
+ return size < floor ? floor : size;
1110
+ }
1111
+
390
1112
  inline bool isDisplayNone(const ComputedStyle &style)
391
1113
  {
392
1114
  return style.display == kDisplayNone;
@@ -394,7 +1116,7 @@ inline bool isDisplayNone(const ComputedStyle &style)
394
1116
 
395
1117
  inline bool isDisplayGrid(const ComputedStyle &style)
396
1118
  {
397
- return style.display == kDisplayGrid;
1119
+ return GEA_CSS_GRID && style.display == kDisplayGrid;
398
1120
  }
399
1121
 
400
1122
  inline bool usesRowLayout(const ComputedStyle &style)
@@ -417,31 +1139,79 @@ inline bool usesRowLayout(const ComputedStyle &style)
417
1139
  return style.flex_direction_explicit ? style.flex_direction == 1 : true;
418
1140
  }
419
1141
 
1142
+ // Keep specified axes separate: changing the other axis must undo CSS's
1143
+ // visible->auto / clip->hidden computed-value conversion.
1144
+ inline bool isScrollableOverflow(int value) { return value == 1 || value == 2; }
1145
+ inline int usedOverflow(int axis, int other)
1146
+ {
1147
+ return isScrollableOverflow(other) ? (axis == 0 ? 2 : axis == 3 ? 1 : axis) : axis;
1148
+ }
1149
+ #if GEA_CSS_OVERFLOW_AXES
1150
+ inline int overflowX(const ComputedStyle &style) { return usedOverflow(style.overflow_x, style.overflow_y); }
1151
+ inline int overflowY(const ComputedStyle &style) { return usedOverflow(style.overflow_y, style.overflow_x); }
1152
+ #else
1153
+ // A single-axis shorthand gives both axes exactly this value. The existing
1154
+ // helpers become one direct field read, with no axis-coupling computation.
1155
+ inline int overflowX(const ComputedStyle &style) { return style.overflow; }
1156
+ inline int overflowY(const ComputedStyle &style) { return style.overflow; }
1157
+ #endif
420
1158
  inline int8_t aggregateOverflow(int8_t overflowX, int8_t overflowY)
421
1159
  {
422
- if (overflowX == 2 || overflowY == 2) return 2;
423
- if (overflowX != 0 || overflowY != 0) return 1;
424
- return 0;
1160
+ const int x = usedOverflow(overflowX, overflowY), y = usedOverflow(overflowY, overflowX);
1161
+ if (x == 2 || y == 2) return 2;
1162
+ if (x == 1 || y == 1) return 1;
1163
+ return x == 3 || y == 3 ? 3 : 0;
1164
+ }
1165
+ inline bool overflowEstablishesContext(const ComputedStyle &style)
1166
+ {
1167
+ return isScrollableOverflow(overflowX(style)) || isScrollableOverflow(overflowY(style));
1168
+ }
1169
+ // Grouping effects force the used transform-style to flat.
1170
+ inline bool preserves3D(const ComputedStyle &style)
1171
+ {
1172
+ #if GEA_CSS_TRANSFORMS
1173
+ const auto &rare = rstyle(style);
1174
+ return rare.transform_preserve_3d && style.opacity == 255 &&
1175
+ !isScrollableOverflow(overflowX(style)) && !isScrollableOverflow(overflowY(style)) &&
1176
+ !rare.filter_present && !rare.filter_blur_radius && !(rare.containment & 16) &&
1177
+ !style.mask_right_fade_width;
1178
+ #else
1179
+ (void)style;
1180
+ return false;
1181
+ #endif
425
1182
  }
426
-
427
1183
  inline bool scrollsOverflowX(const ComputedStyle &style)
428
1184
  {
429
- return style.overflow_x == 2;
1185
+ #if GEA_CSS_SCROLLING
1186
+ return overflowX(style) == 2;
1187
+ #else
1188
+ (void)style;
1189
+ return false;
1190
+ #endif
430
1191
  }
431
-
432
1192
  inline bool scrollsOverflowY(const ComputedStyle &style)
433
1193
  {
434
- return style.overflow_y == 2;
1194
+ #if GEA_CSS_SCROLLING
1195
+ return overflowY(style) == 2;
1196
+ #else
1197
+ (void)style;
1198
+ return false;
1199
+ #endif
435
1200
  }
436
1201
 
437
1202
  inline bool hasSideBorder(const ComputedStyle &style)
438
1203
  {
1204
+ #if GEA_CSS_SIDE_BORDERS
439
1205
  if (style.rare_style < 0) return false; // no RareStyle => no per-side borders
440
1206
  const RareStyle &r = rstyle(style);
441
1207
  return r.border_side_width[0] > 0 ||
442
1208
  r.border_side_width[1] > 0 ||
443
1209
  r.border_side_width[2] > 0 ||
444
1210
  r.border_side_width[3] > 0;
1211
+ #else
1212
+ (void)style;
1213
+ return false;
1214
+ #endif
445
1215
  }
446
1216
 
447
1217
  inline bool hasAnyBorder(const ComputedStyle &style)
@@ -449,6 +1219,12 @@ inline bool hasAnyBorder(const ComputedStyle &style)
449
1219
  return style.border_width > 0 || hasSideBorder(style);
450
1220
  }
451
1221
 
1222
+ inline bool hasBorderRelief(const ComputedStyle &style)
1223
+ {
1224
+ const auto &r = rstyle(style);
1225
+ return r.border_relief[0] || r.border_relief[1] || r.border_relief[2] || r.border_relief[3];
1226
+ }
1227
+
452
1228
  struct LayoutBox {
453
1229
  int16_t x, y;
454
1230
  int16_t width, height;
@@ -461,6 +1237,10 @@ struct LayoutBox {
461
1237
  // every box that starts its own line, which is every box outside an inline
462
1238
  // formatting row.
463
1239
  int16_t inline_indent = 0;
1240
+ // The hypothetical block-start margin edge of an out-of-flow child,
1241
+ // relative to its static-position parent. Capture before relative offsets
1242
+ // and absolute-coordinate conversion; retained refresh reuses this anchor.
1243
+ int16_t static_block_start = 0;
464
1244
 
465
1245
  int16_t previous_x, previous_y;
466
1246
  int16_t previous_width, previous_height;
@@ -469,12 +1249,21 @@ struct LayoutBox {
469
1249
  // content height of itemCount * rowHeight (e.g. 5000 * 259 ≈ 1.29M px),
470
1250
  // which overflows int16_t. Truncation made scroll_content_height wrap
471
1251
  // negative, so scrollMaxY clamped to 0 and the list refused to scroll.
1252
+ #if GEA_CSS_SCROLLING
472
1253
  int32_t scroll_x;
473
1254
  int32_t scroll_y;
474
1255
  int32_t scroll_content_width;
475
1256
  int32_t scroll_content_height;
476
1257
  int32_t previous_scroll_x;
477
1258
  int32_t previous_scroll_y;
1259
+ #else
1260
+ static constexpr int32_t scroll_x = 0;
1261
+ static constexpr int32_t scroll_y = 0;
1262
+ static constexpr int32_t scroll_content_width = 0;
1263
+ static constexpr int32_t scroll_content_height = 0;
1264
+ static constexpr int32_t previous_scroll_x = 0;
1265
+ static constexpr int32_t previous_scroll_y = 0;
1266
+ #endif
478
1267
 
479
1268
  // Intra-pass layout memo: the flex engine re-measures whole subtrees after
480
1269
  // every parent resize (repositionChildren -> measureChildren -> layoutNode),
@@ -485,44 +1274,97 @@ struct LayoutBox {
485
1274
  // that pattern. Scoped to a single pass (serial bumped by beginLayoutPass),
486
1275
  // so no cross-frame invalidation is needed and the final
487
1276
  // absolute-coordinate resolve is unaffected.
488
- // result_w/h: the node dims each slot's layout produced. The MRU slot's
489
- // result is the node's live state, so its hit is unconditional; the older
490
- // slot's layout has been overwritten in the tree, so its hit is only sound
491
- // when it produced exactly the current dims (the subtree is then
492
- // byte-identical — child avails derive from the node's own box).
1277
+ // 16-bit pass tags are direct loads, not packed fields. beginLayoutPass()
1278
+ // clears every tag before reusing serial 1 after 65,535 passes.
1279
+ // Both slots share result_w/h. An older entry can hit only when its result
1280
+ // equals the current dimensions, so discard it on a dimension change instead
1281
+ // of storing a second result that can never hit. External flex resizing still
1282
+ // compares the shared result against live dimensions before either lookup.
493
1283
  int16_t memo_avail_w;
494
1284
  int16_t memo_avail_h;
495
1285
  int16_t memo_result_w;
496
1286
  int16_t memo_result_h;
497
- uint32_t memo_pass;
1287
+ uint16_t memo_pass;
498
1288
  int16_t memo2_avail_w;
499
1289
  int16_t memo2_avail_h;
500
- int16_t memo2_result_w;
501
- int16_t memo2_result_h;
502
- uint32_t memo2_pass;
1290
+ uint16_t memo2_pass;
1291
+ uint8_t static_block_axis = 0; // 0: unavailable, 1: y, 2: x
503
1292
  };
504
1293
 
505
1294
  struct RenderState {
1295
+ #if GEA_CSS_TRANSFORMS
1296
+ int16_t previous_rotate_angle;
1297
+ int32_t previous_rotate_axis_x, previous_rotate_axis_y, previous_rotate_axis_z;
1298
+ int16_t previous_scale_x, previous_scale_y, previous_scale_z;
506
1299
  int16_t previous_transform_rotate;
507
1300
  int16_t previous_transform_rotate_x;
508
1301
  int16_t previous_transform_rotate_y;
509
- int16_t previous_transform_translate_x;
510
- int16_t previous_transform_translate_y;
511
- int16_t previous_transform_translate_z;
512
- int16_t previous_transform_translate_x_percent;
513
- int16_t previous_transform_translate_y_percent;
1302
+ int16_t previous_translate_x, previous_translate_y, previous_translate_z;
1303
+ int16_t previous_translate_x_percent, previous_translate_y_percent;
1304
+ uint8_t previous_transform_translate_outer_axes;
1305
+ int32_t previous_transform_translate_x;
1306
+ int32_t previous_transform_translate_y;
1307
+ int32_t previous_transform_translate_z;
1308
+ int32_t previous_transform_translate_x_percent;
1309
+ int32_t previous_transform_translate_y_percent;
514
1310
  int16_t previous_transform_scale_x;
515
1311
  int16_t previous_transform_scale_y;
1312
+ int16_t previous_transform_scale_z;
516
1313
  int16_t previous_transform_origin_x;
517
1314
  int16_t previous_transform_origin_y;
518
1315
  int16_t previous_perspective;
519
1316
  int16_t previous_perspective_origin_x;
520
1317
  int16_t previous_perspective_origin_y;
1318
+ uint8_t previous_transformable_box;
1319
+ #else
1320
+ static constexpr int16_t previous_rotate_angle = 0;
1321
+ static constexpr int32_t previous_rotate_axis_x = 0;
1322
+ static constexpr int32_t previous_rotate_axis_y = 0;
1323
+ static constexpr int32_t previous_rotate_axis_z = 1000000;
1324
+ static constexpr int16_t previous_scale_x = 1000;
1325
+ static constexpr int16_t previous_scale_y = 1000;
1326
+ static constexpr int16_t previous_scale_z = 1000;
1327
+ static constexpr int16_t previous_transform_rotate = 0;
1328
+ static constexpr int16_t previous_transform_rotate_x = 0;
1329
+ static constexpr int16_t previous_transform_rotate_y = 0;
1330
+ static constexpr int16_t previous_translate_x = 0;
1331
+ static constexpr int16_t previous_translate_y = 0;
1332
+ static constexpr int16_t previous_translate_z = 0;
1333
+ static constexpr int16_t previous_translate_x_percent = 0;
1334
+ static constexpr int16_t previous_translate_y_percent = 0;
1335
+ static constexpr uint8_t previous_transform_translate_outer_axes = 0;
1336
+ static constexpr int32_t previous_transform_translate_x = 0;
1337
+ static constexpr int32_t previous_transform_translate_y = 0;
1338
+ static constexpr int32_t previous_transform_translate_z = 0;
1339
+ static constexpr int32_t previous_transform_translate_x_percent = 0;
1340
+ static constexpr int32_t previous_transform_translate_y_percent = 0;
1341
+ static constexpr int16_t previous_transform_scale_x = 1000;
1342
+ static constexpr int16_t previous_transform_scale_y = 1000;
1343
+ static constexpr int16_t previous_transform_scale_z = 1000;
1344
+ static constexpr int16_t previous_transform_origin_x = 500;
1345
+ static constexpr int16_t previous_transform_origin_y = 500;
1346
+ static constexpr int16_t previous_perspective = 0;
1347
+ static constexpr int16_t previous_perspective_origin_x = 500;
1348
+ static constexpr int16_t previous_perspective_origin_y = 500;
1349
+ static constexpr uint8_t previous_transformable_box = 0;
1350
+ #endif
1351
+ #if GEA_CSS_FILTERS
521
1352
  int16_t previous_filter_blur_radius;
1353
+ #else
1354
+ static constexpr int16_t previous_filter_blur_radius = 0;
1355
+ #endif
522
1356
 
523
1357
  uint8_t dirty;
1358
+ #if GEA_CSS_SCROLLING
524
1359
  uint8_t scroll_dirty;
1360
+ #else
1361
+ static constexpr uint8_t scroll_dirty = 0;
1362
+ #endif
1363
+ #if GEA_CSS_SCROLLING
525
1364
  uint8_t non_scroll_dirty;
1365
+ #else
1366
+ static constexpr uint8_t non_scroll_dirty = 0;
1367
+ #endif
526
1368
  // Set alongside `dirty` when the change can affect GEOMETRY (layout
527
1369
  // property, box-changing text, structural mutation). Paint-only dirt (a
528
1370
  // background/color class toggle, stable-box text) leaves it clear, letting
@@ -530,10 +1372,12 @@ struct RenderState {
530
1372
  // relayout compute its LCA over geometry-relevant nodes only. Cleared with
531
1373
  // `dirty`.
532
1374
  uint8_t layout_dirty;
1375
+ #if GEA_CSS_TRANSFORMS
533
1376
  uint8_t transform_dirty;
1377
+ #else
1378
+ static constexpr uint8_t transform_dirty = 0;
1379
+ #endif
534
1380
  uint8_t bg_recolor_pending;
535
- style_color_t bg_recolor_from;
536
- style_color_t bg_recolor_to;
537
1381
  // Tree::setText pre-measures incoming text and sets this flag when the
538
1382
  // update is safe for the retained/direct-replay path: absolute text may
539
1383
  // update its measured bbox out of flow, while in-flow text must keep the
@@ -544,13 +1388,11 @@ struct RenderState {
544
1388
  // Glyph-incremental text dirty (set by Tree::setText): when a content-only text
545
1389
  // change keeps the same layout box and only a middle run of glyphs differs
546
1390
  // (e.g. a ticking counter "58"->"57", a clock), the dirty collector flushes only
547
- // [text_dirty_x0, text_dirty_x1] across the node's height instead of the whole
1391
+ // [text_dirty.x0, text_dirty.x1] across the node's height instead of the whole
548
1392
  // box. A 26vmin badge re-render then copies just the changed digits (~one glyph)
549
1393
  // rather than ~the whole panel width, so it fits a TE-locked frame's slack.
550
1394
  // Cleared with text_layout_stable each frame (LayoutSnapshot::capture).
551
1395
  uint8_t text_partial_dirty;
552
- int16_t text_dirty_x0;
553
- int16_t text_dirty_x1;
554
1396
  // This box SHARES a line box with other inline content, so it was placed on
555
1397
  // that line's baseline (FlexLayoutPass::placeLineItems). TextRenderer::record
556
1398
  // then draws the run at its baseline instead of centring the string's ink in
@@ -558,40 +1400,58 @@ struct RenderState {
558
1400
  // glyphs reach, so runs of different words — or different fonts — on one line
559
1401
  // end up at different heights. A run that owns its line keeps the centring.
560
1402
  uint8_t inline_baseline;
1403
+ // Only one paint shortcut may own this scratch space. Mixed changes use
1404
+ // the ordinary dirty-region replay. The recolor destination is bg_color.
1405
+ union {
1406
+ style_color_t bg_recolor_from;
1407
+ struct { int16_t x0, x1; } text_dirty;
1408
+ };
561
1409
  };
562
1410
 
1411
+ inline bool hadIndividualLinearTransform(const RenderState &s)
1412
+ {
1413
+ return ((s.previous_rotate_angle % 3600) != 0 && (s.previous_rotate_axis_x || s.previous_rotate_axis_y || s.previous_rotate_axis_z)) ||
1414
+ s.previous_scale_x != 1000 || s.previous_scale_y != 1000 || s.previous_scale_z != 1000;
1415
+ }
1416
+
563
1417
  struct Node {
564
- NodeType type;
565
- ComputedStyle style;
1418
+ // Keep the hot style at offset zero. Reuse only record tail padding;
1419
+ // ordinary field reads remain naturally aligned direct loads.
1420
+ [[no_unique_address]] ComputedStyle style;
1421
+ // Interned tag id; zero is the empty tag. Fits in style's tail padding
1422
+ // when the source proof removes the unused alpha fields.
1423
+ int16_t tag_id = 0;
566
1424
 
567
1425
  int16_t parent;
568
1426
  int16_t first_child, last_child;
569
1427
  int16_t next_sibling, prev_sibling;
570
1428
 
571
- // Text content. std::string gives us dynamic sizing without the silent
572
- // truncation a fixed buffer caused, and on every modern libstdc++ /
573
- // libc++ build it has small-string optimization — strings up to ~22
574
- // chars stay inline in the std::string header with no heap allocation,
575
- // so the common short-label case (button text, counter values) doesn't
576
- // pay an allocation cost. Apps that put paragraph copy in a single
577
- // text node (e.g. typography sampler, ~160 chars) get the heap
578
- // allocation they actually need rather than being chopped to 63 chars.
579
- std::string text;
1429
+ // Index into the shared pool for optional listeners/attributes/styles.
1430
+ // -1 means absent and is restored by Node{} / node reuse.
1431
+ int16_t rare_data = -1;
1432
+ // Empty structural nodes retain only the four-byte text ownership handle.
1433
+ NodeText text;
1434
+ #if GEA_UI_IMAGE_NODES
580
1435
  int16_t image_id;
581
- // Interned tag id (index into the global tag table) rather than a 16-byte
582
- // inline string — the tag vocabulary is ~15 distinct strings, so this saves
583
- // 14 B/node. 0 = the empty tag. Use Tree::tagName(node) / tagFromId(tag_id)
584
- // to read the string, internTag(...) to write.
585
- int16_t tag_id = 0;
586
-
587
- LayoutBox layout;
1436
+ #else
1437
+ static constexpr int16_t image_id = -1;
1438
+ #endif
1439
+ [[no_unique_address]] LayoutBox layout;
1440
+ NodeType type;
588
1441
  RenderState render;
589
-
590
- // Blink-style "rare data" handle: index into the shared NodeRareData pool for
591
- // the cold/optional per-node state most nodes never have (event listeners, and
592
- // later attributes/custom-properties/etc.). -1 = none, so the common node pays
593
- // 2 bytes instead of inlining those tables. Reset to -1 by Node{} / node reuse.
594
- int16_t rare_data = -1;
595
1442
  };
596
1443
 
1444
+ // Overflow clips the padding edge on each non-visible axis. Open axes span
1445
+ // the positive display coordinate range and remain stationary during replay.
1446
+ inline void overflowClipBounds(const Node &node, int &x, int &y, int &w, int &h)
1447
+ {
1448
+ const auto &s = node.style;
1449
+ const int left = boxInset(s, 3) - s.padding[3], right = boxInset(s, 1) - s.padding[1];
1450
+ const int top = boxInset(s, 0) - s.padding[0], bottom = boxInset(s, 2) - s.padding[2];
1451
+ x = overflowX(s) ? node.layout.x + left : 0;
1452
+ y = overflowY(s) ? node.layout.y + top : 0;
1453
+ w = overflowX(s) ? std::max(0, node.layout.width - left - right) : 32767;
1454
+ h = overflowY(s) ? std::max(0, node.layout.height - top - bottom) : 32767;
1455
+ }
1456
+
597
1457
  } // namespace gea::embedded::ui