@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/tree_state.h CHANGED
@@ -10,12 +10,13 @@
10
10
  #include <cstddef>
11
11
  #include <cstdint>
12
12
  #include <string>
13
+ #include <memory>
13
14
  #include <vector>
14
15
 
15
16
  namespace gea::embedded::ui {
16
17
 
17
18
  struct NodeClassList {
18
- static constexpr std::uint8_t kInlineTokenCount = 4;
19
+ static constexpr std::uint8_t kInlineTokenCount = GEA_UI_CLASS_INLINE_TOKENS;
19
20
  static constexpr std::uint16_t kNoOverflow = 0xFFFFu;
20
21
 
21
22
  CssAtomId inlineTokens[kInlineTokenCount]{};
@@ -50,13 +51,8 @@ struct NodeStyleOverride {
50
51
  };
51
52
 
52
53
  struct NodeStyleOverrideStore {
53
- static constexpr std::uint8_t kInlineCount = 4;
54
- NodeStyleOverride inlineValues[kInlineCount]{};
55
- NodeStyleOverride *spillValues = nullptr;
56
- std::size_t spillCount = 0;
57
- std::size_t spillCapacity = 0;
58
- std::uint8_t inlineCount = 0;
59
- bool spilled = false;
54
+ struct Block;
55
+ Block *block = nullptr;
60
56
 
61
57
  NodeStyleOverrideStore() = default;
62
58
  NodeStyleOverrideStore(const NodeStyleOverrideStore &other);
@@ -67,25 +63,69 @@ struct NodeStyleOverrideStore {
67
63
 
68
64
  void clear();
69
65
  void set(Property property, int value);
66
+ void setCssPixels(Property property, float value);
67
+ bool getCssPixels(Property property, float &value) const;
70
68
  bool remove(Property property);
71
- std::size_t size() const { return spilled ? spillCount : inlineCount; }
69
+ std::size_t size() const;
72
70
  bool empty() const { return size() == 0; }
73
71
  const NodeStyleOverride &at(std::size_t index) const;
74
72
  };
75
73
 
74
+ // CSS ::first-line painting is uncommon and line fragments are useful only
75
+ // for nodes inside a block with a first-line background. Keep this metadata in
76
+ // the node's rare allocation instead of charging every Node for it.
77
+ struct FirstLineBackground {
78
+ style_color_t color = 0;
79
+ std::uint8_t alpha = 0;
80
+ bool hasColor = false;
81
+ std::int16_t lineY = 0;
82
+ std::int16_t lineHeight = 0;
83
+ std::int16_t lineContextNode = -1;
84
+ bool lineValid = false;
85
+ };
86
+
87
+ struct FirstLineFragment {
88
+ std::int16_t x = 0;
89
+ std::int16_t y = 0;
90
+ std::int16_t width = 0;
91
+ std::int16_t height = 0;
92
+ std::int16_t contextNode = -1;
93
+ bool valid = false;
94
+ };
95
+
96
+ struct InlineStaticPosition {
97
+ std::int16_t x = 0;
98
+ std::int16_t y = 0;
99
+ bool continuationLine = false;
100
+ bool valid = false;
101
+ };
102
+
76
103
  struct NodeCustomProperty {
77
104
  CssAtomId nameId = kInvalidCssAtom;
78
- std::string value;
79
105
  CssAtomId valueAtom = kInvalidCssAtom;
80
- std::int32_t colorStyle = 0;
81
- std::int32_t colorNative = 0;
106
+ // Most values already live in the atom table: alias its stable immutable
107
+ // string without a control block. A full atom table uses owned storage.
108
+ std::shared_ptr<const std::string> value{std::shared_ptr<const std::string>{}, &cssAtomString(kInvalidCssAtom)};
109
+ // Both caches hold packed target colors: RGB565/gray fit 16 bits;
110
+ // full-color targets retain all 32 bits and their signed carrier.
111
+ using ColorValue = std::conditional_t<GEA_PIXEL_FORMAT_IS_8888, std::int32_t, std::uint16_t>;
112
+ ColorValue colorStyle = 0;
113
+ ColorValue colorNative = 0;
114
+ #if GEA_CSS_CUSTOM_PROPERTY_LENGTHS
82
115
  float lengthValue = 0.0f;
116
+ #else
117
+ static constexpr float lengthValue = 0.0f;
118
+ #endif
83
119
  std::uint8_t colorAlpha = 255;
120
+ #if GEA_CSS_CUSTOM_PROPERTY_LENGTHS
84
121
  std::uint8_t lengthUnit = 0;
122
+ #else
123
+ static constexpr std::uint8_t lengthUnit = 0;
124
+ #endif
85
125
  std::uint8_t flags = 0;
86
126
 
87
127
  bool hasColor() const { return (flags & 1u) != 0; }
88
- bool hasLength() const { return (flags & 2u) != 0; }
128
+ bool hasLength() const { return GEA_CSS_CUSTOM_PROPERTY_LENGTHS && (flags & 2u) != 0; }
89
129
  };
90
130
 
91
131
  struct NodeCustomPropertyStore {
@@ -126,22 +166,66 @@ struct VirtualListNodeState {
126
166
  // properties, and virtual-list windowing state. Stored in a shared pool and
127
167
  // referenced by a single int16 handle on the node (Node::rare_data) instead of
128
168
  // inlining a fixed slot on every node, so a plain styled node allocates nothing.
169
+ struct GridTrackLayout {
170
+ std::vector<int> columnStart, columnEnd, rowStart, rowEnd;
171
+ int columnOrigin = 0, rowOrigin = 0;
172
+ };
173
+
129
174
  struct NodeRareData {
175
+ // Reuse the listener record's tail padding for inline-position metadata.
176
+ // Both members remain ordinary embedded fields with fixed-offset access.
177
+ [[no_unique_address]] NodeEventListeners listeners;
178
+ InlineStaticPosition inlineStaticPosition;
130
179
  NodeAttributeStore attributes;
131
- NodeEventListeners listeners;
132
180
  NodeCustomPropertyStore customProperties;
181
+ // Authored inline values survive rebuilding the computed custom-property map.
182
+ NodeCustomPropertyStore inlineCustomProperties;
133
183
  NodeStyleOverrideStore defaultStyles;
134
184
  NodeStyleOverrideStore inlineStyles;
135
- VirtualListNodeState virtualList;
185
+ #if GEA_CSS_GRID
186
+ CssAtomId inlineGridTemplates[2] = {kInvalidCssAtom, kInvalidCssAtom};
187
+ uint8_t inlineGridShorthandMask = 0;
188
+ std::unique_ptr<GridTrackLayout> gridLayout;
189
+ #endif
190
+ #if GEA_CSS_SCROLLING
191
+ std::unique_ptr<VirtualListNodeState> virtualList;
192
+ VirtualListNodeState &ensureVirtualList()
193
+ {
194
+ if (!virtualList) virtualList = std::make_unique<VirtualListNodeState>();
195
+ return *virtualList;
196
+ }
197
+ #else
198
+ static constexpr const VirtualListNodeState *virtualList = nullptr;
199
+ #endif
200
+ #if GEA_CSS_FIRST_LINE
201
+ FirstLineBackground firstLineBackground;
202
+ FirstLineFragment firstLineFragment;
203
+ #else
204
+ inline static constexpr FirstLineBackground firstLineBackground{};
205
+ inline static constexpr FirstLineFragment firstLineFragment{};
206
+ #endif
136
207
 
137
208
  void clear()
138
209
  {
139
210
  attributes.clear();
140
211
  listeners.clear();
141
212
  customProperties.clear();
213
+ inlineCustomProperties.clear();
142
214
  defaultStyles.clear();
143
215
  inlineStyles.clear();
144
- virtualList = VirtualListNodeState{};
216
+ #if GEA_CSS_GRID
217
+ inlineGridTemplates[0] = inlineGridTemplates[1] = kInvalidCssAtom;
218
+ inlineGridShorthandMask = 0;
219
+ gridLayout.reset();
220
+ #endif
221
+ #if GEA_CSS_SCROLLING
222
+ virtualList.reset();
223
+ #endif
224
+ #if GEA_CSS_FIRST_LINE
225
+ firstLineBackground = FirstLineBackground{};
226
+ firstLineFragment = FirstLineFragment{};
227
+ #endif
228
+ inlineStaticPosition = InlineStaticPosition{};
145
229
  }
146
230
  };
147
231
 
@@ -162,15 +246,23 @@ struct TreeState {
162
246
  int mountedRoot = -1;
163
247
  int mountedWidth = 0;
164
248
  int mountedHeight = 0;
249
+ // Conservative fast-out for fixed-descendant clip/scroll checks. Set on
250
+ // first use and retained until tree state is reset.
251
+ bool fixedPositionUsed = false;
165
252
  int lastFrameMs = 0;
166
253
  // Monotonic counter bumped on every mount()/refresh() — i.e. whenever the
167
254
  // reactive tree is (re)built. Lets native renderers (macOS) skip an entire
168
255
  // re-sync when the tree hasn't changed since the last frame, instead of
169
256
  // diffing the whole view tree at 60Hz while idle.
170
257
  uint64_t refreshSerial = 0;
258
+ #if GEA_CSS_SCROLLING
171
259
  uint64_t scrollDirtyNodes[kScrollDirtyWordCount]{};
172
260
  bool scrollDirtyAny = false;
173
261
  int pendingScrollIntoViewNode = -1;
262
+ #else
263
+ static constexpr bool scrollDirtyAny = false;
264
+ static constexpr int pendingScrollIntoViewNode = -1;
265
+ #endif
174
266
  bool inputTickRequired = false;
175
267
  bool displayListDirty = true;
176
268
  // When a rebuild is pending (displayListDirty), this says whether it may have
@@ -209,6 +301,7 @@ struct TreeState {
209
301
  // ViewGeometry::anyTransformPresent(). When false, the per-node ancestor-chain
210
302
  // transform walks short-circuit to O(1) — non-3D trees (the common case) pay
211
303
  // nothing for the 3D machinery. Defaults coax a recompute before first use.
304
+ #if GEA_CSS_TRANSFORMS
212
305
  uint64_t transformScanSerial = ~0ull;
213
306
  bool transformPresent = true;
214
307
  // Durable validity for a cached `transformPresent == false`. refreshSerial bumps
@@ -220,14 +313,26 @@ struct TreeState {
220
313
  // old mode-gate regression was that re-scan, not the gate itself). A cached `true`
221
314
  // is NOT held here — it still re-scans per refreshSerial so a removal is seen.
222
315
  bool transformScanValid = false;
316
+ #else
317
+ static constexpr uint64_t transformScanSerial = ~0ull;
318
+ static constexpr bool transformPresent = false;
319
+ static constexpr bool transformScanValid = true;
320
+ #endif
223
321
 
224
322
  // Focus + caret state for `<input>` elements. -1 means no input is
225
323
  // focused. caretLastFlipMs/caretVisible drive the blink animation —
226
324
  // consulted by InputRenderer::record on the pixel target. The macOS
227
325
  // renderer ignores these (NSResponder owns its own caret).
326
+ #if GEA_UI_INPUT_NODES
228
327
  int activeInputId = -1;
229
328
  int caretLastFlipMs = 0;
230
329
  bool caretVisible = true;
330
+ #else
331
+ static constexpr int activeInputId = -1;
332
+ static constexpr int caretLastFlipMs = 0;
333
+ static constexpr bool caretVisible = false;
334
+ #endif
335
+ int hoveredNodeId = -1;
231
336
  };
232
337
 
233
338
  TreeState &treeState();