@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.
Files changed (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/bitmap_font.cpp +165 -0
  4. package/canvas.cpp +4608 -0
  5. package/components/Button.d.ts +4 -0
  6. package/components/Button.tsx +32 -0
  7. package/components/Image.d.ts +3 -0
  8. package/components/Image.tsx +17 -0
  9. package/components/Text.d.ts +3 -0
  10. package/components/Text.tsx +9 -0
  11. package/components/View.d.ts +3 -0
  12. package/components/View.tsx +24 -0
  13. package/components/index.d.ts +8 -0
  14. package/components/index.ts +4 -0
  15. package/css/animation.h +252 -0
  16. package/css/declarative.h +131 -0
  17. package/css/easing.h +160 -0
  18. package/css/engine.h +223 -0
  19. package/css/interpolate.h +38 -0
  20. package/image_store.cpp +807 -0
  21. package/package.json +62 -0
  22. package/rasterized_font.cpp +570 -0
  23. package/touch_runtime.cpp +513 -0
  24. package/ui/absolute_leaf_refresh.cpp +279 -0
  25. package/ui/absolute_leaf_refresh.h +12 -0
  26. package/ui/canvas_element.cpp +2314 -0
  27. package/ui/canvas_element.h +353 -0
  28. package/ui/canvas_store.cpp +188 -0
  29. package/ui/canvas_store.h +59 -0
  30. package/ui/core.cpp +135 -0
  31. package/ui/css_atom.cpp +155 -0
  32. package/ui/css_atom.h +21 -0
  33. package/ui/dirty_regions.cpp +66 -0
  34. package/ui/dirty_regions.h +34 -0
  35. package/ui/display_invalidation.cpp +101 -0
  36. package/ui/display_invalidation.h +15 -0
  37. package/ui/document.cpp +356 -0
  38. package/ui/document.h +101 -0
  39. package/ui/image.h +16 -0
  40. package/ui/image_element.cpp +13 -0
  41. package/ui/image_node.cpp +165 -0
  42. package/ui/input.cpp +936 -0
  43. package/ui/input_render.cpp +213 -0
  44. package/ui/internal.h +567 -0
  45. package/ui/layout.cpp +2025 -0
  46. package/ui/layout_snapshot.cpp +82 -0
  47. package/ui/layout_snapshot.h +12 -0
  48. package/ui/mirror.h +25 -0
  49. package/ui/node.cpp +243 -0
  50. package/ui/node.h +154 -0
  51. package/ui/node_lifecycle.cpp +137 -0
  52. package/ui/node_lifecycle.h +13 -0
  53. package/ui/node_model.h +597 -0
  54. package/ui/refresh_perf.h +235 -0
  55. package/ui/refresh_trace.h +68 -0
  56. package/ui/render.cpp +12097 -0
  57. package/ui/root_scroll_refresh.cpp +859 -0
  58. package/ui/root_scroll_refresh.h +30 -0
  59. package/ui/state_init.h +21 -0
  60. package/ui/style.cpp +14994 -0
  61. package/ui/style.h +727 -0
  62. package/ui/style_values.h +31 -0
  63. package/ui/text.cpp +2010 -0
  64. package/ui/text.h +15 -0
  65. package/ui/text_element.cpp +15 -0
  66. package/ui/tree_events.cpp +621 -0
  67. package/ui/tree_events.h +69 -0
  68. package/ui/tree_internal.h +191 -0
  69. package/ui/tree_nodes.cpp +628 -0
  70. package/ui/tree_render.cpp +3138 -0
  71. package/ui/tree_scroll_mirror.cpp +101 -0
  72. package/ui/tree_state.cpp +574 -0
  73. package/ui/tree_state.h +235 -0
  74. package/ui/tree_style.cpp +698 -0
  75. package/ui/ui.h +9 -0
  76. package/ui/view.cpp +2232 -0
  77. package/ui/view.h +14 -0
  78. package/ui/view_element.cpp +13 -0
  79. package/ui/viewport_region.cpp +36 -0
  80. package/ui/viewport_region.h +12 -0
  81. package/ui/virtual_keyboard.cpp +908 -0
  82. package/ui/virtual_keyboard.h +59 -0
  83. package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
  84. package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
  85. package/vendor/stb/stb_image.h +7988 -0
  86. package/vendor/stb/stb_truetype.h +5079 -0
@@ -0,0 +1,698 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #include "display_invalidation.h"
3
+ #include "internal.h"
4
+ #include "node_lifecycle.h"
5
+ #include "refresh_perf.h"
6
+ #include "style_values.h"
7
+ #include "tree_state.h"
8
+
9
+ // Skip the inline-style record for Left/Top (see setStyleValue). Default off: keep the
10
+ // record so static-authored absolute elements survive class-recompute. Opt in per-app
11
+ // for reactive-keyed-list-position apps (bouncing-balls-jsx) that re-apply every frame.
12
+ #ifndef GEA_EMBEDDED_SKIP_POSITION_INLINE_RECORD
13
+ #define GEA_EMBEDDED_SKIP_POSITION_INLINE_RECORD 0
14
+ #endif
15
+
16
+ namespace gea::embedded::ui {
17
+
18
+ namespace {
19
+
20
+ bool nodeParticipatesInMountedTree(const TreeState &state, int node)
21
+ {
22
+ const int root = Tree::instance().mountedRoot();
23
+ if (root < 0) return false;
24
+ for (int current = node; current >= 0 && current < state.nodeCount; current = state.nodes[current].parent) {
25
+ if (current == root) return true;
26
+ }
27
+ return false;
28
+ }
29
+
30
+ bool isTransformProperty(Property prop)
31
+ {
32
+ switch (prop) {
33
+ case Property::TransformRotate:
34
+ case Property::TransformRotateX:
35
+ case Property::TransformRotateY:
36
+ case Property::TransformTranslateX:
37
+ case Property::TransformTranslateY:
38
+ case Property::TransformTranslateZ:
39
+ case Property::TransformTranslateXPercent:
40
+ case Property::TransformTranslateYPercent:
41
+ case Property::TransformScaleX:
42
+ case Property::TransformScaleY:
43
+ case Property::TransformOriginX:
44
+ case Property::TransformOriginY:
45
+ case Property::Perspective:
46
+ case Property::PerspectiveOriginX:
47
+ case Property::PerspectiveOriginY:
48
+ return true;
49
+ default:
50
+ return false;
51
+ }
52
+ }
53
+
54
+ bool isLayoutProperty(Property prop)
55
+ {
56
+ switch (prop) {
57
+ case Property::Display:
58
+ case Property::FlexDirection:
59
+ case Property::FlexWrap:
60
+ case Property::JustifyContent:
61
+ case Property::AlignItems:
62
+ case Property::JustifyItems:
63
+ case Property::AlignContent:
64
+ case Property::AlignSelf:
65
+ case Property::Gap:
66
+ case Property::Width:
67
+ case Property::Height:
68
+ case Property::WidthPercent:
69
+ case Property::HeightPercent:
70
+ case Property::MinWidth:
71
+ case Property::MinHeight:
72
+ case Property::MaxWidth:
73
+ case Property::MaxHeight:
74
+ case Property::Flex:
75
+ case Property::FlexShrink:
76
+ case Property::FlexBasis:
77
+ case Property::PaddingTop:
78
+ case Property::PaddingRight:
79
+ case Property::PaddingBottom:
80
+ case Property::PaddingLeft:
81
+ case Property::MarginTop:
82
+ case Property::MarginRight:
83
+ case Property::MarginBottom:
84
+ case Property::MarginLeft:
85
+ case Property::Position:
86
+ case Property::Top:
87
+ case Property::Right:
88
+ case Property::Bottom:
89
+ case Property::Left:
90
+ case Property::TopPercent:
91
+ case Property::RightPercent:
92
+ case Property::BottomPercent:
93
+ case Property::LeftPercent:
94
+ case Property::Overflow:
95
+ case Property::OverflowX:
96
+ case Property::OverflowY:
97
+ case Property::FontId:
98
+ case Property::FontSize:
99
+ case Property::FontWeight:
100
+ case Property::LineHeight:
101
+ case Property::WhiteSpace:
102
+ case Property::TextOverflow:
103
+ case Property::ImageId:
104
+ case Property::ImageFit:
105
+ return true;
106
+ default:
107
+ return false;
108
+ }
109
+ }
110
+
111
+ bool isPaintProperty(Property prop)
112
+ {
113
+ return DisplayInvalidation::rebuildsNodeDisplayCommands(prop) && !isTransformProperty(prop);
114
+ }
115
+
116
+ struct ScopedRefreshStat
117
+ {
118
+ std::int64_t start;
119
+ std::int64_t &slot;
120
+
121
+ explicit ScopedRefreshStat(std::int64_t &slot)
122
+ : start(refreshPerfNowUs()), slot(slot)
123
+ {
124
+ }
125
+
126
+ ~ScopedRefreshStat()
127
+ {
128
+ slot += refreshPerfNowUs() - start;
129
+ }
130
+ };
131
+
132
+ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordInline)
133
+ {
134
+ auto &perf = refreshPerfStatsMutable();
135
+ ScopedRefreshStat timer(perf.treeSetStyleUs);
136
+ perf.treeSetStyleCalls++;
137
+ auto &state = treeState();
138
+ if (node < 0 || node >= state.nodeCount) return;
139
+ // Record every authored inline property — including Left/Top — so it survives a
140
+ // class-change / style recompute. resetStyleForClassRecompute() rebuilds a node's
141
+ // style from its class rules + inlineStyles, so anything NOT recorded here is lost
142
+ // on the next recompute. A static template that authors inline left/top exactly
143
+ // once (e.g. an absolutely-positioned board: `style={{ left: BOARD_X, top: BOARD_Y }}`)
144
+ // depends on this: previously Left/Top were skipped as a perf shortcut for the
145
+ // reactive keyed-list position path (~128 writes/frame in bouncing-balls), which
146
+ // pinned every statically-authored absolute element to (0,0) after the first
147
+ // recompute while width/height (which WERE recorded) survived. The keyed-list path
148
+ // re-applies its live left/top every frame, so a recompute that momentarily reverts
149
+ // to the last-recorded value self-corrects on the next frame; the only cost there is
150
+ // the per-write record.
151
+ // Per-app opt (GEA_EMBEDDED_SKIP_POSITION_INLINE_RECORD): the inline-style record
152
+ // exists only so authored styles survive a class-recompute. Apps whose Left/Top come
153
+ // exclusively from a reactive keyed-list (bouncing-balls: ~128 writes/frame) re-apply
154
+ // live position every frame, so a recompute self-corrects next frame — the record is
155
+ // pure waste (~384µs/frame here). Skip Left/Top recording for those apps ONLY; keep it
156
+ // for any app that authors static absolute left/top AND toggles classes.
157
+ #if GEA_EMBEDDED_SKIP_POSITION_INLINE_RECORD
158
+ if (recordInline && prop != Property::Left && prop != Property::Top)
159
+ #else
160
+ if (recordInline)
161
+ #endif
162
+ ensureRareData(node).inlineStyles.set(prop, value);
163
+ Node *n = &state.nodes[node];
164
+ int changed = 0;
165
+ int prevOpacity = -1;
166
+ // These previous-bg values feed ONLY the BackgroundColor solid-recolor fast path
167
+ // below (itself gated on prop == BackgroundColor). Reading them on every setStyle —
168
+ // including the 4 pooled rstyle() bg-gradient lookups — is pure waste for the common
169
+ // layout/paint writes (e.g. 128 left/top writes per frame in bouncing-balls = ~512
170
+ // wasted pooled reads). Gate them on the property.
171
+ const bool isBgColorChange = (prop == Property::BackgroundColor);
172
+ const style_color_t previousBgColor = isBgColorChange ? n->style.bg_color : style_color_t{};
173
+ const uint8_t previousHasBg = isBgColorChange ? n->style.has_bg : 0;
174
+ const uint8_t previousBgAlpha = isBgColorChange ? n->style.bg_alpha : 0;
175
+ const int8_t previousBgFill = isBgColorChange ? n->style.bg_fill : 0;
176
+ const uint8_t previousBgGradientHasMid = isBgColorChange ? rstyle(n->style).bg_gradient_has_mid : 0;
177
+ const uint8_t previousBgOverlayGradient = isBgColorChange ? rstyle(n->style).bg_overlay_gradient : 0;
178
+ const uint8_t previousBgRadialGradient = isBgColorChange ? rstyle(n->style).bg_radial_gradient : 0;
179
+ const uint8_t previousBgGridAxes = isBgColorChange ? rstyle(n->style).bg_grid_axes : 0;
180
+ switch (prop) {
181
+ case Property::Display:
182
+ // Any application of the `display` property is explicit authoring — record
183
+ // it so the inline-formatting heuristic treats e.g. `display:block` on a
184
+ // <span> as block-level (stacks) rather than its default inline behaviour.
185
+ if (!n->style.display_explicit) { n->style.display_explicit = 1; changed = 1; }
186
+ if (n->style.display != value) { n->style.display = value; changed = 1; }
187
+ break;
188
+ case Property::FlexDirection:
189
+ if (!n->style.flex_direction_explicit) {
190
+ n->style.flex_direction_explicit = 1;
191
+ changed = 1;
192
+ }
193
+ if (n->style.flex_direction != value) {
194
+ n->style.flex_direction = value;
195
+ changed = 1;
196
+ }
197
+ break;
198
+ case Property::FlexWrap: if (n->style.flex_wrap != value) { n->style.flex_wrap = value; changed = 1; } break;
199
+ case Property::JustifyContent: if (n->style.justify_content != value) { n->style.justify_content = value; changed = 1; } break;
200
+ case Property::AlignItems: if (n->style.align_items != value) { n->style.align_items = value; changed = 1; } break;
201
+ case Property::JustifyItems: if (n->style.justify_items != value) { n->style.justify_items = value; changed = 1; } break;
202
+ case Property::AlignContent: if (n->style.align_content != value) { n->style.align_content = value; changed = 1; } break;
203
+ case Property::AlignSelf: if (n->style.align_self != value) { n->style.align_self = value; changed = 1; } break;
204
+ case Property::Gap: if (n->style.gap != value) { n->style.gap = value; changed = 1; } break;
205
+ case Property::Width:
206
+ if (n->style.width != value || n->style.width_percent != kUnset) {
207
+ n->style.width = value;
208
+ n->style.width_percent = kUnset;
209
+ changed = 1;
210
+ }
211
+ break;
212
+ case Property::Height:
213
+ if (n->style.height != value || n->style.height_percent != kUnset) {
214
+ n->style.height = value;
215
+ n->style.height_percent = kUnset;
216
+ changed = 1;
217
+ }
218
+ break;
219
+ case Property::WidthPercent:
220
+ if (n->style.width_percent != value || n->style.width != kUnset) {
221
+ n->style.width_percent = value;
222
+ n->style.width = kUnset;
223
+ changed = 1;
224
+ }
225
+ break;
226
+ case Property::HeightPercent:
227
+ if (n->style.height_percent != value || n->style.height != kUnset) {
228
+ n->style.height_percent = value;
229
+ n->style.height = kUnset;
230
+ changed = 1;
231
+ }
232
+ break;
233
+ case Property::MinWidth: if (n->style.min_width != value) { n->style.min_width = value; changed = 1; } break;
234
+ case Property::MinHeight: if (n->style.min_height != value) { n->style.min_height = value; changed = 1; } break;
235
+ case Property::MaxWidth: if (n->style.max_width != value) { n->style.max_width = value; changed = 1; } break;
236
+ case Property::MaxHeight: if (n->style.max_height != value) { n->style.max_height = value; changed = 1; } break;
237
+ case Property::Flex: if (n->style.flex != value) { n->style.flex = value; changed = 1; } break;
238
+ case Property::FlexShrink: if (n->style.flex_shrink != value) { n->style.flex_shrink = value; changed = 1; } break;
239
+ case Property::FlexBasis: if (n->style.flex_basis != value) { n->style.flex_basis = value; changed = 1; } break;
240
+ case Property::PaddingTop: if (n->style.padding[0] != value) { n->style.padding[0] = value; changed = 1; } break;
241
+ case Property::PaddingRight: if (n->style.padding[1] != value) { n->style.padding[1] = value; changed = 1; } break;
242
+ case Property::PaddingBottom: if (n->style.padding[2] != value) { n->style.padding[2] = value; changed = 1; } break;
243
+ case Property::PaddingLeft: if (n->style.padding[3] != value) { n->style.padding[3] = value; changed = 1; } break;
244
+ case Property::MarginTop: if (n->style.margin[0] != value) { n->style.margin[0] = value; changed = 1; } break;
245
+ case Property::MarginRight: if (n->style.margin[1] != value) { n->style.margin[1] = value; changed = 1; } break;
246
+ case Property::MarginBottom: if (n->style.margin[2] != value) { n->style.margin[2] = value; changed = 1; } break;
247
+ case Property::MarginLeft: if (n->style.margin[3] != value) { n->style.margin[3] = value; changed = 1; } break;
248
+ case Property::Position: if (n->style.position != value) { n->style.position = value; changed = 1; } break;
249
+ case Property::Top:
250
+ if (n->style.pos_offsets[0] != value || n->style.pos_offset_percent[0] != kUnset) {
251
+ n->style.pos_offsets[0] = value;
252
+ n->style.pos_offset_percent[0] = kUnset;
253
+ changed = 1;
254
+ }
255
+ break;
256
+ case Property::Right:
257
+ if (n->style.pos_offsets[1] != value || n->style.pos_offset_percent[1] != kUnset) {
258
+ n->style.pos_offsets[1] = value;
259
+ n->style.pos_offset_percent[1] = kUnset;
260
+ changed = 1;
261
+ }
262
+ break;
263
+ case Property::Bottom:
264
+ if (n->style.pos_offsets[2] != value || n->style.pos_offset_percent[2] != kUnset) {
265
+ n->style.pos_offsets[2] = value;
266
+ n->style.pos_offset_percent[2] = kUnset;
267
+ changed = 1;
268
+ }
269
+ break;
270
+ case Property::Left:
271
+ if (n->style.pos_offsets[3] != value || n->style.pos_offset_percent[3] != kUnset) {
272
+ n->style.pos_offsets[3] = value;
273
+ n->style.pos_offset_percent[3] = kUnset;
274
+ changed = 1;
275
+ }
276
+ break;
277
+ case Property::TopPercent:
278
+ if (n->style.pos_offset_percent[0] != value || n->style.pos_offsets[0] != kUnset) {
279
+ n->style.pos_offset_percent[0] = value;
280
+ n->style.pos_offsets[0] = kUnset;
281
+ changed = 1;
282
+ }
283
+ break;
284
+ case Property::RightPercent:
285
+ if (n->style.pos_offset_percent[1] != value || n->style.pos_offsets[1] != kUnset) {
286
+ n->style.pos_offset_percent[1] = value;
287
+ n->style.pos_offsets[1] = kUnset;
288
+ changed = 1;
289
+ }
290
+ break;
291
+ case Property::BottomPercent:
292
+ if (n->style.pos_offset_percent[2] != value || n->style.pos_offsets[2] != kUnset) {
293
+ n->style.pos_offset_percent[2] = value;
294
+ n->style.pos_offsets[2] = kUnset;
295
+ changed = 1;
296
+ }
297
+ break;
298
+ case Property::LeftPercent:
299
+ if (n->style.pos_offset_percent[3] != value || n->style.pos_offsets[3] != kUnset) {
300
+ n->style.pos_offset_percent[3] = value;
301
+ n->style.pos_offsets[3] = kUnset;
302
+ changed = 1;
303
+ }
304
+ break;
305
+ case Property::ZIndex: if (n->style.z_index != value) { n->style.z_index = value; changed = 1; } break;
306
+ case Property::BackgroundColor: {
307
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
308
+ if (n->style.bg_color != next) { n->style.bg_color = next; changed = 1; }
309
+ if (n->style.bg_alpha != 255) { n->style.bg_alpha = 255; changed = 1; }
310
+ if (n->style.bg_fill != 0) { n->style.bg_fill = 0; changed = 1; }
311
+ if (rstyle(n->style).bg_gradient_has_mid != 0) { rstyleMut(n->style).bg_gradient_has_mid = 0; changed = 1; }
312
+ if (rstyle(n->style).bg_overlay_gradient != 0) { rstyleMut(n->style).bg_overlay_gradient = 0; changed = 1; }
313
+ if (rstyle(n->style).bg_radial_gradient != 0) { rstyleMut(n->style).bg_radial_gradient = 0; changed = 1; }
314
+ if (rstyle(n->style).bg_grid_axes != 0) { rstyleMut(n->style).bg_grid_axes = 0; changed = 1; }
315
+ break;
316
+ }
317
+ case Property::HasBackground: if (n->style.has_bg != value) { n->style.has_bg = value; changed = 1; } break;
318
+ case Property::ActiveBackgroundColor: {
319
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
320
+ if (n->style.active_bg_color != next) { n->style.active_bg_color = next; changed = 1; }
321
+ break;
322
+ }
323
+ case Property::HasActiveBackground: if (n->style.has_active_bg != value) { n->style.has_active_bg = value; changed = 1; } break;
324
+ case Property::Color: {
325
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
326
+ if (n->style.text_color != next) { n->style.text_color = next; changed = 1; }
327
+ if (n->style.text_alpha != 255) { n->style.text_alpha = 255; changed = 1; }
328
+ break;
329
+ }
330
+ case Property::Opacity: {
331
+ uint8_t next = (uint8_t)value;
332
+ if (n->style.opacity != next) { prevOpacity = n->style.opacity; n->style.opacity = next; changed = 1; }
333
+ break;
334
+ }
335
+ case Property::BlinkInterval:
336
+ value = value > 0 ? value : 0;
337
+ if (n->style.blink_interval_ms != value) {
338
+ n->style.blink_interval_ms = value;
339
+ n->style.blink_started_ms = state.lastFrameMs;
340
+ n->style.blink_visible = 1;
341
+ changed = 1;
342
+ }
343
+ break;
344
+ case Property::BorderWidth: if (n->style.border_width != value) { n->style.border_width = value; changed = 1; } break;
345
+ case Property::BorderColor: {
346
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
347
+ if (n->style.border_color != next) { n->style.border_color = next; changed = 1; }
348
+ if (n->style.border_alpha != 255) { n->style.border_alpha = 255; changed = 1; }
349
+ break;
350
+ }
351
+ case Property::BorderTopWidth: if (rstyle(n->style).border_side_width[0] != value) { rstyleMut(n->style).border_side_width[0] = value; changed = 1; } break;
352
+ case Property::BorderRightWidth: if (rstyle(n->style).border_side_width[1] != value) { rstyleMut(n->style).border_side_width[1] = value; changed = 1; } break;
353
+ case Property::BorderBottomWidth: if (rstyle(n->style).border_side_width[2] != value) { rstyleMut(n->style).border_side_width[2] = value; changed = 1; } break;
354
+ case Property::BorderLeftWidth: if (rstyle(n->style).border_side_width[3] != value) { rstyleMut(n->style).border_side_width[3] = value; changed = 1; } break;
355
+ case Property::BorderTopColor: {
356
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
357
+ if (rstyle(n->style).border_side_color[0] != next) { rstyleMut(n->style).border_side_color[0] = next; changed = 1; }
358
+ if (rstyle(n->style).border_side_alpha[0] != 255) { rstyleMut(n->style).border_side_alpha[0] = 255; changed = 1; }
359
+ break;
360
+ }
361
+ case Property::BorderRightColor: {
362
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
363
+ if (rstyle(n->style).border_side_color[1] != next) { rstyleMut(n->style).border_side_color[1] = next; changed = 1; }
364
+ if (rstyle(n->style).border_side_alpha[1] != 255) { rstyleMut(n->style).border_side_alpha[1] = 255; changed = 1; }
365
+ break;
366
+ }
367
+ case Property::BorderBottomColor: {
368
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
369
+ if (rstyle(n->style).border_side_color[2] != next) { rstyleMut(n->style).border_side_color[2] = next; changed = 1; }
370
+ if (rstyle(n->style).border_side_alpha[2] != 255) { rstyleMut(n->style).border_side_alpha[2] = 255; changed = 1; }
371
+ break;
372
+ }
373
+ case Property::BorderLeftColor: {
374
+ style_color_t next = StyleValues::pixelFromStyleValue(value);
375
+ if (rstyle(n->style).border_side_color[3] != next) { rstyleMut(n->style).border_side_color[3] = next; changed = 1; }
376
+ if (rstyle(n->style).border_side_alpha[3] != 255) { rstyleMut(n->style).border_side_alpha[3] = 255; changed = 1; }
377
+ break;
378
+ }
379
+ case Property::BorderRadiusTopLeft:
380
+ if (n->style.border_radius[0] != value || n->style.border_radius_percent[0] != kUnset) {
381
+ n->style.border_radius[0] = value;
382
+ n->style.border_radius_percent[0] = kUnset;
383
+ changed = 1;
384
+ }
385
+ break;
386
+ case Property::BorderRadiusTopRight:
387
+ if (n->style.border_radius[1] != value || n->style.border_radius_percent[1] != kUnset) {
388
+ n->style.border_radius[1] = value;
389
+ n->style.border_radius_percent[1] = kUnset;
390
+ changed = 1;
391
+ }
392
+ break;
393
+ case Property::BorderRadiusBottomRight:
394
+ if (n->style.border_radius[2] != value || n->style.border_radius_percent[2] != kUnset) {
395
+ n->style.border_radius[2] = value;
396
+ n->style.border_radius_percent[2] = kUnset;
397
+ changed = 1;
398
+ }
399
+ break;
400
+ case Property::BorderRadiusBottomLeft:
401
+ if (n->style.border_radius[3] != value || n->style.border_radius_percent[3] != kUnset) {
402
+ n->style.border_radius[3] = value;
403
+ n->style.border_radius_percent[3] = kUnset;
404
+ changed = 1;
405
+ }
406
+ break;
407
+ case Property::BorderRadiusTopLeftPercent:
408
+ if (n->style.border_radius_percent[0] != value || n->style.border_radius[0] != 0) {
409
+ n->style.border_radius_percent[0] = value;
410
+ n->style.border_radius[0] = 0;
411
+ changed = 1;
412
+ }
413
+ break;
414
+ case Property::BorderRadiusTopRightPercent:
415
+ if (n->style.border_radius_percent[1] != value || n->style.border_radius[1] != 0) {
416
+ n->style.border_radius_percent[1] = value;
417
+ n->style.border_radius[1] = 0;
418
+ changed = 1;
419
+ }
420
+ break;
421
+ case Property::BorderRadiusBottomRightPercent:
422
+ if (n->style.border_radius_percent[2] != value || n->style.border_radius[2] != 0) {
423
+ n->style.border_radius_percent[2] = value;
424
+ n->style.border_radius[2] = 0;
425
+ changed = 1;
426
+ }
427
+ break;
428
+ case Property::BorderRadiusBottomLeftPercent:
429
+ if (n->style.border_radius_percent[3] != value || n->style.border_radius[3] != 0) {
430
+ n->style.border_radius_percent[3] = value;
431
+ n->style.border_radius[3] = 0;
432
+ changed = 1;
433
+ }
434
+ break;
435
+ case Property::FontId: if (n->style.font_id != value) { n->style.font_id = value; changed = 1; } break;
436
+ case Property::FontSize: if (n->style.font_size != value) { n->style.font_size = value; changed = 1; } break;
437
+ case Property::FontWeight: if (n->style.font_weight != value) { n->style.font_weight = value; changed = 1; } break;
438
+ case Property::LineHeight: if (n->style.line_height != value) { n->style.line_height = value; changed = 1; } break;
439
+ case Property::TextAlign: if (n->style.text_align != value) { n->style.text_align = value; changed = 1; } break;
440
+ case Property::TextDecoration: if (n->style.text_decoration != value) { n->style.text_decoration = value; changed = 1; } break;
441
+ case Property::TextTransform: if (n->style.text_transform != value) { n->style.text_transform = value; changed = 1; } break;
442
+ case Property::WhiteSpace: if (n->style.white_space != static_cast<int8_t>(value)) { n->style.white_space = static_cast<int8_t>(value); changed = 1; } break;
443
+ case Property::TextOverflow: if (n->style.text_overflow != static_cast<int8_t>(value)) { n->style.text_overflow = static_cast<int8_t>(value); changed = 1; } break;
444
+ case Property::Backface: if (n->style.backface_hidden != static_cast<int8_t>(value)) { n->style.backface_hidden = static_cast<int8_t>(value); changed = 1; } break;
445
+ case Property::PointerEvents: if (n->style.pointer_events != static_cast<int8_t>(value)) { n->style.pointer_events = static_cast<int8_t>(value); changed = 1; } break;
446
+ case Property::Overflow: {
447
+ const int8_t next = static_cast<int8_t>(value);
448
+ if (n->style.overflow != next || n->style.overflow_x != next || n->style.overflow_y != next) {
449
+ n->style.overflow = next;
450
+ n->style.overflow_x = next;
451
+ n->style.overflow_y = next;
452
+ changed = 1;
453
+ }
454
+ break;
455
+ }
456
+ case Property::OverflowX: {
457
+ const int8_t next = static_cast<int8_t>(value);
458
+ const int8_t aggregate = aggregateOverflow(next, n->style.overflow_y);
459
+ if (n->style.overflow_x != next || n->style.overflow != aggregate) {
460
+ n->style.overflow_x = next;
461
+ n->style.overflow = aggregate;
462
+ changed = 1;
463
+ }
464
+ break;
465
+ }
466
+ case Property::OverflowY: {
467
+ const int8_t next = static_cast<int8_t>(value);
468
+ const int8_t aggregate = aggregateOverflow(n->style.overflow_x, next);
469
+ if (n->style.overflow_y != next || n->style.overflow != aggregate) {
470
+ n->style.overflow_y = next;
471
+ n->style.overflow = aggregate;
472
+ changed = 1;
473
+ }
474
+ break;
475
+ }
476
+ case Property::MaskRightFadeWidth: {
477
+ const int16_t next = static_cast<int16_t>(value < 0 ? 0 : value > 32767 ? 32767 : value);
478
+ if (n->style.mask_right_fade_width != next) {
479
+ n->style.mask_right_fade_width = next;
480
+ changed = 1;
481
+ }
482
+ break;
483
+ }
484
+ case Property::ImageId: if (n->image_id != value) { n->image_id = value; changed = 1; } break;
485
+ case Property::ImageFit: if (n->style.image_fit != value) { n->style.image_fit = value; changed = 1; } break;
486
+ case Property::TransformRotate:
487
+ if (rstyle(n->style).transform_rotate != value) {
488
+ rstyleMut(n->style).transform_rotate = value;
489
+ changed = 1;
490
+ }
491
+ break;
492
+ case Property::TransformRotateX: if (rstyle(n->style).transform_rotate_x != value) { rstyleMut(n->style).transform_rotate_x = value; changed = 1; } break;
493
+ case Property::TransformRotateY: if (rstyle(n->style).transform_rotate_y != value) { rstyleMut(n->style).transform_rotate_y = value; changed = 1; } break;
494
+ case Property::TransformTranslateX: if (rstyle(n->style).transform_translate_x != value) { rstyleMut(n->style).transform_translate_x = value; changed = 1; } break;
495
+ case Property::TransformTranslateY: if (rstyle(n->style).transform_translate_y != value) { rstyleMut(n->style).transform_translate_y = value; changed = 1; } break;
496
+ case Property::TransformTranslateZ: if (rstyle(n->style).transform_translate_z != value) { rstyleMut(n->style).transform_translate_z = value; changed = 1; } break;
497
+ case Property::TransformTranslateXPercent: if (rstyle(n->style).transform_translate_x_percent != value) { rstyleMut(n->style).transform_translate_x_percent = value; changed = 1; } break;
498
+ case Property::TransformTranslateYPercent: if (rstyle(n->style).transform_translate_y_percent != value) { rstyleMut(n->style).transform_translate_y_percent = value; changed = 1; } break;
499
+ case Property::TransformScaleX: if (rstyle(n->style).transform_scale_x != value) { rstyleMut(n->style).transform_scale_x = value; changed = 1; } break;
500
+ case Property::TransformScaleY: if (rstyle(n->style).transform_scale_y != value) { rstyleMut(n->style).transform_scale_y = value; changed = 1; } break;
501
+ case Property::TransformOriginX: if (rstyle(n->style).transform_origin_x != value) { rstyleMut(n->style).transform_origin_x = value; changed = 1; } break;
502
+ case Property::TransformOriginY: if (rstyle(n->style).transform_origin_y != value) { rstyleMut(n->style).transform_origin_y = value; changed = 1; } break;
503
+ case Property::Perspective: if (rstyle(n->style).perspective != value) { rstyleMut(n->style).perspective = value; changed = 1; } break;
504
+ case Property::PerspectiveOriginX: if (rstyle(n->style).perspective_origin_x != value) { rstyleMut(n->style).perspective_origin_x = value; changed = 1; } break;
505
+ case Property::PerspectiveOriginY: if (rstyle(n->style).perspective_origin_y != value) { rstyleMut(n->style).perspective_origin_y = value; changed = 1; } break;
506
+ case Property::FilterBlur: if (rstyle(n->style).filter_blur_radius != value) { rstyleMut(n->style).filter_blur_radius = value; changed = 1; } break;
507
+ case Property::BoxShadowInset: {
508
+ const uint8_t next = value != 0 ? 1 : 0;
509
+ if (rstyle(n->style).box_shadow_inset != next) { rstyleMut(n->style).box_shadow_inset = next; changed = 1; }
510
+ break;
511
+ }
512
+ case Property::BoxShadowOffsetX: if (rstyle(n->style).box_shadow_offset_x != value) { rstyleMut(n->style).box_shadow_offset_x = value; changed = 1; } break;
513
+ case Property::BoxShadowOffsetY: if (rstyle(n->style).box_shadow_offset_y != value) { rstyleMut(n->style).box_shadow_offset_y = value; changed = 1; } break;
514
+ case Property::BoxShadowBlur: if (rstyle(n->style).box_shadow_blur_radius != value) { rstyleMut(n->style).box_shadow_blur_radius = value; changed = 1; } break;
515
+ case Property::BoxShadowSpread: if (rstyle(n->style).box_shadow_spread != value) { rstyleMut(n->style).box_shadow_spread = value; changed = 1; } break;
516
+ case Property::BoxShadowColor: {
517
+ const style_color_t next = StyleValues::pixelFromStyleValue(value);
518
+ if (rstyle(n->style).box_shadow_color != next) { rstyleMut(n->style).box_shadow_color = next; changed = 1; }
519
+ break;
520
+ }
521
+ case Property::BoxShadowAlpha: {
522
+ const uint8_t next = static_cast<uint8_t>(value < 0 ? 0 : value > 255 ? 255 : value);
523
+ if (rstyle(n->style).box_shadow_alpha != next) { rstyleMut(n->style).box_shadow_alpha = next; changed = 1; }
524
+ break;
525
+ }
526
+ default:
527
+ perf.treeSetStyleNoop++;
528
+ return;
529
+ }
530
+ if (!changed) {
531
+ perf.treeSetStyleNoop++;
532
+ return;
533
+ }
534
+ perf.treeSetStyleChanged++;
535
+ if (isLayoutProperty(prop))
536
+ perf.treeSetStyleLayoutChanged++;
537
+ if (isTransformProperty(prop))
538
+ perf.treeSetStyleTransformChanged++;
539
+ else if (isPaintProperty(prop))
540
+ perf.treeSetStylePaintChanged++;
541
+ if (state.styleInvalidationSuppressionDepth > 0) return;
542
+ if (!nodeParticipatesInMountedTree(state, node)) return;
543
+ // An ImageId (src) swap on an element with a FIXED CSS display box (explicit
544
+ // width+height — e.g. a forecast row's 24x20 icon re-pointed at a different icon
545
+ // every data refresh) is PAINT-ONLY: the layout box is the styled box regardless
546
+ // of the new image's intrinsic size, so no reflow and no sibling movement. Patch
547
+ // just this node's BlitImage command in place and repaint its box; DON'T set
548
+ // layout_dirty or displayListDirty (ImageId is otherwise treated as a layout
549
+ // property, which would force a full relayout + full display-list rebuild + a
550
+ // full-screen-coalesced re-raster — measured as the bulk of a ~350ms weather city
551
+ // switch's 18 icon swaps). An auto-sized <img> still falls through to the full
552
+ // path below, since its intrinsic size can move layout.
553
+ if (prop == Property::ImageId) {
554
+ const bool fixedBox =
555
+ (n->style.width != kUnset || n->style.width_percent != kUnset) &&
556
+ (n->style.height != kUnset || n->style.height_percent != kUnset);
557
+ if (fixedBox) {
558
+ n->render.dirty = 1;
559
+ n->render.non_scroll_dirty = 1;
560
+ tree.markNodeDisplayCommandsDirty(node);
561
+ return;
562
+ }
563
+ }
564
+ if (prop == Property::BackgroundColor &&
565
+ previousHasBg &&
566
+ previousBgAlpha == 255 &&
567
+ previousBgFill == 0 &&
568
+ previousBgGradientHasMid == 0 &&
569
+ previousBgOverlayGradient == 0 &&
570
+ previousBgRadialGradient == 0 &&
571
+ previousBgGridAxes == 0 &&
572
+ n->style.has_bg &&
573
+ n->style.bg_alpha == 255 &&
574
+ n->style.bg_fill == 0 &&
575
+ rstyle(n->style).bg_gradient_has_mid == 0 &&
576
+ rstyle(n->style).bg_overlay_gradient == 0 &&
577
+ rstyle(n->style).bg_radial_gradient == 0 &&
578
+ rstyle(n->style).bg_grid_axes == 0 &&
579
+ previousBgColor != n->style.bg_color) {
580
+ n->render.bg_recolor_pending = 1;
581
+ n->render.bg_recolor_from = previousBgColor;
582
+ n->render.bg_recolor_to = n->style.bg_color;
583
+ }
584
+ n->render.dirty = 1;
585
+ // Paint-only properties (background, colors, shadows, ...) repaint in
586
+ // place: geometry is untouched, so they don't demand a relayout pass.
587
+ // Layout and transform properties keep the conservative marking.
588
+ if (isLayoutProperty(prop) || isTransformProperty(prop))
589
+ n->render.layout_dirty = 1;
590
+ n->render.non_scroll_dirty = 1;
591
+ if (isTransformProperty(prop)) {
592
+ n->render.transform_dirty = 1;
593
+ state.transformScanSerial = ~0ull;
594
+ state.transformScanValid = false; // a transform was added/changed → drop durable no-transform cache
595
+ }
596
+ if (DisplayInvalidation::rebuildsNodeDisplayCommands(prop)) {
597
+ const bool stayLocal = DisplayInvalidation::nodeDisplayChangeCanStayLocal(node);
598
+ bool forceFull = false;
599
+ if (prop == Property::Display) {
600
+ forceFull = !stayLocal;
601
+ } else if (prop == Property::Opacity) {
602
+ // Partial→partial fade: the SetAlpha scope already exists on both
603
+ // sides (opacity 0 still records a scope), so patch its value in place
604
+ // and keep the display list — no rebuild, no displayListDirty. The
605
+ // full per-rect replay path (tree_render) replays the scope in order,
606
+ // so the patched alpha applies correctly. (The incremental
607
+ // direct-replay path can't use this: it replays only a node's
608
+ // [drawStart,drawEnd], which excludes the scope — which is why
609
+ // canReplayDirectDirtyRegions still bails and we fall to the safe
610
+ // full-per-rect replay. The record stays incremental either way.)
611
+ if (stayLocal && prevOpacity < 255 && n->style.opacity < 255 &&
612
+ DisplayList::instance().patchNodeAlpha(node, static_cast<uint8_t>(n->style.opacity)))
613
+ return;
614
+ // Crossing the 255 boundary (scope appears/disappears) or a non-leaf:
615
+ // a leaf toggling strictly 0↔255 re-records locally; otherwise rebuild.
616
+ const bool toggleOnly = (prevOpacity == 0 || prevOpacity == 255) &&
617
+ (n->style.opacity == 0 || n->style.opacity == 255);
618
+ forceFull = !stayLocal || !toggleOnly;
619
+ } else if (prop == Property::MaskRightFadeWidth ||
620
+ prop == Property::FilterBlur ||
621
+ prop == Property::BoxShadowInset ||
622
+ prop == Property::BoxShadowOffsetX ||
623
+ prop == Property::BoxShadowOffsetY ||
624
+ prop == Property::BoxShadowBlur ||
625
+ prop == Property::BoxShadowSpread ||
626
+ prop == Property::BoxShadowColor ||
627
+ prop == Property::BoxShadowAlpha) {
628
+ forceFull = true;
629
+ }
630
+ if (forceFull) {
631
+ // A partial-opacity change only alters this node's own pixels — no
632
+ // reflow, no draw-order change — so the rebuilt list can be replayed
633
+ // over just the dirty-node region (content-dirty skips the
634
+ // full-viewport repaint). Display toggles (visibility/order) and
635
+ // filter/box-shadow (pixel spillover past the node box) keep the
636
+ // conservative full repaint.
637
+ if (prop == Property::Opacity)
638
+ tree.markDisplayListContentDirty();
639
+ else
640
+ tree.markDisplayListDirty();
641
+ } else {
642
+ tree.markNodeDisplayCommandsDirty(node);
643
+ }
644
+ } else if (!DisplayInvalidation::retainsDisplayCommands(prop)) {
645
+ // An absolute, childless leaf changing size is out of flow: no sibling
646
+ // reflow, no draw-order change. Mark only this node's commands dirty (so
647
+ // it re-records at the new size) and let AbsoluteLeafRefresh reconcile
648
+ // layout.{width,height} from style — no displayListDirty, so the display
649
+ // list stays keepable and only this node re-records (the static text
650
+ // labels are NOT re-recorded). Every other size/layout/z-index change
651
+ // reflows or reorders → full rebuild.
652
+ const bool absLeafSize = (prop == Property::Width || prop == Property::Height) &&
653
+ n->style.position == 1 && n->first_child < 0 && n->type != NodeType::Text;
654
+ if (absLeafSize)
655
+ tree.markNodeDisplayCommandsDirty(node);
656
+ else
657
+ tree.markDisplayListDirty();
658
+ }
659
+ }
660
+
661
+ } // namespace
662
+
663
+ void Tree::setStyle(int node, Property prop, int value)
664
+ {
665
+ setStyleValue(*this, node, prop, value, true);
666
+ }
667
+
668
+ void Tree::setDefaultStyle(int node, Property prop, int value)
669
+ {
670
+ auto &state = treeState();
671
+ if (node < 0 || node >= state.nodeCount) return;
672
+ ensureRareData(node).defaultStyles.set(prop, value);
673
+ StyleSheet::instance().recomputeSubtree(node);
674
+ }
675
+
676
+ void Tree::setStyleFromClass(int node, Property prop, int value)
677
+ {
678
+ setStyleValue(*this, node, prop, value, false);
679
+ }
680
+
681
+ void Tree::resetStyleForClassRecompute(int node)
682
+ {
683
+ auto &state = treeState();
684
+ if (node < 0 || node >= state.nodeCount) return;
685
+
686
+ Node defaults;
687
+ NodeLifecycle::init(&defaults, state.nodes[node].type);
688
+ state.nodes[node].style = defaults.style;
689
+ state.nodes[node].image_id = defaults.image_id;
690
+ if (state.styleInvalidationSuppressionDepth > 0) return;
691
+ if (!nodeParticipatesInMountedTree(state, node)) return;
692
+ state.nodes[node].render.dirty = 1;
693
+ state.nodes[node].render.layout_dirty = 1;
694
+ state.nodes[node].render.non_scroll_dirty = 1;
695
+ markDisplayListDirty();
696
+ }
697
+
698
+ } // namespace gea::embedded::ui