@geastack/engine 0.1.5 → 0.1.6

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/input.cpp CHANGED
@@ -300,6 +300,7 @@ public:
300
300
  // velocity samples from a touch the new app never saw.
301
301
  void reset()
302
302
  {
303
+ treeState().hoveredNodeId = -1;
303
304
  activeTouchNode_ = -1;
304
305
  savedBackgroundColor_ = 0;
305
306
  savedHasBackground_ = 0;
@@ -396,20 +397,6 @@ public:
396
397
  private:
397
398
  InputController() = default;
398
399
 
399
- void sortChildrenByZIndex(int *children, int childCount) const
400
- {
401
- Node *nodes = Tree::instance().nodes();
402
- for (int i = 1; i < childCount; i++) {
403
- const int key = children[i];
404
- int j = i - 1;
405
- while (j >= 0 && nodes[children[j]].style.z_index > nodes[key].style.z_index) {
406
- children[j + 1] = children[j];
407
- j--;
408
- }
409
- children[j + 1] = key;
410
- }
411
- }
412
-
413
400
  static bool pointInsideNodeHitArea(const Node &node, int x, int y)
414
401
  {
415
402
  if (node.layout.width <= 0 || node.layout.height <= 0) return false;
@@ -451,10 +438,10 @@ private:
451
438
  return true;
452
439
  }
453
440
 
454
- int hitTestNodeId(int id, int x, int y)
441
+ int hitTestNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
455
442
  {
456
443
  Node &node = Tree::instance().nodes()[id];
457
- if (node.style.display == 1) return -1;
444
+ if (node.style.display == 1 || isCollapsedFlexSubtree(node)) return -1;
458
445
  // CSS `pointer-events: none` — this node and its subtree are never the
459
446
  // target of a pointer event, so the hit-test falls through to whatever is
460
447
  // painted behind it. Without this, a decorative overlay image positioned
@@ -463,39 +450,63 @@ private:
463
450
  if (node.style.pointer_events == 1) return -1;
464
451
 
465
452
  const bool inside = pointInsideNodeHitArea(node, x, y);
466
- if (!inside && node.style.overflow != 0) return -1;
467
-
468
- int children[kMaxChildren];
469
- const int childCount = LayoutEngine::instance().collectChildren(id, children, kMaxChildren, false);
470
- sortChildrenByZIndex(children, childCount);
471
-
472
- for (int i = childCount - 1; i >= 0; i--) {
473
- const int result = hitTestNodeId(children[i], x, y);
453
+ if (LayoutEngine::isViewportFixed(node)) clipped = false;
454
+ int clipX, clipY, clipW, clipH;
455
+ overflowClipBounds(node, clipX, clipY, clipW, clipH);
456
+ const bool outsideClip = x < clipX || y < clipY || x >= clipX + clipW || y >= clipY + clipH;
457
+ const bool childClipped = clipped || (outsideClip && node.style.overflow != 0);
458
+ if (childClipped && (!inside || clipped) && !LayoutEngine::containsViewportFixed(id)) return -1;
459
+
460
+ const auto children = PaintOrder::collectChildren(id, groupRoot, includePositioned);
461
+ for (auto child = children.rbegin(); child != children.rend(); ++child) {
462
+ bool inheritedClip = childClipped, ignored = false;
463
+ const Node *nodes = Tree::instance().nodes();
464
+ for (int p = nodes[*child].parent; p >= 0 && p != id; p = nodes[p].parent) {
465
+ const auto &ancestor = nodes[p];
466
+ if (ancestor.style.pointer_events == 1) ignored = true;
467
+ int ax, ay, aw, ah;
468
+ overflowClipBounds(ancestor, ax, ay, aw, ah);
469
+ if (ancestor.style.overflow && (x < ax || y < ay || x >= ax + aw || y >= ay + ah)) inheritedClip = true;
470
+ }
471
+ if (ignored) continue;
472
+ const int result = hitTestNodeId(*child, x, y, inheritedClip, PaintOrder::isGroup(*child), PaintOrder::isContext(*child));
474
473
  if (result >= 0) return result;
475
474
  }
476
475
 
477
- if (!inside) return -1;
476
+ if (!inside || clipped || node.style.visibility != 0) return -1;
478
477
  return id;
479
478
  }
480
479
 
481
- int findScrollNodeId(int id, int x, int y)
480
+ int findScrollNodeId(int id, int x, int y, bool clipped = false, bool groupRoot = true, bool includePositioned = true)
482
481
  {
483
482
  Node &node = Tree::instance().nodes()[id];
484
- if (node.style.display == 1) return -1;
483
+ if (node.style.display == 1 || isCollapsedFlexSubtree(node)) return -1;
485
484
 
486
485
  const bool inside = pointInsideNodeHitArea(node, x, y);
487
- if (!inside && node.style.overflow != 0) return -1;
488
-
489
- int children[kMaxChildren];
490
- const int childCount = LayoutEngine::instance().collectChildren(id, children, kMaxChildren, false);
491
- sortChildrenByZIndex(children, childCount);
492
-
493
- for (int i = childCount - 1; i >= 0; i--) {
494
- const int result = findScrollNodeId(children[i], x, y);
486
+ if (LayoutEngine::isViewportFixed(node)) clipped = false;
487
+ int clipX, clipY, clipW, clipH;
488
+ overflowClipBounds(node, clipX, clipY, clipW, clipH);
489
+ const bool outsideClip = x < clipX || y < clipY || x >= clipX + clipW || y >= clipY + clipH;
490
+ const bool childClipped = clipped || (outsideClip && node.style.overflow != 0);
491
+ if (childClipped && (!inside || clipped) && !LayoutEngine::containsViewportFixed(id)) return -1;
492
+
493
+ const auto children = PaintOrder::collectChildren(id, groupRoot, includePositioned);
494
+ for (auto child = children.rbegin(); child != children.rend(); ++child) {
495
+ bool inheritedClip = childClipped, ignored = false;
496
+ const Node *nodes = Tree::instance().nodes();
497
+ for (int p = nodes[*child].parent; p >= 0 && p != id; p = nodes[p].parent) {
498
+ const auto &ancestor = nodes[p];
499
+
500
+ int ax, ay, aw, ah;
501
+ overflowClipBounds(ancestor, ax, ay, aw, ah);
502
+ if (ancestor.style.overflow && (x < ax || y < ay || x >= ax + aw || y >= ay + ah)) inheritedClip = true;
503
+ }
504
+ if (ignored) continue;
505
+ const int result = findScrollNodeId(*child, x, y, inheritedClip, PaintOrder::isGroup(*child), PaintOrder::isContext(*child));
495
506
  if (result >= 0) return result;
496
507
  }
497
508
 
498
- if (!inside) return -1;
509
+ if (!inside || clipped || node.style.visibility != 0) return -1;
499
510
  const bool scrollableVirtualList = node.type == NodeType::VirtualList && VirtualListRenderer::scrollMaxY(id) > 0;
500
511
  const bool scrollableView = node.type != NodeType::VirtualList && isViewLikeNodeType(node.type) &&
501
512
  (nodeCanScrollX(id, node) || nodeCanScrollY(id, node));
@@ -826,6 +837,25 @@ int Tree::hitTestNode(int x, int y)
826
837
  return InputController::instance().hitTestNode(x, y);
827
838
  }
828
839
 
840
+ int Tree::pointerHover(int x, int y)
841
+ {
842
+ auto &state = treeState();
843
+ const int target = x < 0 || y < 0 ? -1 : hitTestNode(x, y);
844
+ if (target != state.hoveredNodeId) {
845
+ state.hoveredNodeId = target;
846
+ StyleSheet::instance().hoverChanged();
847
+ }
848
+ return target;
849
+ }
850
+
851
+ bool Tree::isHovered(int node) const
852
+ {
853
+ const auto &state = treeState();
854
+ const int target = state.hoveredNodeId;
855
+ return target >= 0 && target < state.nodeCount && state.nodeActive[target] &&
856
+ containsNode(mountedRoot(), target) && containsNode(node, target);
857
+ }
858
+
829
859
  void Tree::pointerDown(int x, int y)
830
860
  {
831
861
  InputController::instance().pointerDown(x, y);
@@ -86,15 +86,15 @@ void InputRenderer::layout(int id, int)
86
86
 
87
87
  const char *content = inputContentText(id, nullptr, n.style.text_color);
88
88
  const char *measureText = inputMeasureText(id);
89
- int width = TextRenderer::measureWidth(content, n.style.font_id, n.style.font_size, n.style.text_transform) + n.style.padding[1] + n.style.padding[3];
90
- int height = TextRenderer::measureHeight(measureText, n.style.font_id, n.style.font_size, n.style.text_transform, n.style.line_height) + n.style.padding[0] + n.style.padding[2];
91
-
92
- if (n.style.width != kUnset) width = n.style.width;
93
- else if (n.style.width_percent != kUnset && n.layout.width > 0) width = n.layout.width;
94
- if (n.style.height != kUnset) height = n.style.height;
95
- else if (n.style.height_percent != kUnset && n.layout.height > 0) height = n.layout.height;
96
- n.layout.width = LayoutEngine::instance().clampSize(width, n.style.min_width, n.style.max_width);
97
- n.layout.height = LayoutEngine::instance().clampSize(height, n.style.min_height, n.style.max_height);
89
+ int width = TextRenderer::measureWidth(content, n.style.font_id, n.style.font_size, n.style.text_transform) + boxInset(n.style, 1) + boxInset(n.style, 3);
90
+ int height = TextRenderer::measureHeight(measureText, n.style.font_id, n.style.font_size, n.style.text_transform, n.style.line_height) + boxInset(n.style, 0) + boxInset(n.style, 2);
91
+
92
+ if (n.style.width != kUnset) width = contentSizeToBorderSize(n.style, n.style.width, true);
93
+ else if ((n.style.width_percent != kUnset || n.style.width_expression >= 0) && n.layout.width > 0) width = n.layout.width;
94
+ if (n.style.height != kUnset) height = contentSizeToBorderSize(n.style, n.style.height, false);
95
+ else if ((n.style.height_percent != kUnset || n.style.height_expression >= 0) && n.layout.height > 0) height = n.layout.height;
96
+ n.layout.width = clampBorderBoxSize(n.style, width, true);
97
+ n.layout.height = clampBorderBoxSize(n.style, height, false);
98
98
  n.layout.scroll_content_height = n.layout.height;
99
99
  n.layout.scroll_y = 0;
100
100
  }
@@ -114,10 +114,10 @@ void InputRenderer::record(int id)
114
114
  const int y = n.layout.y;
115
115
  const int w = n.layout.width;
116
116
  const int h = n.layout.height;
117
- const int padLeft = n.style.padding[3];
118
- const int padRight = n.style.padding[1];
119
- const int padTop = n.style.padding[0];
120
- const int padBottom = n.style.padding[2];
117
+ const int padLeft = boxInset(n.style, 3);
118
+ const int padRight = boxInset(n.style, 1);
119
+ const int padTop = boxInset(n.style, 0);
120
+ const int padBottom = boxInset(n.style, 2);
121
121
  const int contentX = x + padLeft;
122
122
  const int contentY = y + padTop;
123
123
  int contentW = w - padLeft - padRight;
package/ui/internal.h CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "tree_internal.h"
5
5
 
6
6
  #include <cstdint>
7
+ #include <vector>
7
8
 
8
9
  #ifdef quad
9
10
  #undef quad
@@ -32,6 +33,9 @@ extern bool gScrollImageHoldPending;
32
33
  // blits marks the tree dirty for one normal full refresh (images included).
33
34
  void rootScrollImageHoldTick();
34
35
 
36
+ bool isCollapsedFlexItem(const Node &node);
37
+ bool isCollapsedFlexSubtree(const Node &node);
38
+
35
39
  class CameraSurfaceProvider;
36
40
 
37
41
  // Max children collected per node in one recordNode level. The record scratch
@@ -73,7 +77,11 @@ void rootScrollImageHoldTick();
73
77
  struct DisplayCommand
74
78
  {
75
79
  DisplayCommandType type;
80
+ bool textDecorationInk = false;
76
81
  int16_t bx, by, bw, bh;
82
+ // Background paint can use descendant glyph coverage without changing
83
+ // foreground text color or allocating a viewport-sized mask.
84
+ int16_t textClipOwner = -1;
77
85
  union
78
86
  {
79
87
  struct
@@ -164,6 +172,10 @@ void rootScrollImageHoldTick();
164
172
  int16_t tl, tr, br, bl;
165
173
  int16_t lineWidth;
166
174
  gea::framework::graphics::pixel::native_t color;
175
+ // CSS radii are already normalized on the outer border box. Inner
176
+ // curves may exceed half the clipped box; do not clamp them again.
177
+ int16_t rx8[4], ry8[4];
178
+ uint8_t cssRadii;
167
179
  } strokeRoundedRect;
168
180
  struct
169
181
  {
@@ -198,6 +210,7 @@ void rootScrollImageHoldTick();
198
210
  gea::framework::graphics::pixel::native_t color;
199
211
  uint8_t alpha;
200
212
  int8_t textTransform;
213
+ int8_t whiteSpace;
201
214
  // CSS backface-visibility:hidden — drop this projected label when its winding
202
215
  // points away from the viewer, matching its (culled) back-facing parent face.
203
216
  uint8_t backfaceHidden;
@@ -286,6 +299,7 @@ void rootScrollImageHoldTick();
286
299
  static DisplayList &instance();
287
300
 
288
301
  DisplayCommand *append();
302
+ int setRecordingTextClipOwner(int owner);
289
303
  void clear();
290
304
  void resetStorage();
291
305
  // allowSkipStatic: caller guarantees this frame will use the direct
@@ -392,6 +406,7 @@ void rootScrollImageHoldTick();
392
406
  bool reprojectDirtyRect(int *x0, int *y0, int *x1, int *y1) const;
393
407
  void filterBlurCacheStats(int *hits, int *misses) const;
394
408
  int commandCount() const;
409
+ bool hasTextClippedBackgrounds() const;
395
410
  int nodeCommandCount(int node) const;
396
411
  const DisplayCommand *nodeCommandAt(int node, int index) const;
397
412
  bool nodeCommandBounds(int node, int *x0, int *y0, int *x1, int *y1) const;
@@ -402,6 +417,13 @@ void rootScrollImageHoldTick();
402
417
  {
403
418
  public:
404
419
  static LayoutEngine &instance();
420
+ static int alignedAbsoluteOffset(const Node &parent, const Node &child, bool horizontal,
421
+ const Node *containing = nullptr, int containingStart = 0, int containingSize = 0);
422
+ static int fixedContainingBlock(const Node &node);
423
+ static bool isViewportFixed(const Node &node);
424
+ static bool containsViewportFixed(int node);
425
+ static bool absoluteGridArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height);
426
+ static void absoluteContainingArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height);
405
427
 
406
428
  int clampSize(int size, int minSize, int maxSize) const;
407
429
  int collectChildren(int parent, int *out, int max, bool skipAbsolute) const;
@@ -409,7 +431,7 @@ void rootScrollImageHoldTick();
409
431
  // (LayoutBox::memo_pass). Must be called before each root layoutNode()
410
432
  // so memo hits never leak across passes/frames.
411
433
  void beginLayoutPass();
412
- void layoutNode(int id, int availableWidth, int availableHeight);
434
+ void layoutNode(int id, int availableWidth, int availableHeight, bool intrinsicBoxEdges = false);
413
435
  // Scoped relayout: re-lays ONLY `scope`'s subtree using the available box
414
436
  // remembered from its last layout, then resolves the subtree's absolute
415
437
  // coords from the scope's (unchanged) position. Returns false — caller
@@ -426,6 +448,21 @@ void rootScrollImageHoldTick();
426
448
  // resolveRowDirection). Exposed for refresh fast paths that mirror that
427
449
  // flow decision without running a layout pass.
428
450
  static bool isInlineLevelNode(const Node &n);
451
+ // CSS display classification without layout-only margin heuristics.
452
+ // Inline-level boxes blockified by float, absolute/fixed positioning, or
453
+ // flex/grid-item status return false.
454
+ static bool isCssInlineLevelBox(const Node &n, bool hypothetical = false);
455
+ };
456
+
457
+ // Shared order for recording, retained transform replay, and hit testing.
458
+ class PaintOrder
459
+ {
460
+ public:
461
+ static void sortChildren(int *children, int count, int contextRoot);
462
+ static int compareNodes(int first, int second);
463
+ static bool isContext(int node);
464
+ static bool isGroup(int node);
465
+ static std::vector<int> collectChildren(int node, bool groupRoot = true, bool includePositioned = true);
429
466
  };
430
467
 
431
468
  class ViewRenderer
@@ -434,6 +471,7 @@ void rootScrollImageHoldTick();
434
471
  static bool recordClipBegin(const Node &node);
435
472
  static void recordClipEnd(const Node &node);
436
473
  static void recordBox(const Node &node, uint8_t parentAlpha = 255);
474
+ static int canvasBackgroundSource();
437
475
  static void recordScrollbar(const Node &node);
438
476
  static int scrollMaxX(const Node &node);
439
477
  static int scrollMaxY(const Node &node);
@@ -442,6 +480,8 @@ void rootScrollImageHoldTick();
442
480
  static void transformedCorners(const Node &node, bool usePrevious, int16_t *xs, int16_t *ys);
443
481
  static void transformedRectCorners(const Node &node, bool usePrevious, int x, int y, int w, int h, int16_t *xs, int16_t *ys,
444
482
  int16_t *xs8 = nullptr, int16_t *ys8 = nullptr);
483
+ static bool backfaceSubtreeHidden(const Node &node);
484
+ static bool isTransformableBox(const Node &node);
445
485
  static int transformedDepth(const Node &node, bool usePrevious);
446
486
  // True iff any node in the tree carries a transform/perspective this frame
447
487
  // or last (cached once per refresh). Lets paint-order sorting skip the 3D
@@ -456,6 +496,7 @@ void rootScrollImageHoldTick();
456
496
  struct InlineFlowMeasure {
457
497
  int lineCount = 0;
458
498
  int firstLineWidth = 0;
499
+ int firstLineTrailingSpace = 0;
459
500
  int lastLineWidth = 0;
460
501
  int maxLineWidth = 0;
461
502
  int lineAdvance = 0;
@@ -465,16 +506,17 @@ void rootScrollImageHoldTick();
465
506
  // identically to deleting them — and keeps the run a single unmodified
466
507
  // string for the display list.
467
508
  int firstLineIndentAdjust = 0;
468
- // True when the first line could only be filled by cutting a word open —
469
- // the run does not fit the space left on the line box it was offered, so an
470
- // inline formatting context starts it on the next one instead.
471
- bool firstLineForcedSplit = false;
509
+
472
510
  };
473
511
 
474
512
  class TextRenderer
475
513
  {
476
514
  public:
515
+ // Shared preparation for measuring and replaying authored text. Storage
516
+ // owns the result only when collapsing or case transformation is needed.
517
+ static const char *prepareText(const char *text, int textTransform, int whiteSpace, std::string &storage);
477
518
  static void layout(int id, int availableWidth);
519
+ static int baselineOffset(const Node &node, bool last);
478
520
  // True when a run's line breaking is reproducible from per-glyph advances,
479
521
  // i.e. the same wrapper the draw path uses. A host that measures whole
480
522
  // strings for us (CoreText on Apple targets) does its own breaking, which
@@ -487,12 +529,16 @@ void rootScrollImageHoldTick();
487
529
  // `atLineStart`, as CSS does when a line box begins.
488
530
  static InlineFlowMeasure measureInlineFlow(const Node &node, int firstAvail, int contentWidth, bool atLineStart);
489
531
  static void record(const Node &node, uint8_t parentAlpha = 255);
532
+ static void unionCoverageRow(const DisplayCommand &command, int screenY, int screenX,
533
+ int width, uint8_t *outCoverage);
490
534
  static void drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign,
491
535
  int containerWidth, int fontId, int textTransform = 0, int lineHeight = 0, int whiteSpace = 0, int textOverflow = 0, int maxHeight = 0,
492
536
  int firstLineIndent = 0);
493
537
  // Single-line width measure for places that don't go through layout()
494
538
  // — used by InputRenderer to position the caret at the end of the value.
495
539
  static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
540
+ static int firstUnbreakableWidth(const Node &node);
541
+ static int minContentWidth(const Node &node, int *pendingWord = nullptr);
496
542
  static int measureHeight(const char *text, int fontId, int fontSize, int textTransform = 0, int lineHeight = 0);
497
543
  // In-place box re-measure for a rebound text node on refresh paths that
498
544
  // skip the layout pass (root-scroll fast path): record() wraps and clips