@geastack/engine 0.1.6 → 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.
package/ui/text.cpp CHANGED
@@ -1592,8 +1592,17 @@ void Tree::setText(int node, const char *text)
1592
1592
  // fixed-width label appear equally wide. A shrinking update such as
1593
1593
  // "San Francisco" -> "Lisbon" then dirtied only the new, shorter run (or even a
1594
1594
  // sliver at the box edge), leaving the old trailing glyphs on the physical panel.
1595
- const bool gid_canPartial = gid_singleLine && target.style.white_space == 1 &&
1595
+ const bool gid_hadPartial = target.render.text_partial_dirty;
1596
+ const int gid_previousX0 = gid_hadPartial ? target.render.text_dirty.x0 : 0;
1597
+ const int gid_previousX1 = gid_hadPartial ? target.render.text_dirty.x1 : 0;
1598
+ const bool gid_canPartial = (!target.render.dirty || gid_hadPartial) &&
1599
+ !target.render.bg_recolor_pending && gid_singleLine && target.style.white_space == 1 &&
1596
1600
  target.style.text_align == 0 && gid_prefix < gid_newLen;
1601
+ // Text and recolor shortcuts share their payload. Other pending paint
1602
+ // changes require a full node repaint, while consecutive text runs union
1603
+ // their extents so none of the earlier changes is forgotten.
1604
+ target.render.bg_recolor_pending = 0;
1605
+ target.render.text_partial_dirty = 0;
1597
1606
  int gid_preW = 0;
1598
1607
  int gid_rightW = 0;
1599
1608
  if (gid_canPartial) {
@@ -1619,7 +1628,9 @@ void Tree::setText(int node, const char *text)
1619
1628
  const bool gid_hadLayoutDirty = target.render.layout_dirty != 0;
1620
1629
  target.render.dirty = 1;
1621
1630
  target.render.layout_dirty = 1;
1631
+ #if GEA_CSS_SCROLLING
1622
1632
  target.render.non_scroll_dirty = 1;
1633
+ #endif
1623
1634
  target.render.text_layout_stable = 0;
1624
1635
  markNodeDisplayCommandsDirty(node);
1625
1636
  // assign() past capacity reallocates and frees the old buffer, leaving any
@@ -1670,8 +1681,10 @@ void Tree::setText(int node, const char *text)
1670
1681
  if (gid_sameHeight && gid_canPartial) {
1671
1682
  const int gid_originX = target.layout.x + target.style.padding[3];
1672
1683
  constexpr int kTextDirtyPadPx = 4; // AA / glyph-overhang guard
1673
- target.render.text_dirty_x0 = static_cast<int16_t>(gid_originX + gid_preW - kTextDirtyPadPx);
1674
- target.render.text_dirty_x1 = static_cast<int16_t>(gid_originX + gid_rightW + kTextDirtyPadPx);
1684
+ const int x0 = gid_originX + gid_preW - kTextDirtyPadPx;
1685
+ const int x1 = gid_originX + gid_rightW + kTextDirtyPadPx;
1686
+ target.render.text_dirty.x0 = static_cast<int16_t>(gid_hadPartial ? std::min(gid_previousX0, x0) : x0);
1687
+ target.render.text_dirty.x1 = static_cast<int16_t>(gid_hadPartial ? std::max(gid_previousX1, x1) : x1);
1675
1688
  target.render.text_partial_dirty = 1;
1676
1689
  }
1677
1690
  }
@@ -1911,6 +1924,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
1911
1924
  const Node *n = &node;
1912
1925
  if (n->type != NodeType::Text || n->text.empty()) return;
1913
1926
 
1927
+ #if GEA_CSS_FIRST_LINE
1914
1928
  // A first-line background belongs to the inline fragment, not the block's
1915
1929
  // entire width. Layout records this run's first line box/advance only when an
1916
1930
  // ancestor has a resolved ::first-line background. Emit it before the text
@@ -1981,6 +1995,7 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
1981
1995
  }
1982
1996
 
1983
1997
 
1998
+ #endif
1984
1999
  int x = n->layout.x;
1985
2000
  int y = n->layout.y;
1986
2001
  int w = n->layout.width;
@@ -2122,7 +2137,12 @@ void GEA_TEXT_HOT_SRAM TextRenderer::record(const Node &node, uint8_t parentAlph
2122
2137
  usesRowLayout(n->style)) {
2123
2138
  const int contentH = h - boxInset(n->style, 0) - boxInset(n->style, 2);
2124
2139
  const int slack = contentH - paintMeasure.height;
2125
- const int alignment = usedAlignment(n->style.align_items, slack, (n->style.flex_wrap & 3) == 2);
2140
+ #if GEA_CSS_FLEX_WRAP
2141
+ const bool reverseCrossAxis = (n->style.flex_wrap & 3) == 2;
2142
+ #else
2143
+ constexpr bool reverseCrossAxis = false;
2144
+ #endif
2145
+ const int alignment = usedAlignment(n->style.align_items, slack, reverseCrossAxis);
2126
2146
  if (alignment == 1) drawY += slack / 2;
2127
2147
  else if (alignment == 2) drawY += slack;
2128
2148
  }
@@ -6,10 +6,11 @@
6
6
  #include "tree_internal.h"
7
7
  #include "tree_state.h"
8
8
 
9
+ #include <algorithm>
10
+ #include <new>
9
11
  #include <cstddef>
10
12
  #include <cstdio>
11
13
  #include <cstring>
12
- #include <deque>
13
14
  #include <utility>
14
15
  #include <vector>
15
16
 
@@ -154,12 +155,13 @@ bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event)
154
155
  // Cold/optional per-node state (currently event listeners) lives here instead
155
156
  // of a dense [kMaxNodes] array. A node holds an int16 handle (Node::rare_data,
156
157
  // -1 = none) into this pool; a block is allocated lazily the first time a node
157
- // needs one and returned to a free list when the node is reset. A std::deque
158
- // backs the pool because its element addresses are STABLE across growth — the
159
- // dispatcher holds a NodeRareData* across the (re-entrant) handler call, exactly
160
- // as the old fixed array allowed. The free list keeps it bounded and reused.
158
+ // needs one and returned to a free list when the node is reset. Owned records
159
+ // keep their addresses STABLE while the pointer table grows: the dispatcher
160
+ // retains NodeRareData* across re-entrant handlers. A direct pointer table also
161
+ // avoids deque's block arithmetic changing when record compaction crosses its
162
+ // block-size thresholds. The free list keeps allocations bounded and reused.
161
163
  namespace {
162
- std::deque<NodeRareData> g_rareDataPool;
164
+ std::vector<std::unique_ptr<NodeRareData>> g_rareDataPool;
163
165
  std::vector<int16_t> g_rareDataFreeList;
164
166
  } // namespace
165
167
 
@@ -167,16 +169,16 @@ NodeRareData &ensureRareData(int node)
167
169
  {
168
170
  auto &state = treeState();
169
171
  int16_t handle = state.nodes[node].rare_data;
170
- if (handle >= 0) return g_rareDataPool[static_cast<std::size_t>(handle)];
172
+ if (handle >= 0) return *g_rareDataPool[static_cast<std::size_t>(handle)];
171
173
  if (!g_rareDataFreeList.empty()) {
172
174
  handle = g_rareDataFreeList.back();
173
175
  g_rareDataFreeList.pop_back();
174
176
  } else {
175
177
  handle = static_cast<int16_t>(g_rareDataPool.size());
176
- g_rareDataPool.emplace_back();
178
+ g_rareDataPool.emplace_back(std::make_unique<NodeRareData>());
177
179
  }
178
180
  state.nodes[node].rare_data = handle;
179
- return g_rareDataPool[static_cast<std::size_t>(handle)];
181
+ return *g_rareDataPool[static_cast<std::size_t>(handle)];
180
182
  }
181
183
 
182
184
  NodeRareData *rareDataFor(int node)
@@ -184,7 +186,7 @@ NodeRareData *rareDataFor(int node)
184
186
  auto &state = treeState();
185
187
  if (node < 0 || node >= kMaxNodes) return nullptr;
186
188
  const int16_t handle = state.nodes[node].rare_data;
187
- return handle >= 0 ? &g_rareDataPool[static_cast<std::size_t>(handle)] : nullptr;
189
+ return handle >= 0 ? g_rareDataPool[static_cast<std::size_t>(handle)].get() : nullptr;
188
190
  }
189
191
 
190
192
  void releaseRareData(int node)
@@ -193,52 +195,115 @@ void releaseRareData(int node)
193
195
  if (node < 0 || node >= kMaxNodes) return;
194
196
  const int16_t handle = state.nodes[node].rare_data;
195
197
  if (handle < 0) return;
196
- g_rareDataPool[static_cast<std::size_t>(handle)].clear();
198
+ g_rareDataPool[static_cast<std::size_t>(handle)]->clear();
197
199
  g_rareDataFreeList.push_back(handle);
198
200
  state.nodes[node].rare_data = -1;
199
201
  }
200
202
 
203
+ void NodeAttributeDeleter::operator()(NodeAttributeEntry *entry) const
204
+ {
205
+ entry->~NodeAttributeEntry();
206
+ ::operator delete(entry);
207
+ }
208
+ NodeAttributePtr NodeAttributeEntry::create(const char *name, const char *value)
209
+ {
210
+ if (!value) value = "";
211
+ const auto nameBytes = std::min(std::strlen(name), std::size_t(kNodeAttributeNameMax - 1)) + 1;
212
+ const auto valueBytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
213
+ auto *entry = new (::operator new(sizeof(NodeAttributeEntry) + nameBytes + valueBytes)) NodeAttributeEntry;
214
+ entry->nameBytes = nameBytes;
215
+ entry->valueCapacity = valueBytes;
216
+ copyBounded(reinterpret_cast<char *>(entry + 1), nameBytes, name);
217
+ copyBounded(entry->value(), valueBytes, value);
218
+ return NodeAttributePtr(entry);
219
+ }
220
+
221
+ NodeAttributeStore::NodeAttributeStore(const NodeAttributeStore &other)
222
+ : pressId(other.pressId), pressValue(other.pressValue), idAtom(other.idAtom), count(other.count)
223
+ {
224
+ auto *tail = &values;
225
+ for (auto *entry = other.values.get(); entry; entry = entry->next.get()) {
226
+ *tail = NodeAttributeEntry::create(entry->name(), entry->value());
227
+ tail = &(*tail)->next;
228
+ }
229
+ }
230
+
231
+ NodeAttributeStore &NodeAttributeStore::operator=(const NodeAttributeStore &other)
232
+ {
233
+ if (this != &other) {
234
+ NodeAttributeStore copy(other);
235
+ *this = std::move(copy);
236
+ }
237
+ return *this;
238
+ }
239
+
240
+ NodeAttributeStore::NodeAttributeStore(NodeAttributeStore &&other) noexcept
241
+ {
242
+ *this = std::move(other);
243
+ }
244
+
245
+ NodeAttributeStore &NodeAttributeStore::operator=(NodeAttributeStore &&other) noexcept
246
+ {
247
+ if (this == &other) return *this;
248
+ values = std::move(other.values);
249
+ pressId = other.pressId;
250
+ pressValue = other.pressValue;
251
+ idAtom = other.idAtom;
252
+ count = other.count;
253
+ other.clear();
254
+ return *this;
255
+ }
256
+
201
257
  void NodeAttributeStore::clear()
202
258
  {
203
259
  pressId = -1;
204
260
  pressValue = -1;
205
261
  idAtom = kInvalidCssAtom;
206
262
  count = 0;
207
- for (auto &attr : values) {
208
- attr.name[0] = '\0';
209
- attr.value[0] = '\0';
210
- }
263
+ values.reset();
211
264
  }
212
265
 
213
266
  void NodeAttributeStore::set(const char *name, const char *value)
214
267
  {
215
- if (!name || name[0] == '\0') return;
268
+ if (!name || !*name) return;
269
+ if (!value) value = "";
216
270
  const bool isId = sameName(name, "id");
217
- for (uint8_t i = 0; i < count; i++) {
218
- if (!sameName(values[i].name, name)) continue;
219
- copyBounded(values[i].value, kNodeAttributeValueMax, value);
220
- if (isId) idAtom = internCssAtom(values[i].value);
221
- return;
271
+ auto *tail = &values;
272
+ while (*tail) {
273
+ auto &entry = **tail;
274
+ if (sameName(entry.name(), name)) {
275
+ const auto bytes = std::min(std::strlen(value), std::size_t(kNodeAttributeValueMax - 1)) + 1;
276
+ if (bytes > entry.valueCapacity) {
277
+ // Allocate/copy first: value may point into the existing entry.
278
+ auto replacement = NodeAttributeEntry::create(name, value);
279
+ replacement->next = std::move(entry.next);
280
+ *tail = std::move(replacement);
281
+ } else {
282
+ std::memmove(entry.value(), value, bytes - 1);
283
+ entry.value()[bytes - 1] = 0;
284
+ }
285
+ if (isId) idAtom = internCssAtom((*tail)->value());
286
+ return;
287
+ }
288
+ tail = &entry.next;
222
289
  }
223
290
  if (count >= kMaxNodeAttributes) return;
224
- copyBounded(values[count].name, kNodeAttributeNameMax, name);
225
- copyBounded(values[count].value, kNodeAttributeValueMax, value);
226
- if (isId) idAtom = internCssAtom(values[count].value);
227
- count++;
291
+ auto entry = NodeAttributeEntry::create(name, value);
292
+ if (isId) idAtom = internCssAtom(entry->value());
293
+ *tail = std::move(entry);
294
+ ++count;
228
295
  }
229
296
 
230
297
  bool NodeAttributeStore::remove(const char *name)
231
298
  {
232
299
  if (!name) return false;
233
- for (uint8_t i = 0; i < count; i++) {
234
- if (!sameName(values[i].name, name)) continue;
300
+ for (auto *link = &values; *link; link = &(*link)->next) {
301
+ if (!sameName((*link)->name(), name)) continue;
235
302
  if (sameName(name, "id")) idAtom = kInvalidCssAtom;
236
- for (uint8_t j = i; j + 1 < count; j++) {
237
- values[j] = values[j + 1];
238
- }
303
+ // Keep the removed owner alive while moving its next link.
304
+ auto removed = std::move(*link);
305
+ *link = std::move(removed->next);
239
306
  count--;
240
- values[count].name[0] = '\0';
241
- values[count].value[0] = '\0';
242
307
  return true;
243
308
  }
244
309
  return false;
@@ -247,8 +312,8 @@ bool NodeAttributeStore::remove(const char *name)
247
312
  const char *NodeAttributeStore::get(const char *name) const
248
313
  {
249
314
  if (!name) return "";
250
- for (uint8_t i = 0; i < count; i++) {
251
- if (sameName(values[i].name, name)) return values[i].value;
315
+ for (auto *entry = values.get(); entry; entry = entry->next.get()) {
316
+ if (sameName(entry->name(), name)) return entry->value();
252
317
  }
253
318
  return "";
254
319
  }
@@ -256,52 +321,18 @@ const char *NodeAttributeStore::get(const char *name) const
256
321
  bool NodeAttributeStore::has(const char *name) const
257
322
  {
258
323
  if (!name) return false;
259
- for (uint8_t i = 0; i < count; i++) {
260
- if (sameName(values[i].name, name)) return true;
324
+ for (auto *entry = values.get(); entry; entry = entry->next.get()) {
325
+ if (sameName(entry->name(), name)) return true;
261
326
  }
262
327
  return false;
263
328
  }
264
329
 
265
330
  void NodeEventListeners::clear()
266
331
  {
267
- // Releasing a non-empty list drops a node from its type's live-listener count, so
268
- // the dispatcher stops walking the tree for a type once its last listener
269
- // goes away.
270
- const auto release = [](NodeEventListenerList &list, int index) {
271
- if (!list.empty() && g_listenerTypeCounts[index] > 0) g_listenerTypeCounts[index]--;
272
- list.entries.clear();
273
- };
274
- release(click, 0);
275
- release(touchstart, 1);
276
- release(touchmove, 2);
277
- release(touchend, 3);
278
- release(input, 4);
279
- release(keydown, 5);
280
- release(scroll, 6);
281
- }
282
-
283
- NodeEventListenerList *NodeEventListeners::listenersFor(const char *type)
284
- {
285
- if (sameName(type, "click")) return &click;
286
- // Pointer events alias onto their touch* sibling slot — see eventTypeIndex.
287
- if (sameName(type, "touchstart") || sameName(type, "pointerdown")) return &touchstart;
288
- if (sameName(type, "touchmove") || sameName(type, "pointermove")) return &touchmove;
289
- if (sameName(type, "touchend") || sameName(type, "pointerup")) return &touchend;
290
- if (sameName(type, "input")) return &input;
291
- if (sameName(type, "keydown")) return &keydown;
292
- if (sameName(type, "scroll")) return &scroll;
293
- return nullptr;
294
- }
295
-
296
- const NodeEventListenerList *NodeEventListeners::listenersFor(const char *type) const
297
- {
298
- return const_cast<NodeEventListeners *>(this)->listenersFor(type);
299
- }
300
-
301
- bool NodeEventListeners::hasAny() const
302
- {
303
- return !click.empty() || !touchstart.empty() || !touchmove.empty() ||
304
- !touchend.empty() || !input.empty() || !keydown.empty() || !scroll.empty();
332
+ for (int type = 0; type < 7; ++type)
333
+ if (hasType(type) && g_listenerTypeCounts[type] > 0) --g_listenerTypeCounts[type];
334
+ entries.clear();
335
+ types = 0;
305
336
  }
306
337
 
307
338
  EventListenerId Tree::setEventListener(int node, const char *type, gea::framework::events::EventListener listener)
@@ -312,16 +343,16 @@ EventListenerId Tree::setEventListener(int node, const char *type, gea::framewor
312
343
  // Don't allocate a rare-data block for an unrecognized event type (the set
313
344
  // listenerFor knows == the set eventTypeIndex tracks).
314
345
  if (eventTypeIndex(type) < 0) return kInvalidEventListenerId;
315
- auto *list = ensureRareData(node).listeners.listenersFor(type);
316
- if (!list) return kInvalidEventListenerId;
317
- // First listener for this (node, type): bump the type's live count so the
318
- // dispatcher knows the type is worth walking the tree for.
346
+ auto &list = ensureRareData(node).listeners;
319
347
  const int typeIndex = eventTypeIndex(type);
320
- if (list->empty() && typeIndex >= 0) g_listenerTypeCounts[typeIndex]++;
348
+ if (!list.hasType(typeIndex)) {
349
+ ++g_listenerTypeCounts[typeIndex];
350
+ list.types |= 1u << typeIndex;
351
+ }
321
352
  EventListenerId id = g_nextEventListenerId++;
322
353
  if (id == kInvalidEventListenerId) id = g_nextEventListenerId++;
323
- list->entries.push_back(NodeEventListenerEntry{
324
- id,
354
+ list.entries.push_back(NodeEventListenerEntry{
355
+ id, static_cast<std::uint8_t>(typeIndex),
325
356
  std::make_shared<gea::framework::events::EventListener>(std::move(listener))});
326
357
  return id;
327
358
  }
@@ -332,14 +363,17 @@ bool Tree::removeEventListener(int node, const char *type, EventListenerId liste
332
363
  if (node < 0 || node >= state.nodeCount || listenerId == kInvalidEventListenerId) return false;
333
364
  NodeRareData *rd = rareDataFor(node);
334
365
  if (!rd) return false;
335
- NodeEventListenerList *list = rd->listeners.listenersFor(type);
336
- if (!list) return false;
337
- for (auto it = list->entries.begin(); it != list->entries.end(); ++it) {
338
- if (it->id != listenerId) continue;
339
- list->entries.erase(it);
340
- if (list->empty()) {
341
- const int typeIndex = eventTypeIndex(type);
342
- if (typeIndex >= 0 && g_listenerTypeCounts[typeIndex] > 0) g_listenerTypeCounts[typeIndex]--;
366
+ auto &list = rd->listeners;
367
+ const int typeIndex = eventTypeIndex(type);
368
+ if (!list.hasType(typeIndex)) return false;
369
+ for (auto it = list.entries.begin(); it != list.entries.end(); ++it) {
370
+ if (it->id != listenerId || it->type != typeIndex) continue;
371
+ list.entries.erase(it);
372
+ const bool remains = std::any_of(list.entries.begin(), list.entries.end(),
373
+ [typeIndex](const auto &entry) { return entry.type == typeIndex; });
374
+ if (!remains) {
375
+ list.types &= ~(1u << typeIndex);
376
+ if (g_listenerTypeCounts[typeIndex] > 0) --g_listenerTypeCounts[typeIndex];
343
377
  }
344
378
  return true;
345
379
  }
@@ -373,8 +407,8 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
373
407
  if (!event.bubbles && node != event.targetId) break;
374
408
  NodeRareData *rd = rareDataFor(node);
375
409
  if (!rd) continue;
376
- auto *initialList = rd->listeners.listenersFor(event.typeName());
377
- if (!initialList || initialList->empty()) continue;
410
+ const int typeIndex = eventTypeIndex(event.typeName());
411
+ if (!rd->listeners.hasType(typeIndex)) continue;
378
412
 
379
413
  event.currentTargetId = node;
380
414
  event.currentTarget = gea::framework::events::EventTarget(node);
@@ -393,16 +427,16 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
393
427
  // keeps the in-flight function alive after its entry is erased. Reacquire the
394
428
  // list after every callback and advance by monotonic listener id; listeners
395
429
  // added during this dispatch are above maxId and do not receive this event.
396
- const EventListenerId maxId = initialList->entries.back().id;
430
+ const EventListenerId maxId = rd->listeners.entries.back().id;
397
431
  EventListenerId cursor = kInvalidEventListenerId;
398
432
  for (;;) {
399
433
  rd = rareDataFor(node);
400
434
  if (!rd) break;
401
- auto *list = rd->listeners.listenersFor(event.typeName());
402
- if (!list || list->empty()) break;
435
+ if (!rd->listeners.hasType(typeIndex)) break;
403
436
  EventListenerId nextId = kInvalidEventListenerId;
404
437
  std::shared_ptr<gea::framework::events::EventListener> callback;
405
- for (const auto &entry : list->entries) {
438
+ for (const auto &entry : rd->listeners.entries) {
439
+ if (entry.type != typeIndex) continue;
406
440
  if (entry.id <= cursor || entry.id > maxId) continue;
407
441
  nextId = entry.id;
408
442
  callback = entry.listener;
@@ -498,7 +532,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
498
532
  // (e.g. an EPUB cover applied via setAttribute) never paints.
499
533
  markDisplayListDirty();
500
534
  state.nodes[node].render.dirty = 1;
535
+ #if GEA_CSS_SCROLLING
501
536
  state.nodes[node].render.non_scroll_dirty = 1;
537
+ #endif
502
538
  }
503
539
  }
504
540
  if (state.nodes[node].type == NodeType::Image && sameName(name, "fit")) {
@@ -518,7 +554,9 @@ void Tree::setAttribute(int node, const char *name, const char *value)
518
554
  state.displayListDirty = true;
519
555
  state.nodes[node].render.dirty = 1;
520
556
  state.nodes[node].render.layout_dirty = 1;
557
+ #if GEA_CSS_SCROLLING
521
558
  state.nodes[node].render.non_scroll_dirty = 1;
559
+ #endif
522
560
  }
523
561
  }
524
562
 
@@ -541,7 +579,9 @@ void Tree::removeAttribute(int node, const char *name)
541
579
  state.displayListDirty = true;
542
580
  state.nodes[node].render.dirty = 1;
543
581
  state.nodes[node].render.layout_dirty = 1;
582
+ #if GEA_CSS_SCROLLING
544
583
  state.nodes[node].render.non_scroll_dirty = 1;
584
+ #endif
545
585
  }
546
586
  }
547
587
 
package/ui/tree_events.h CHANGED
@@ -15,9 +15,20 @@ inline constexpr int kMaxNodeAttributes = 8;
15
15
  inline constexpr int kNodeAttributeNameMax = 32;
16
16
  inline constexpr int kNodeAttributeValueMax = 64;
17
17
 
18
- struct NodeAttribute {
19
- char name[kNodeAttributeNameMax]{};
20
- char value[kNodeAttributeValueMax]{};
18
+ struct NodeAttributeEntry;
19
+ struct NodeAttributeDeleter {
20
+ void operator()(NodeAttributeEntry *entry) const;
21
+ };
22
+ using NodeAttributePtr = std::unique_ptr<NodeAttributeEntry, NodeAttributeDeleter>;
23
+ struct NodeAttributeEntry {
24
+ NodeAttributePtr next;
25
+ std::uint8_t nameBytes = 0, valueCapacity = 0;
26
+ // The allocation continues with nameBytes + valueCapacity bytes. Updating
27
+ // another attribute never moves this entry or invalidates its string.
28
+ const char *name() const { return reinterpret_cast<const char *>(this + 1); }
29
+ char *value() { return reinterpret_cast<char *>(this + 1) + nameBytes; }
30
+ const char *value() const { return reinterpret_cast<const char *>(this + 1) + nameBytes; }
31
+ static NodeAttributePtr create(const char *name, const char *value);
21
32
  };
22
33
 
23
34
  struct NodeAttributeStore {
@@ -25,7 +36,15 @@ struct NodeAttributeStore {
25
36
  int16_t pressValue = -1;
26
37
  CssAtomId idAtom = kInvalidCssAtom;
27
38
  uint8_t count = 0;
28
- NodeAttribute values[kMaxNodeAttributes]{};
39
+ // Allocate only attributes that exist. Entries stay at stable addresses
40
+ // as other attributes are added/removed; an empty store allocates nothing.
41
+ NodeAttributePtr values;
42
+
43
+ NodeAttributeStore() = default;
44
+ NodeAttributeStore(const NodeAttributeStore &other);
45
+ NodeAttributeStore &operator=(const NodeAttributeStore &other);
46
+ NodeAttributeStore(NodeAttributeStore &&other) noexcept;
47
+ NodeAttributeStore &operator=(NodeAttributeStore &&other) noexcept;
29
48
 
30
49
  void clear();
31
50
  void set(const char *name, const char *value);
@@ -39,28 +58,17 @@ using gea::framework::events::kInvalidEventListenerId;
39
58
 
40
59
  struct NodeEventListenerEntry {
41
60
  EventListenerId id = kInvalidEventListenerId;
61
+ std::uint8_t type = 0;
42
62
  std::shared_ptr<gea::framework::events::EventListener> listener;
43
63
  };
44
64
 
45
- struct NodeEventListenerList {
46
- std::vector<NodeEventListenerEntry> entries;
47
-
48
- bool empty() const { return entries.empty(); }
49
- };
50
-
51
65
  struct NodeEventListeners {
52
- NodeEventListenerList click;
53
- NodeEventListenerList touchstart;
54
- NodeEventListenerList touchmove;
55
- NodeEventListenerList touchend;
56
- NodeEventListenerList input;
57
- NodeEventListenerList keydown;
58
- NodeEventListenerList scroll;
66
+ std::vector<NodeEventListenerEntry> entries;
67
+ std::uint8_t types = 0;
59
68
 
60
69
  void clear();
61
- NodeEventListenerList *listenersFor(const char *type);
62
- const NodeEventListenerList *listenersFor(const char *type) const;
63
- bool hasAny() const;
70
+ bool hasType(int type) const { return type >= 0 && (types & (1u << type)); }
71
+ bool hasAny() const { return types != 0; }
64
72
  };
65
73
 
66
74
  // NOTE: the NodeRareData block (which bundles attributes + listeners + other
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ namespace gea::embedded::ui {
5
+
6
+ // Read-only native diagnostics. This header intentionally exposes no node or
7
+ // style representation and cannot introduce CSS operations behind the source
8
+ // analyzer's back. As with Tree, callers must respect the UI task's ownership.
9
+ struct TreeInspection {
10
+ static int nodeCount();
11
+ static int mountedWidth();
12
+ static bool hasMountedText(const char *text);
13
+ };
14
+
15
+ } // namespace gea::embedded::ui