@geastack/engine 0.1.19 → 0.1.21

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/canvas.cpp CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  #include <algorithm>
10
10
  #include <atomic>
11
+ #include <climits>
11
12
  #include <cmath>
12
13
  #include <cstdio>
13
14
  #include <cstdlib>
@@ -1347,6 +1348,87 @@ void Canvas::writePixelAlpha(int x, int y, pixel::native_t fg, std::uint8_t alph
1347
1348
  writePixelNativeAlpha(x, y, fg, alpha);
1348
1349
  }
1349
1350
 
1351
+ void Canvas::blendCoverageRow(int y, int x0, int count, const std::uint8_t *coverage, pixel::native_t color,
1352
+ bool markRowDirty)
1353
+ {
1354
+ if (!pixels_ || !coverage || count <= 0 || globalAlpha_ == 0) return;
1355
+ const ClipRect &clip = clipStack_[clipDepth_];
1356
+ if (y < 0 || y >= height_ || y < clip.y0 || y > clip.y1) return;
1357
+ int begin = std::max({x0, clip.x0, 0});
1358
+ int end = std::min({x0 + count - 1, clip.x1, width_ - 1});
1359
+ while (begin <= end && coverage[begin - x0] == 0) ++begin;
1360
+ while (end >= begin && coverage[end - x0] == 0) --end;
1361
+ if (begin > end) return;
1362
+ const int phys = rowToPhysical(y);
1363
+ for (int x = begin; x <= end;) {
1364
+ // Runs of equal coverage: a shape's interior is one long run, its edges
1365
+ // short ones. Full runs are span fills; partial runs blend one colour at
1366
+ // one alpha, so the result for a given destination pixel repeats -- and
1367
+ // under a chart the destination is mostly one background colour.
1368
+ const std::uint8_t c = coverage[x - x0];
1369
+ int run = x + 1;
1370
+ while (run <= end && coverage[run - x0] == c) ++run;
1371
+ const int n = run - x;
1372
+ if (c == 255) {
1373
+ fillSpanGlobalAlpha(phys, x, n, color);
1374
+ } else if (c != 0) {
1375
+ const int a = globalAlpha_ == 255 ? c : (c * globalAlpha_) / 255;
1376
+ if (a > 0) blendSpanAlpha(y, phys, x, n, color, a);
1377
+ }
1378
+ x = run;
1379
+ }
1380
+ if (markRowDirty) markDirty(begin, y, end, y);
1381
+ }
1382
+
1383
+ void Canvas::blendCoverageSpan(int y, int x0, int count, std::uint8_t coverage, pixel::native_t color,
1384
+ bool markRowDirty)
1385
+ {
1386
+ if (!pixels_ || count <= 0 || coverage == 0 || globalAlpha_ == 0) return;
1387
+ const ClipRect &clip = clipStack_[clipDepth_];
1388
+ if (y < 0 || y >= height_ || y < clip.y0 || y > clip.y1) return;
1389
+ const int begin = std::max({x0, clip.x0, 0});
1390
+ const int end = std::min({x0 + count - 1, clip.x1, width_ - 1});
1391
+ if (begin > end) return;
1392
+ const int phys = rowToPhysical(y);
1393
+ if (coverage == 255) {
1394
+ fillSpanGlobalAlpha(phys, begin, end - begin + 1, color);
1395
+ } else {
1396
+ const int a = globalAlpha_ == 255 ? coverage : (coverage * globalAlpha_) / 255;
1397
+ if (a <= 0) return;
1398
+ blendSpanAlpha(y, phys, begin, end - begin + 1, color, a);
1399
+ }
1400
+ if (markRowDirty) markDirty(begin, y, end, y);
1401
+ }
1402
+
1403
+ // A run blends one colour at one alpha, so the result for a given destination
1404
+ // pixel repeats -- and under a chart the destination is mostly one colour.
1405
+ void Canvas::blendSpanAlpha(int y, int phys, int x, int n, pixel::native_t color, int a)
1406
+ {
1407
+ #if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
1408
+ if (landscapeRot_) {
1409
+ for (int i = 0; i < n; ++i) rotBlend(x + i, y, color, a);
1410
+ return;
1411
+ }
1412
+ #endif
1413
+ (void)y;
1414
+ #if GEA_PIXEL_STORAGE_PACKED
1415
+ for (int i = 0; i < n; ++i) pixel::packed::blendPixel(packedRow(phys), x + i, color, a);
1416
+ #else
1417
+ pixel::native_t *p = &pixels_[phys * stride_ + x];
1418
+ pixel::native_t lastBg = p[0];
1419
+ pixel::native_t lastOut = pixel::blendNative(color, lastBg, a);
1420
+ p[0] = lastOut;
1421
+ for (int i = 1; i < n; ++i) {
1422
+ const pixel::native_t bg = p[i];
1423
+ if (bg != lastBg) {
1424
+ lastBg = bg;
1425
+ lastOut = pixel::blendNative(color, bg, a);
1426
+ }
1427
+ p[i] = lastOut;
1428
+ }
1429
+ #endif
1430
+ }
1431
+
1350
1432
  // Fill a horizontal span at physical row `phys` with a colour (converted once
1351
1433
  // to the native pixel). Native fill — no per-pixel conversion, no branch.
1352
1434
  void Canvas::fillSpanColor(int phys, int x0, int count, pixel::native_t color)
@@ -1860,19 +1942,23 @@ void Canvas::fillRect(int x, int y, int w, int h, pixel::native_t color)
1860
1942
  runStart = -1; // keep the shared tail below a no-op
1861
1943
  }
1862
1944
  #else
1863
- pixel::native_t *dst = &pixels_[rowToPhysical(row) * stride_ + x0];
1864
- int runStart = -1;
1865
- for (int i = 0; i < count; i++) {
1866
- if (dst[i] == c) {
1867
- if (runStart >= 0) {
1868
- markDirty(x0 + runStart, row, x0 + i - 1, row);
1869
- runStart = -1;
1870
- }
1871
- continue;
1872
- }
1873
- if (runStart < 0) runStart = i;
1874
- dst[i] = c;
1875
- }
1945
+ // Trim the already-correct pixels off both ends and fill what is
1946
+ // left as one span. Pixels inside the span that already match are
1947
+ // rewritten with the same value, so the pixels are exactly those of
1948
+ // a per-run fill; the dirty rect is the row's differing extent, a
1949
+ // superset of the per-run rects. Per-run marking cost a dirty-list
1950
+ // walk per run: a fill over freshly reused staging memory (the
1951
+ // fused flush's strip buffer) differs in scattered runs, and it
1952
+ // measured 15.8 cycles/px on an ESP32-S3.
1953
+ const pixel::native_t *dst = &pixels_[rowToPhysical(row) * stride_ + x0];
1954
+ const int runStart = -1;
1955
+ int a = 0;
1956
+ while (a < count && dst[a] == c) ++a;
1957
+ if (a == count) continue;
1958
+ int b = count - 1;
1959
+ while (dst[b] == c) --b;
1960
+ fillSpanColor(rowToPhysical(row), x0 + a, b - a + 1, c);
1961
+ markDirty(x0 + a, row, x0 + b, row);
1876
1962
  #endif
1877
1963
  if (runStart >= 0) markDirty(x0 + runStart, row, x1, row);
1878
1964
  }
@@ -3983,8 +4069,14 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
3983
4069
  for (int sy = row0; sy <= row1; sy++) {
3984
4070
  int sx0 = width_;
3985
4071
  int sx1 = -1;
4072
+ // The row's span before clipping: the antialiased edge band is measured
4073
+ // from the shape's own edges, not from where a clip happens to cut it.
4074
+ int ux0 = INT_MAX;
4075
+ int ux1 = INT_MIN;
3986
4076
  auto addSpan = [&](int left, int right) {
3987
4077
  if (left > right) return;
4078
+ if (left < ux0) ux0 = left;
4079
+ if (right > ux1) ux1 = right;
3988
4080
  if (left < clip->x0) left = clip->x0;
3989
4081
  if (right > clip->x1) right = clip->x1;
3990
4082
  if (left < 0) left = 0;
@@ -4036,10 +4128,12 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
4036
4128
  anyX0 = width_;
4037
4129
  anyX1 = -1;
4038
4130
  roundedRectAnyCoverageSpan(x, y, w, h, tl, tr, br, bl, sy, aaSamples, kernelWidth, &anyX0, &anyX1);
4039
- if (anyX0 < clip->x0) anyX0 = clip->x0;
4040
- if (anyX1 > clip->x1) anyX1 = clip->x1;
4041
4131
  if (anyX0 < x) anyX0 = x;
4042
4132
  if (anyX1 > x + w - 1) anyX1 = x + w - 1;
4133
+ if (ux0 < anyX0) ux0 = anyX0;
4134
+ if (ux1 > anyX1) ux1 = anyX1;
4135
+ if (anyX0 < clip->x0) anyX0 = clip->x0;
4136
+ if (anyX1 > clip->x1) anyX1 = clip->x1;
4043
4137
  if (anyX0 < 0) anyX0 = 0;
4044
4138
  if (anyX1 >= width_) anyX1 = width_ - 1;
4045
4139
  if (sx0 < anyX0) sx0 = anyX0;
@@ -4116,18 +4210,23 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
4116
4210
  for (int px = inX1 + 1; px <= anyX1; ++px) paintCoverageEdge(px);
4117
4211
  continue;
4118
4212
  } else if (useAntialias) {
4119
- if (sx0 <= sx1) {
4120
- const int leftEdgeEnd = std::min(anyX1, sx0 + edgePad);
4121
- const int rightEdgeStart = std::max(anyX0, sx1 - edgePad);
4122
- if (leftEdgeEnd >= rightEdgeStart) {
4123
- for (int px = anyX0; px <= anyX1; ++px) paintCoverageEdge(px);
4124
- } else {
4125
- for (int px = anyX0; px <= leftEdgeEnd; ++px) paintCoverageEdge(px);
4126
- for (int px = rightEdgeStart; px <= anyX1; ++px) paintCoverageEdge(px);
4127
- }
4128
- } else {
4213
+ // Coverage-test only the pixels within edgePad of the shape's edges;
4214
+ // the solid interior below takes the rest. Measuring the band from
4215
+ // the clipped span instead sampled coverage at both clip borders of
4216
+ // every row, though the shape covers those pixels fully: a card
4217
+ // background repainted under a dirty region inside it spent most
4218
+ // of its time there.
4219
+ const int solidX0 = ux0 + edgePad + 1;
4220
+ const int solidX1 = ux1 - edgePad - 1;
4221
+ if (sx0 > sx1 || solidX0 > solidX1) {
4129
4222
  for (int px = anyX0; px <= anyX1; ++px) paintCoverageEdge(px);
4223
+ } else {
4224
+ const int leftEdgeEnd = std::min(anyX1, solidX0 - 1);
4225
+ const int rightEdgeStart = std::max(anyX0, solidX1 + 1);
4226
+ for (int px = anyX0; px <= leftEdgeEnd; ++px) paintCoverageEdge(px);
4227
+ for (int px = rightEdgeStart; px <= anyX1; ++px) paintCoverageEdge(px);
4130
4228
  }
4229
+ if (sx0 > sx1) continue; // no solid span (and ux0/ux1 may be unset)
4131
4230
  } else if (sx0 > sx1) {
4132
4231
  continue;
4133
4232
  }
@@ -4136,8 +4235,8 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
4136
4235
  // full opaque shape — fill it directly, with no per-pixel edge coverage
4137
4236
  // (roundedRectSampleContains). AA on carves the antialiased edge band (edgePad)
4138
4237
  // out of the solid fill and leaves those edges to the coverage passes above.
4139
- int fillX0 = useAntialias ? sx0 + edgePad + 1 : sx0;
4140
- int fillX1 = useAntialias ? sx1 - edgePad - 1 : sx1;
4238
+ int fillX0 = useAntialias ? ux0 + edgePad + 1 : sx0;
4239
+ int fillX1 = useAntialias ? ux1 - edgePad - 1 : sx1;
4141
4240
  if (fillX0 < clip->x0) fillX0 = clip->x0;
4142
4241
  if (fillX1 > clip->x1) fillX1 = clip->x1;
4143
4242
  if (fillX0 < 0) fillX0 = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/touch_runtime.cpp CHANGED
@@ -121,6 +121,15 @@ public:
121
121
  if (picker.consume(event.touchPhase, x, y, event.pointerId)) return true;
122
122
  }
123
123
  #endif
124
+ // A primary move marker holds the controller's queued-move flag: every
125
+ // path below must drain it, or the controller stops reporting moves and
126
+ // every later drag is dead while taps still work.
127
+ int tx = event.x;
128
+ int ty = event.y;
129
+ if (event.touchPhase == TouchPhase::Move && event.pointerId == 0) {
130
+ gea::platform::touch::Touchscreen::consumeLatestMove(&tx, &ty);
131
+ TouchRuntime::transformTouchToLogical(&tx, &ty);
132
+ }
124
133
  // Immediate-mode apps (Display.ctx games) mount no UI tree: hitTestNode
125
134
  // returns -1 and there is no root to bind document listeners onto, so the
126
135
  // tree dispatch below can never reach the app. Deliver pointer events
@@ -140,21 +149,14 @@ public:
140
149
 
141
150
  if (retireInvalidPrimary(!event.touching && event.touchPhase == TouchPhase::Up)) return false;
142
151
  if(primaryQuarantined_){
143
- if(event.touchPhase==TouchPhase::Move) gea::platform::touch::Touchscreen::consumeLatestMove(nullptr,nullptr);
144
152
  if(!event.touching && event.touchPhase==TouchPhase::Up)primaryQuarantined_=false;
145
153
  return false;
146
154
  }
147
155
  auto dispatchTicket=primaryTicket_;bool primaryBegan=false;
148
156
  bool changed = false;
149
157
 
150
- int tx = event.x;
151
- int ty = event.y;
152
158
  bool touching = event.touching;
153
- if (event.touchPhase == TouchPhase::Move) {
154
- gea::platform::touch::Touchscreen::consumeLatestMove(&tx, &ty);
155
- TouchRuntime::transformTouchToLogical(&tx, &ty);
156
- touching = true;
157
- }
159
+ if (event.touchPhase == TouchPhase::Move) touching = true;
158
160
  // Up callbacks inherit the last consumed move, while tx/ty retain the
159
161
  // consumed edge coordinates. Expose both without changing routing.
160
162
  recordConsumed(event, touching, tx, ty, !touching && wasActive_ ? lastX_ : tx,
@@ -259,3 +259,54 @@ with the preceding 164-byte candidate, this saves 648 B in TreeState and
259
259
  11,664 B of firmware. The 49-node host allocation fixture is unchanged because
260
260
  of allocator rounding; these record reductions are not a host heap saving.
261
261
  This remains a development checkpoint, not a 50-byte node or a 60 fps guarantee.
262
+
263
+
264
+ ## Inline SVG
265
+
266
+ `<svg>` and its shapes are ordinary nodes (`svg_element.h`): they take classes,
267
+ inline style, listeners and `:active`, and `getAttribute` returns full path
268
+ data. The `<svg>` box lays out like a view (its `width`/`height` attributes are
269
+ its default size; CSS wins) and records one `DrawSvg` display command. That
270
+ command rasterizes the svg's cached scene into the framebuffer with exact-area
271
+ anti-aliasing, honouring clip and opacity. Shapes are out of flow and zero-size.
272
+ The scene rebuilds once, on the next frame after anything in the subtree changes
273
+ (attribute, class, style, structure), and only the svg's box repaints.
274
+
275
+ Supported:
276
+
277
+ - Elements: `svg`, `g`, `path`, `polyline`, `polygon`, `line`, `circle`,
278
+ `ellipse` and `rect` (with `rx`/`ry`). `defs`, `title`, `desc` and `text`
279
+ are accepted and not painted.
280
+ - `viewBox` with `preserveAspectRatio` (all align values, `meet`/`slice`,
281
+ `none`).
282
+ - Path data: `M L H V C S Q T A Z`, absolute and relative, with implicit
283
+ repeats and compact arc flags. Parsing stops at the first error and keeps
284
+ what came before it, as browsers do.
285
+ - `transform` on shapes and groups: `matrix`, `translate`, `scale`,
286
+ `rotate(a [cx cy])`, `skewX` and `skewY`.
287
+ - Paint: `fill`, `stroke`, `stroke-width`, `stroke-linecap` (butt, round,
288
+ square), `stroke-linejoin` (miter, round, bevel), `stroke-miterlimit`,
289
+ `fill-rule`, `opacity`, `fill-opacity`, `stroke-opacity`, `color` with
290
+ `currentColor`, `visibility`, `display` and `pointer-events`. Colours are
291
+ hex (3, 4, 6 or 8 digits), `rgb[a]()`, `hsl[a]()`, named colours and
292
+ `transparent`.
293
+ - The same paint properties as CSS (`.slice { fill: #38bdf8; stroke-width: 3px }`,
294
+ `style={{ fill: color }}`). CSS beats presentation attributes, and the
295
+ inheritable ones inherit through `g`. Group `opacity` multiplies into each
296
+ shape; it is not composited as a layer.
297
+ - Touch: the hit test descends into the svg by geometry, either the fill's
298
+ winding or the stroke within 3px of slop. The topmost shape receives the
299
+ event, which bubbles through `g` and `svg`. `pointer-events: none` shapes
300
+ are transparent to touch.
301
+
302
+ Not supported: `<text>`, `<use>`, gradients and patterns, `clipPath`/`mask`,
303
+ markers, dashes (`stroke-dasharray`), filters, and units other than px.
304
+ `var()` in paint values is not supported either. A CSS `transform` on the
305
+ `<svg>` element itself moves its box, but the scene is not reprojected into the
306
+ transformed space.
307
+
308
+ Cost: the svg paint fields live in the pooled `RareStyle`, allocated only for
309
+ nodes that set a rare field. Ordinary nodes carry nothing new. The plugin
310
+ reports `node-svg` when the source can create an svg element (JSX `<svg>`,
311
+ `createElement('svg')`, `SVG*Element`, opaque markup). The CLI turns that into
312
+ `GEA_UI_SVG`, which compiles the whole feature out of apps that have no svg.
package/ui/input.cpp CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "pixel.h"
5
5
  #include "tree_state.h"
6
+ #include "svg_element.h"
6
7
  #include "control_commit.h"
7
8
  #include "input_retirement.h"
8
9
 
@@ -27,7 +28,7 @@
27
28
  #define GEA_SCROLL_MOMENTUM_MAX_VELOCITY 24.0f
28
29
  #endif
29
30
  #ifndef GEA_SCROLL_MOMENTUM_MIN_VELOCITY
30
- #define GEA_SCROLL_MOMENTUM_MIN_VELOCITY 0.06f
31
+ #define GEA_SCROLL_MOMENTUM_MIN_VELOCITY 0.2f
31
32
  #endif
32
33
  #ifndef GEA_SCROLL_MOMENTUM_DECAY_MS
33
34
  #define GEA_SCROLL_MOMENTUM_DECAY_MS 680.0f
@@ -106,6 +107,7 @@ public:
106
107
  carryOverVelocity_ = momentumVelocity_;
107
108
  carryOverAxis_ = momentumAxis_;
108
109
  cancelMomentum();
110
+ pointerDownMs_ = gea::framework::services::FrameScheduler::nowMs();
109
111
  activeScrollNode_ = tree.nodeCount() == 0 ? -1 : findScrollNodeId(0, x, y);
110
112
  activeScrollOwner_=NodeHandle(activeScrollNode_);
111
113
  snapAccumDy_ = 0;
@@ -516,6 +518,14 @@ private:
516
518
  if (result >= 0) return result;
517
519
  }
518
520
 
521
+ #if GEA_UI_SVG
522
+ // Inside an <svg>, the target is the topmost shape under the point, by
523
+ // its painted geometry; the svg itself when none is.
524
+ if (inside && !clipped && svg::isRoot(node)) {
525
+ const int shape = svg::hitTest(id, x, y);
526
+ if (shape >= 0) return shape;
527
+ }
528
+ #endif
519
529
  if (!inside || clipped || node.computedStyle().visibility != 0) return -1;
520
530
  return id;
521
531
  }
@@ -766,27 +776,53 @@ private:
766
776
  if (scrollNode < 0 || scrollNode >= tree.nodeCount()) return;
767
777
  if (!nodeCanScrollAxis(scrollNode, tree.node(scrollNode), axis)) return;
768
778
 
769
- // Average velocity from the oldest sample to the newest in the ring.
770
- // Using two endpoints rather than a per-sample derivative smooths
771
- // out the noisy last few touch reports right before lift-off.
772
- const int newestIdx =
773
- (velocitySampleNext_ + kVelocitySampleCount - 1) % kVelocitySampleCount;
774
- const int oldestIdx =
775
- velocitySampleCount_ < kVelocitySampleCount
776
- ? 0
777
- : velocitySampleNext_;
778
- const VelocitySample &newest = velocitySamples_[newestIdx];
779
- const VelocitySample &oldest = velocitySamples_[oldestIdx];
780
- const int dtMs = newest.timestampMs - oldest.timestampMs;
779
+ // Release velocity is the finger's speed over the last
780
+ // kVelocityWindowMs before lift-off, not over the whole ring: a flick
781
+ // that started fast and slowed before release must launch at the slow
782
+ // speed. The newest sample is the lift itself (pushed at pointer up),
783
+ // so a pause before lifting counts as standing still. The window start
784
+ // is interpolated between the two samples that straddle it, which
785
+ // keeps the estimate independent of the touch report rate.
786
+ auto sampleAt = [this](int back) -> const VelocitySample & {
787
+ return velocitySamples_[(velocitySampleNext_ + kVelocitySampleCount - 1 - back) %
788
+ kVelocitySampleCount];
789
+ };
790
+ auto along = [axis](const VelocitySample &s) {
791
+ return static_cast<float>(axis == ScrollAxis::X ? s.x : s.y);
792
+ };
793
+ const VelocitySample &newest = sampleAt(0);
794
+ const int windowStartMs = newest.timestampMs - kVelocityWindowMs;
795
+ int dtMs = 0;
796
+ float deltaF = 0.0f;
797
+ for (int back = 1; back < velocitySampleCount_; back++) {
798
+ const VelocitySample &older = sampleAt(back);
799
+ if (older.timestampMs > windowStartMs && back + 1 < velocitySampleCount_) continue;
800
+ if (older.timestampMs >= windowStartMs) {
801
+ // The ring does not reach back a whole window: use what it holds.
802
+ dtMs = newest.timestampMs - older.timestampMs;
803
+ deltaF = along(newest) - along(older);
804
+ break;
805
+ }
806
+ const VelocitySample &newer = sampleAt(back - 1);
807
+ const int span = newer.timestampMs - older.timestampMs;
808
+ const float t = span > 0
809
+ ? static_cast<float>(windowStartMs - older.timestampMs) / span
810
+ : 1.0f;
811
+ const float startPos = along(older) + (along(newer) - along(older)) * t;
812
+ dtMs = kVelocityWindowMs;
813
+ deltaF = along(newest) - startPos;
814
+ break;
815
+ }
781
816
  if (dtMs <= 0) return;
782
817
 
783
818
  const int nowMs = gea::framework::services::FrameScheduler::nowMs();
784
819
 
785
- const int delta = axis == ScrollAxis::X ? newest.x - oldest.x : newest.y - oldest.y;
786
- float velocityPxPerMs = static_cast<float>(delta) / static_cast<float>(dtMs);
820
+ const int delta = static_cast<int>(deltaF);
821
+ float velocityPxPerMs = deltaF / static_cast<float>(dtMs);
787
822
 
788
- // Below ~0.06 px/ms = 60 px/sec, the fling is so weak it'd stop in a
789
- // frame or two — not worth the tick overhead and visually a no-op.
823
+ // Below ~0.2 px/ms = 200 px/sec over the release window the finger was
824
+ // not flicking: a finger that stopped still rolls a few px as it lifts,
825
+ // and launching that roll reads as the list moving on by itself.
790
826
  // A tap (no drag, weak velocity) also lands here, which is what we
791
827
  // want: a tap should NOT resume a stashed fling.
792
828
  if (std::fabs(velocityPxPerMs) < kMinFlingVelocity) {
@@ -805,7 +841,11 @@ private:
805
841
  // the new flick goes in the same direction, add the leftover
806
842
  // velocity to the new one. Opposite direction → user is reversing
807
843
  // course, drop the stash.
844
+ // Only a quick re-flick carries: a finger that caught the fling and held
845
+ // or dragged slowly before lifting would otherwise launch faster than
846
+ // it moved.
808
847
  if (carryOverAxis_ == axis && carryOverVelocity_ != 0.0f &&
848
+ nowMs - pointerDownMs_ <= kCarryOverWindowMs &&
809
849
  (carryOverVelocity_ > 0.0f) == (velocityPxPerMs > 0.0f)) {
810
850
  velocityPxPerMs += carryOverVelocity_ * kCarryOverBoost;
811
851
  }
@@ -843,9 +883,11 @@ private:
843
883
  int x;
844
884
  int y;
845
885
  };
846
- static constexpr int kVelocitySampleCount = 5;
886
+ static constexpr int kVelocitySampleCount = 8;
887
+ static constexpr int kVelocityWindowMs = 50;
847
888
  static constexpr float kLaunchVelocityBoost = GEA_SCROLL_MOMENTUM_LAUNCH_BOOST;
848
889
  static constexpr float kCarryOverBoost = GEA_SCROLL_MOMENTUM_CARRY_BOOST;
890
+ static constexpr int kCarryOverWindowMs = 250;
849
891
  static constexpr float kMaxMomentumVelocity = GEA_SCROLL_MOMENTUM_MAX_VELOCITY; // px/ms
850
892
  static constexpr float kMinFlingVelocity = GEA_SCROLL_MOMENTUM_MIN_VELOCITY; // px/ms
851
893
  static constexpr float kMomentumDecayMs = GEA_SCROLL_MOMENTUM_DECAY_MS;
@@ -877,6 +919,7 @@ private:
877
919
  // Folded into the next flick if same-direction so successive flicks
878
920
  // accelerate (iOS-style).
879
921
  float carryOverVelocity_ = 0.0f;
922
+ int pointerDownMs_ = 0;
880
923
  ScrollAxis carryOverAxis_ = ScrollAxis::None;
881
924
  };
882
925
 
package/ui/internal.h CHANGED
@@ -73,7 +73,9 @@ void rootScrollImageHoldTick();
73
73
  BeginFilterBlur,
74
74
  ApplyFilterBlur,
75
75
  FillTransformedLinearGradient,
76
- FillTransformedRoundedRect
76
+ FillTransformedRoundedRect,
77
+ // Inline <svg>: rasterizes the svg node's cached scene (svg_element.h).
78
+ DrawSvg
77
79
  };
78
80
 
79
81
  struct DisplayCommand
@@ -111,6 +113,7 @@ void rootScrollImageHoldTick();
111
113
  gea::framework::graphics::pixel::native_t color;
112
114
  } fill;
113
115
  struct { int16_t nodeId, x, y, width, height; std::uint32_t identity; } canvasBatch;
116
+ struct { int16_t nodeId, x, y, w, h; } svg;
114
117
  struct
115
118
  {
116
119
  int16_t cx, cy, r;
@@ -578,6 +581,8 @@ void rootScrollImageHoldTick();
578
581
  static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
579
582
  static int firstUnbreakableWidth(const Node &node);
580
583
  static int minContentWidth(const Node &node, int *pendingWord = nullptr);
584
+ // The run laid out on one line (no soft wraps): CSS max-content width.
585
+ static int maxContentWidth(const Node &node);
581
586
  static int measureHeight(const char *text, int fontId, int fontSize, int textTransform = 0, int lineHeight = 0);
582
587
  // In-place box re-measure for a rebound text node on refresh paths that
583
588
  // skip the layout pass (root-scroll fast path): record() wraps and clips
package/ui/layout.cpp CHANGED
@@ -324,6 +324,15 @@ bool hasFlexBasis(const Node &node)
324
324
  return node.computedStyle().flex_basis != kUnset || rstyle(node.computedStyle()).flex_basis_expression >= 0;
325
325
  }
326
326
 
327
+ // CSS 2 10.3.7/10.6.4: an out-of-flow box with both insets on an axis and an
328
+ // auto size there takes its used size from the containing block. That size is
329
+ // definite before the box's content is laid out, so size the box up front:
330
+ // shrinking it to its content and stretching it afterwards laid every
331
+ // positioned descendant out against the content-sized box and then again
332
+ // against the stretched one -- twice per nesting level of `inset: 0` panels.
333
+ bool insetStretched(const Node &node, bool horizontal);
334
+ int insetStretchedBorderSize(const Node &node, bool horizontal, int basis);
335
+
327
336
  bool hasExplicitWidth(const Node &node)
328
337
  {
329
338
  if (const auto *basis = flexBasisScope(node, true)) return basis->value != kUnset;
@@ -333,6 +342,7 @@ bool hasExplicitWidth(const Node &node)
333
342
  return scope && scope->constraint == 0;
334
343
  }
335
344
  if (node.computedStyle().width != kUnset) return true;
345
+ if (insetStretched(node, true)) return true;
336
346
  if (intrinsicWidthConstraint(node)) return false;
337
347
  return node.computedStyle().width_expression >= 0 || node.computedStyle().width_percent != kUnset;
338
348
  }
@@ -373,6 +383,7 @@ bool hasExplicitHeight(const Node &node)
373
383
  if (const auto *basis = flexBasisScope(node, false)) return basis->value != kUnset;
374
384
  if (const auto *scope = intrinsicSizeScope(node, false); scope && scope->constraint == 0) return true;
375
385
  if (node.computedStyle().height != kUnset) return true;
386
+ if (insetStretched(node, false)) return true;
376
387
  if (intrinsicSizeConstraint(node, false)) return false;
377
388
  if (node.computedStyle().height_expression < 0 && node.computedStyle().height_percent == kUnset) return false;
378
389
  if (!percentageHeightDependsOnIntrinsicSize(node)) return true;
@@ -386,6 +397,8 @@ int resolvedStyleWidth(const Node &node, int basis)
386
397
  if (const auto *scope = intrinsicSizeScope(node, true); scope && scope->constraint == 0)
387
398
  return std::max(0, scope->borderSize - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), true) : 0));
388
399
  if (!hasExplicitWidth(node)) return basis;
400
+ if (insetStretched(node, true))
401
+ return insetStretchedBorderSize(node, true, basis) - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), true) : 0);
389
402
  if (node.computedStyle().width_expression >= 0) return resolveLayoutSizeExpression(static_cast<int>(&node - Tree::instance().nodes()), node.computedStyle().width_expression, true);
390
403
  if (node.computedStyle().width != kUnset) return node.computedStyle().width;
391
404
  if (node.computedStyle().width_percent != kUnset) return resolvePercentSize(basis, node.computedStyle().width_percent);
@@ -398,6 +411,8 @@ int resolvedStyleHeight(const Node &node, int basis)
398
411
  if (const auto *scope = intrinsicSizeScope(node, false); scope && scope->constraint == 0)
399
412
  return std::max(0, scope->borderSize - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), false) : 0));
400
413
  if (!hasExplicitHeight(node)) return basis;
414
+ if (insetStretched(node, false))
415
+ return insetStretchedBorderSize(node, false, basis) - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), false) : 0);
401
416
  if (node.computedStyle().height_expression >= 0) return resolveLayoutSizeExpression(static_cast<int>(&node - Tree::instance().nodes()), node.computedStyle().height_expression, false);
402
417
  if (node.computedStyle().height != kUnset) return node.computedStyle().height;
403
418
  if (node.computedStyle().height_percent != kUnset && !percentageHeightDependsOnIntrinsicSize(node))
@@ -1770,9 +1785,18 @@ private:
1770
1785
  const Node &grand = nodes[c];
1771
1786
  if (isLayoutExcluded(grand) || isOutOfFlowPosition(grand.computedStyle().position)) continue;
1772
1787
  // layout.{x,y} are still parent-relative here: resolveAbsoluteCoords runs
1773
- // after the whole layout pass.
1788
+ // after the whole layout pass. A text run's laid-out box is its line box,
1789
+ // as wide as the space it was offered (and offset by text-align), so it
1790
+ // would floor the item at the whole row -- `<div>BACK</div>` beside a
1791
+ // title never shrank and three `flex: 1` buttons each grew to the full
1792
+ // row. Its contribution is its fit-content width: max-content, capped at
1793
+ // that line box. Min-content alone is too small for a run that wraps --
1794
+ // "AV AV" offered 22px measures its widest line, 18px, while CSS keeps
1795
+ // the item at the 22px it shrank to from its max-content basis.
1774
1796
  const int end = isRow_
1775
- ? grand.layout.x + grand.layout.width + grand.computedStyle().margin[1]
1797
+ ? (grand.type == NodeType::Text
1798
+ ? boxInset(childNode.computedStyle(), 3) + std::min<int>(TextRenderer::maxContentWidth(grand), grand.layout.width)
1799
+ : grand.layout.x + grand.layout.width + grand.computedStyle().margin[1])
1776
1800
  : grand.layout.y + grand.layout.height + grand.computedStyle().margin[2];
1777
1801
  if (end > extent) extent = end;
1778
1802
  }
@@ -3638,6 +3662,30 @@ int resolvedPositionOffsetForBasis(const Node &node, int percentBasis)
3638
3662
  return offset;
3639
3663
  }
3640
3664
 
3665
+ bool insetStretched(const Node &node, bool horizontal)
3666
+ {
3667
+ const ComputedStyle &style = node.computedStyle();
3668
+ if (node.type != NodeType::View || !isOutOfFlowPosition(style.position) || isLayoutExcluded(node)) return false;
3669
+ if (horizontal ? style.width != kUnset || style.width_expression >= 0 || style.width_percent != kUnset ||
3670
+ isIntrinsicSizeExpression(style.width_expression)
3671
+ : style.height != kUnset || style.height_expression >= 0 || style.height_percent != kUnset ||
3672
+ isIntrinsicSizeExpression(style.height_expression)) return false;
3673
+ if (intrinsicSizeScope(node, horizontal) || flexBasisScope(node, horizontal) || preferredRatio(node) > 0) return false;
3674
+ return horizontal ? hasPositionOffsetValue<3>(node) && hasPositionOffsetValue<1>(node)
3675
+ : hasPositionOffsetValue<0>(node) && hasPositionOffsetValue<2>(node);
3676
+ }
3677
+
3678
+ // Border-box size of an inset-stretched box in a containing block `basis` wide
3679
+ // (or tall); the same arithmetic as stretchAbsoluteNodeToContainingBlock.
3680
+ int insetStretchedBorderSize(const Node &node, bool horizontal, int basis)
3681
+ {
3682
+ const ComputedStyle &style = node.computedStyle();
3683
+ const int size = horizontal
3684
+ ? basis - resolvedPositionOffsetForBasis<3>(node, basis) - resolvedPositionOffsetForBasis<1>(node, basis) - style.margin[1] - style.margin[3]
3685
+ : basis - resolvedPositionOffsetForBasis<0>(node, basis) - resolvedPositionOffsetForBasis<2>(node, basis) - style.margin[0] - style.margin[2];
3686
+ return std::max(size, boxInsets(style, horizontal));
3687
+ }
3688
+
3641
3689
  void offsetFromAncestorToNode(int ancestor, int node, Node *nodes, int *outX, int *outY)
3642
3690
  {
3643
3691
  int x = 0;
@@ -4131,6 +4179,7 @@ static_assert(sizeof(LayoutPassMemo) == 10);
4131
4179
  LayoutPassMemo *gLayoutMemo = nullptr;
4132
4180
  int gLayoutMemoCapacity = 0;
4133
4181
  std::size_t gLayoutMemoPeakBytes = 0;
4182
+
4134
4183
  } // namespace
4135
4184
 
4136
4185
  void LayoutEngine::beginLayoutPass()
@@ -29,6 +29,12 @@ static_assert(GEA_UI_CLASS_INLINE_TOKENS >= 1 && GEA_UI_CLASS_INLINE_TOKENS <= 4
29
29
 
30
30
  // Closed whole-source auxiliary-state proof. Unknown/older programs keep all
31
31
  // owners; callers cannot prune these through application manifest switches.
32
+ // Inline <svg>: the element, its scene cache and the SVG paint properties in
33
+ // RareStyle. The plugin proves absence (node-svg); unknown programs keep it.
34
+ #ifndef GEA_UI_SVG
35
+ #define GEA_UI_SVG 1
36
+ #endif
37
+
32
38
  #ifndef GEA_UI_NODE_LISTENERS
33
39
  #define GEA_UI_NODE_LISTENERS 1
34
40
  #endif
package/ui/node_model.h CHANGED
@@ -161,6 +161,22 @@ inline bool isNativeButtonNodeType(NodeType type)
161
161
  // BEFORE ComputedStyle so it can be a by-value member).
162
162
  struct RareStyle {
163
163
  bool operator==(const RareStyle &) const = default;
164
+ #if GEA_UI_SVG
165
+ // SVG paint. Unset (0 / -1) means "inherit from the SVG parent"; the scene
166
+ // resolver walks the svg subtree, so no inheritance machinery runs for them.
167
+ int32_t svg_fill = 0; // svg::encodePaint
168
+ int32_t svg_stroke = 0; // svg::encodePaint
169
+ int32_t svg_stroke_width = -1; // px * 100
170
+ int16_t svg_fill_opacity = -1; // 0..1000
171
+ int16_t svg_stroke_opacity = -1; // 0..1000
172
+ int8_t svg_stroke_linecap = -1; // svg::LineCap
173
+ int8_t svg_stroke_linejoin = -1; // svg::LineJoin
174
+ int8_t svg_fill_rule = -1; // 0 nonzero, 1 evenodd
175
+ #else
176
+ static constexpr int32_t svg_fill = 0, svg_stroke = 0, svg_stroke_width = -1;
177
+ static constexpr int16_t svg_fill_opacity = -1, svg_stroke_opacity = -1;
178
+ static constexpr int8_t svg_stroke_linecap = -1, svg_stroke_linejoin = -1, svg_fill_rule = -1;
179
+ #endif
164
180
  // Logical edges: block-start/end, inline-start/end.
165
181
  #if GEA_CSS_MARGIN_TRIM
166
182
  uint8_t margin_trim = 0;
@@ -494,7 +510,7 @@ inline int composedTranslateZ(const RareStyle &s) { return int(s.transform_trans
494
510
  inline int composedTranslateXPercent(const RareStyle &s) { return int(s.transform_translate_x_percent) + s.translate_x_percent; }
495
511
  inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transform_translate_y_percent) + s.translate_y_percent; }
496
512
 
497
- #define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS)
513
+ #define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS || GEA_UI_SVG)
498
514
  static_assert(GEA_CSS_RARE_STYLE || std::is_empty<RareStyle>::value, "An unguarded rare field requires a reachability family");
499
515
 
500
516
  struct ComputedStyle {