@geastack/engine 0.1.20 → 0.1.22

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.
@@ -980,20 +980,18 @@ void CanvasRenderingContext2D::drawImage(int imageId, int dx, int dy, int dw, in
980
980
  gCanvasPerfStats.drawImageUs += nowUs() - started;
981
981
  }
982
982
  void CanvasRenderingContext2D::drawImage(int imageId, double x, double y, double w, double h) { drawImage(imageId, rounded(x), rounded(y), rounded(w), rounded(h)); }
983
+ // Measuring reads font metrics only. Asking for a drawing surface here would
984
+ // replay the batch recorded so far and drop it off the display present path.
983
985
  double CanvasRenderingContext2D::measureTextInkCenter(const std::string &text)
984
986
  {
985
- auto *surface = drawingCanvas();
986
- if (!surface) surface = canvas();
987
- if (!surface) return 0.0;
988
- return static_cast<double>(surface->measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
987
+ return static_cast<double>(
988
+ gea::framework::graphics::Canvas::measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
989
989
  }
990
990
 
991
991
  double CanvasRenderingContext2D::measureText(const std::string &text)
992
992
  {
993
- auto *surface = drawingCanvas();
994
- if (!surface) surface = canvas();
995
- if (!surface) return 0.0;
996
- return static_cast<double>(surface->measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
993
+ return static_cast<double>(
994
+ gea::framework::graphics::Canvas::measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
997
995
  }
998
996
 
999
997
  void CanvasRenderingContext2D::drawImageCircle(int imageId, int dx, int dy, int dw, int dh)
@@ -2350,20 +2348,18 @@ void CanvasRenderingContext2D::drawImage(int imageId, double dx, double dy, doub
2350
2348
  drawImage(imageId, rounded(dx), rounded(dy), rounded(dw), rounded(dh));
2351
2349
  }
2352
2350
 
2351
+ // Measuring reads font metrics only. Asking for a drawing surface here would
2352
+ // replay the batch recorded so far and drop it off the display present path.
2353
2353
  double CanvasRenderingContext2D::measureTextInkCenter(const std::string &text)
2354
2354
  {
2355
- auto *surface = drawingCanvas();
2356
- if (!surface) surface = canvas();
2357
- if (!surface) return 0.0;
2358
- return static_cast<double>(surface->measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
2355
+ return static_cast<double>(
2356
+ gea::framework::graphics::Canvas::measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
2359
2357
  }
2360
2358
 
2361
2359
  double CanvasRenderingContext2D::measureText(const std::string &text)
2362
2360
  {
2363
- auto *surface = drawingCanvas();
2364
- if (!surface) surface = canvas();
2365
- if (!surface) return 0.0;
2366
- return static_cast<double>(surface->measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
2361
+ return static_cast<double>(
2362
+ gea::framework::graphics::Canvas::measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
2367
2363
  }
2368
2364
 
2369
2365
  void CanvasRenderingContext2D::drawImageCircle(int imageId, int dx, int dy, int dw, int dh)
package/ui/core.cpp CHANGED
@@ -130,13 +130,16 @@ bool Tree::refreshRequired() const
130
130
  }
131
131
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
132
132
  if (!reason && !Document::directCanvasContextUsed()) {
133
- const int root = state.mountedRoot;
134
- const bool displayBackedCanvasRoot =
135
- root >= 0 &&
136
- root < state.nodeCount &&
137
- state.nodes[root].type == NodeType::Canvas &&
138
- isDisplayBackedCanvas(root);
139
- if (!displayBackedCanvasRoot) {
133
+ // A display-backed canvas owns every display pixel (it is only granted
134
+ // when it covers the panel and nothing else draws), so the display's dirty
135
+ // box says nothing a refresh could repaint. Reading it is not free either:
136
+ // a double-buffered panel's canvas() waits for the scanout to release the
137
+ // buffer just swapped in, which stalled every frame of a full-screen canvas
138
+ // app under a wrapper element by up to two panel periods.
139
+ bool displayBackedCanvas = false;
140
+ for (int i = 0; i < state.nodeCount && !displayBackedCanvas; i++)
141
+ displayBackedCanvas = state.nodes[i].type == NodeType::Canvas && isDisplayBackedCanvas(i);
142
+ if (!displayBackedCanvas) {
140
143
  if (auto *canvas = gea::platform::display::Display::canvas()) {
141
144
  if (canvas->dirty(nullptr, nullptr, nullptr, nullptr)) reason = 3;
142
145
  }
package/ui/document.cpp CHANGED
@@ -320,6 +320,7 @@ namespace
320
320
  gea::framework::display::Underlay::Paint underlayPaint = nullptr;
321
321
  void *underlayUser = nullptr;
322
322
  int underlayX0 = 0, underlayY0 = 0, underlayX1 = -1, underlayY1 = -1;
323
+ bool underlayOpaque = false;
323
324
  } // namespace
324
325
 
325
326
  bool gea::framework::display::Underlay::composited()
@@ -335,12 +336,24 @@ void gea::framework::display::Underlay::set(Paint paint, void *user, int x0, int
335
336
  underlayY0 = y0;
336
337
  underlayX1 = x1;
337
338
  underlayY1 = y1;
339
+ underlayOpaque = false;
340
+ }
341
+
342
+ void gea::framework::display::Underlay::setOpaque(bool opaque)
343
+ {
344
+ underlayOpaque = opaque;
345
+ }
346
+
347
+ bool gea::framework::display::Underlay::covers(int x0, int y0, int x1, int y1)
348
+ {
349
+ return underlayPaint && underlayOpaque && x0 >= underlayX0 && y0 >= underlayY0 && x1 <= underlayX1 && y1 <= underlayY1;
338
350
  }
339
351
 
340
352
  void gea::framework::display::Underlay::clear()
341
353
  {
342
354
  underlayPaint = nullptr;
343
355
  underlayUser = nullptr;
356
+ underlayOpaque = false;
344
357
  }
345
358
 
346
359
  bool gea::framework::display::Underlay::active()
@@ -357,4 +370,16 @@ void gea::framework::display::Underlay::paint(int x0, int y0, int x1, int y1)
357
370
  y1 = std::min(y1, underlayY1);
358
371
  if (x0 > x1 || y0 > y1) return;
359
372
  underlayPaint(x0, y0, x1, y1, underlayUser);
373
+ // The painter writes pixels directly, so the canvas has no record of them.
374
+ // A display that stages the replay in a strip copies back only the canvas's
375
+ // dirty box, which left the frame black under everything but the HUD text.
376
+ if (auto *canvas = gea::platform::display::Display::canvas()) {
377
+ int cx0 = 0, cy0 = 0, cx1 = -1, cy1 = -1;
378
+ canvas->currentClip(&cx0, &cy0, &cx1, &cy1);
379
+ x0 = std::max(x0, cx0);
380
+ y0 = std::max(y0, cy0);
381
+ x1 = std::min(x1, cx1);
382
+ y1 = std::min(y1, cy1);
383
+ if (x0 <= x1 && y0 <= y1) canvas->markDirty(x0, y0, x1, y1);
384
+ }
360
385
  }
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
 
@@ -11,6 +12,7 @@
11
12
  #include <algorithm>
12
13
  #include <cmath>
13
14
  #include <cstdint>
15
+ #include <cstring>
14
16
  #include <cstdio>
15
17
  #include <cstdlib>
16
18
  #include <cstring>
@@ -110,6 +112,8 @@ public:
110
112
  activeScrollNode_ = tree.nodeCount() == 0 ? -1 : findScrollNodeId(0, x, y);
111
113
  activeScrollOwner_=NodeHandle(activeScrollNode_);
112
114
  snapAccumDy_ = 0;
115
+ downX_ = x;
116
+ downY_ = y;
113
117
  activeScrollAxis_ = ScrollAxis::None;
114
118
  scrollLastX_ = x;
115
119
  scrollLastY_ = y;
@@ -179,7 +183,7 @@ public:
179
183
  return 0;
180
184
  }
181
185
 
182
- Node &node = tree.nodes()[activeScrollNode_];
186
+ const Node &innerNode = tree.nodes()[activeScrollNode_];
183
187
  const int dx = x - scrollLastX_;
184
188
  const int dy = y - scrollLastY_;
185
189
  scrollLastX_ = x;
@@ -190,17 +194,57 @@ public:
190
194
  pushVelocitySample(x, y);
191
195
  if (dx == 0 && dy == 0) return 0;
192
196
 
193
- const bool canScrollX = nodeCanScrollX(activeScrollNode_, node);
194
- const bool canScrollY = nodeCanScrollY(activeScrollNode_, node);
195
197
  if (activeScrollAxis_ == ScrollAxis::None) {
196
- const int absDx = std::abs(dx);
197
- const int absDy = std::abs(dy);
198
- if (canScrollX && (!canScrollY || absDx >= absDy)) {
199
- activeScrollAxis_ = ScrollAxis::X;
200
- } else if (canScrollY) {
201
- activeScrollAxis_ = ScrollAxis::Y;
198
+ // Decide the axis from the whole movement since the finger landed,
199
+ // once it has moved far enough to tell (LVGL's scroll limit), and
200
+ // hand the gesture to the scroller that can actually take it: the
201
+ // innermost one, or the nearest ancestor when the inner one cannot
202
+ // scroll that way (a vertical page inside a horizontal pager), or is
203
+ // already at its end in the drag's direction (LVGL's scroll chain).
204
+ const int tx = x - downX_;
205
+ const int ty = y - downY_;
206
+ if (std::abs(tx) <= kAxisSlopPx && std::abs(ty) <= kAxisSlopPx) return 0;
207
+ const ScrollAxis want = std::abs(tx) > std::abs(ty) ? ScrollAxis::X : ScrollAxis::Y;
208
+ const int sign = want == ScrollAxis::X ? (tx > 0 ? 1 : -1) : (ty > 0 ? 1 : -1);
209
+ int chosen = -1;
210
+ ScrollAxis chosenAxis = ScrollAxis::None;
211
+ int fallback = -1;
212
+ for (int current = activeScrollNode_; current >= 0 && current < tree.nodeCount();
213
+ current = tree.node(current).parent) {
214
+ const Node &candidate = tree.node(current);
215
+ if (!nodeCanScrollAxis(current, candidate, want)) continue;
216
+ if (fallback < 0) fallback = current;
217
+ if (canScrollToward(current, candidate, want, sign)) {
218
+ chosen = current;
219
+ chosenAxis = want;
220
+ break;
221
+ }
222
+ }
223
+ if (chosen < 0 && fallback >= 0) {
224
+ chosen = fallback;
225
+ chosenAxis = want;
226
+ }
227
+ if (chosen < 0) {
228
+ // Nothing scrolls along the drag: the inner scroller takes the
229
+ // other axis if it has one, as before.
230
+ const ScrollAxis other = want == ScrollAxis::X ? ScrollAxis::Y : ScrollAxis::X;
231
+ if (nodeCanScrollAxis(activeScrollNode_, innerNode, other)) {
232
+ chosen = activeScrollNode_;
233
+ chosenAxis = other;
234
+ }
235
+ }
236
+ if (chosen < 0) return 0;
237
+ if (chosen != activeScrollNode_) {
238
+ activeScrollNode_ = chosen;
239
+ activeScrollOwner_ = NodeHandle(chosen);
202
240
  }
241
+ activeScrollAxis_ = chosenAxis;
242
+ if (snapNode_ == chosen) cancelSnap();
243
+ gestureStartScroll_ = chosenAxis == ScrollAxis::X ? scrollLeft(chosen) : scrollTop(chosen);
203
244
  }
245
+ Node &node = tree.nodes()[activeScrollNode_];
246
+ const bool canScrollX = nodeCanScrollX(activeScrollNode_, node);
247
+ const bool canScrollY = nodeCanScrollY(activeScrollNode_, node);
204
248
 
205
249
  bool changed = false;
206
250
  if (dx != 0 && canScrollX && activeScrollAxis_ == ScrollAxis::X) {
@@ -280,6 +324,13 @@ public:
280
324
  return -1;
281
325
  }
282
326
  snapAccumDy_ = 0;
327
+ if (scrollNode >= 0 && scrollAxis != ScrollAxis::None && nodeSnapsToPages(scrollNode)) {
328
+ pushVelocitySample(scrollLastX_, scrollLastY_);
329
+ settleOnPage(scrollNode, scrollAxis);
330
+ resetVelocitySamples();
331
+ if (activeTouchNode_ >= 0) clearActiveTouch();
332
+ return -1;
333
+ }
283
334
  if (scrollNode >= 0 && nodeHasMomentumOptIn(scrollNode)) {
284
335
  pushVelocitySample(scrollLastX_, scrollLastY_);
285
336
  startMomentum(scrollNode, scrollAxis);
@@ -339,6 +390,7 @@ public:
339
390
  scrollLastX_ = 0;
340
391
  scrollLastY_ = 0;
341
392
  resetVelocitySamples();
393
+ cancelSnap();
342
394
  cancelMomentum();
343
395
  carryOverVelocity_ = 0.0f;
344
396
  carryOverAxis_ = ScrollAxis::None;
@@ -355,6 +407,7 @@ public:
355
407
  auto leaving=[&](const NodeHandle &owner){return inputOwnerLeaving(owner,removed,retained);};
356
408
  if(leaving(activeTouchOwner_) || leaving(activeScrollOwner_)) cancelActiveGesture();
357
409
  if(leaving(momentumOwner_)) cancelMomentum();
410
+ if(leaving(snapOwner_)) cancelSnap();
358
411
  if(leaving(hoveredOwner_)){treeState().hoveredNodeId=-1;hoveredOwner_={};StyleSheet::instance().hoverChanged();}
359
412
  }
360
413
 
@@ -363,6 +416,7 @@ public:
363
416
 
364
417
  void tick(int timestampMs)
365
418
  {
419
+ if (snapNode_ >= 0) tickSnap(timestampMs);
366
420
  if (momentumNode_ < 0) return;
367
421
  Tree &tree = Tree::instance();
368
422
  if (!momentumOwner_.valid() || momentumOwner_.id()!=momentumNode_) {
@@ -438,6 +492,158 @@ public:
438
492
  }
439
493
  }
440
494
 
495
+ // Page snapping (the `snap-page` attribute): a scroller whose pages are its
496
+ // own width (horizontal) or height (vertical) -- LVGL's tabview content,
497
+ // which scrolls one page per swipe and settles on a page edge.
498
+ bool nodeSnapsToPages(int nodeId) const
499
+ {
500
+ Tree &tree = Tree::instance();
501
+ if (nodeId < 0 || nodeId >= tree.nodeCount()) return false;
502
+ return tree.hasAttribute(nodeId, "snap-page");
503
+ }
504
+
505
+ // Animate a scroller to `target` along `axis` with LVGL's scroll animation:
506
+ // an ease-out over 200-400 ms, at 400 px/s between those bounds.
507
+ void startSnap(int nodeId, ScrollAxis axis, int target)
508
+ {
509
+ Tree &tree = Tree::instance();
510
+ if (nodeId < 0 || nodeId >= tree.nodeCount() || axis == ScrollAxis::None) return;
511
+ const int from = axis == ScrollAxis::X ? scrollLeft(nodeId) : scrollTop(nodeId);
512
+ cancelSnap();
513
+ if (from == target) {
514
+ dispatchScrollSettled(nodeId);
515
+ return;
516
+ }
517
+ int duration = std::abs(target - from) * 1000 / kSnapSpeedPxPerS;
518
+ if (duration < kSnapMinMs) duration = kSnapMinMs;
519
+ if (duration > kSnapMaxMs) duration = kSnapMaxMs;
520
+ snapNode_ = nodeId;
521
+ snapOwner_ = NodeHandle(nodeId);
522
+ snapAxis_ = axis;
523
+ snapFrom_ = from;
524
+ snapTo_ = target;
525
+ snapStartMs_ = gea::framework::services::FrameScheduler::nowMs();
526
+ snapDurationMs_ = duration;
527
+ treeState().inputTickRequired = true;
528
+ }
529
+
530
+ void cancelSnap()
531
+ {
532
+ snapNode_ = -1;
533
+ snapOwner_ = {};
534
+ snapAxis_ = ScrollAxis::None;
535
+ treeState().inputTickRequired = momentumNode_ >= 0;
536
+ }
537
+
538
+ void tickSnap(int timestampMs)
539
+ {
540
+ if (!snapOwner_.valid() || snapOwner_.id() != snapNode_) {
541
+ cancelSnap();
542
+ return;
543
+ }
544
+ const int node = snapNode_;
545
+ int elapsed = timestampMs - snapStartMs_;
546
+ if (elapsed < 0) elapsed = 0;
547
+ const bool done = elapsed >= snapDurationMs_;
548
+ const float t = done ? 1.0f : static_cast<float>(elapsed) / static_cast<float>(snapDurationMs_);
549
+ const float eased = 1.0f - (1.0f - t) * (1.0f - t);
550
+ const int next = snapFrom_ + static_cast<int>(std::lround(static_cast<float>(snapTo_ - snapFrom_) * eased));
551
+ if (snapAxis_ == ScrollAxis::X) setScrollLeft(node, next);
552
+ else setScrollTop(node, next);
553
+ if (done) {
554
+ cancelSnap();
555
+ dispatchScrollSettled(node);
556
+ }
557
+ }
558
+
559
+ // The page a released drag settles on: the nearest page edge, or the next
560
+ // page in the fling's direction, never more than one page from where the
561
+ // drag started.
562
+ void settleOnPage(int nodeId, ScrollAxis axis)
563
+ {
564
+ Tree &tree = Tree::instance();
565
+ const Node &node = tree.node(nodeId);
566
+ const int page = axis == ScrollAxis::X ? node.layout.width : node.layout.height;
567
+ if (page <= 0) return;
568
+ const int cur = axis == ScrollAxis::X ? scrollLeft(nodeId) : scrollTop(nodeId);
569
+ const int maxScroll = axis == ScrollAxis::X ? scrollMaxX(nodeId, node) : scrollMaxY(nodeId, node);
570
+ const int lastPage = (maxScroll + page / 2) / page;
571
+ const int startPage = (gestureStartScroll_ + page / 2) / page;
572
+ int target = (cur + page / 2) / page;
573
+ // A sixth of a page of drag turns the page, whichever way it went: half
574
+ // a page (400 px on an 800 px pager) asked for a swipe nearly across
575
+ // the screen.
576
+ const int turn = page / kPageTurnDivisor;
577
+ if (cur - gestureStartScroll_ >= turn) target = startPage + 1;
578
+ else if (gestureStartScroll_ - cur >= turn) target = startPage - 1;
579
+ const float v = releaseVelocity(axis);
580
+ if (v < -kPageFlingVelocity) target = startPage + 1;
581
+ else if (v > kPageFlingVelocity) target = startPage - 1;
582
+ if (target > startPage + 1) target = startPage + 1;
583
+ if (target < startPage - 1) target = startPage - 1;
584
+ if (target < 0) target = 0;
585
+ if (target > lastPage) target = lastPage;
586
+ int targetScroll = target * page;
587
+ if (targetScroll > maxScroll) targetScroll = maxScroll;
588
+ startSnap(nodeId, axis, targetScroll);
589
+ }
590
+
591
+ // The finger's speed along `axis` over the last 100 ms, px/ms.
592
+ float releaseVelocity(ScrollAxis axis) const
593
+ {
594
+ if (velocitySampleCount_ < 2) return 0.0f;
595
+ auto sampleAt = [this](int back) -> const VelocitySample & {
596
+ return velocitySamples_[(velocitySampleNext_ + kVelocitySampleCount - 1 - back) % kVelocitySampleCount];
597
+ };
598
+ const VelocitySample &newest = sampleAt(0);
599
+ const VelocitySample *oldest = &newest;
600
+ for (int back = 1; back < velocitySampleCount_; back++) {
601
+ const VelocitySample &s = sampleAt(back);
602
+ if (newest.timestampMs - s.timestampMs > 100) break;
603
+ oldest = &s;
604
+ }
605
+ const int dt = newest.timestampMs - oldest->timestampMs;
606
+ if (dt <= 0) return 0.0f;
607
+ const int d = axis == ScrollAxis::X ? newest.x - oldest->x : newest.y - oldest->y;
608
+ return static_cast<float>(d) / static_cast<float>(dt);
609
+ }
610
+
611
+ static void dispatchScrollSettled(int nodeId)
612
+ {
613
+ Tree &tree = Tree::instance();
614
+ if (!tree.hasListenersForType("scroll")) return;
615
+ gea::framework::events::PointerEvent event{};
616
+ event.type = gea::framework::events::PointerEventType::Scroll;
617
+ event.targetId = nodeId;
618
+ event.bubbles = false;
619
+ event.cancelable = false;
620
+ tree.dispatchEvent(event);
621
+ }
622
+
623
+ // Whether the scroller has room to move content the way a finger moving in
624
+ // direction `sign` (+1 right/down, -1 left/up) drags it.
625
+ static bool canScrollToward(int nodeId, const Node &node, ScrollAxis axis, int sign)
626
+ {
627
+ const int cur = axis == ScrollAxis::X ? scrollLeft(nodeId) : scrollTop(nodeId);
628
+ const int maxScroll = axis == ScrollAxis::X ? scrollMaxX(nodeId, node) : scrollMaxY(nodeId, node);
629
+ return sign > 0 ? cur > 0 : cur < maxScroll;
630
+ }
631
+
632
+ public:
633
+ // Programmatic scroll of a `snap-page` scroller: animate rather than jump,
634
+ // the way LVGL's tabview animates to a tab picked from its buttons.
635
+ bool animateProgrammaticScroll(int nodeId, bool horizontal, int target)
636
+ {
637
+ if (!nodeSnapsToPages(nodeId)) return false;
638
+ Tree &tree = Tree::instance();
639
+ const Node &node = tree.node(nodeId);
640
+ const int maxScroll = horizontal ? scrollMaxX(nodeId, node) : scrollMaxY(nodeId, node);
641
+ if (target < 0) target = 0;
642
+ if (target > maxScroll) target = maxScroll;
643
+ startSnap(nodeId, horizontal ? ScrollAxis::X : ScrollAxis::Y, target);
644
+ return true;
645
+ }
646
+
441
647
  private:
442
648
  InputController() = default;
443
649
 
@@ -517,6 +723,14 @@ private:
517
723
  if (result >= 0) return result;
518
724
  }
519
725
 
726
+ #if GEA_UI_SVG
727
+ // Inside an <svg>, the target is the topmost shape under the point, by
728
+ // its painted geometry; the svg itself when none is.
729
+ if (inside && !clipped && svg::isRoot(node)) {
730
+ const int shape = svg::hitTest(id, x, y);
731
+ if (shape >= 0) return shape;
732
+ }
733
+ #endif
520
734
  if (!inside || clipped || node.computedStyle().visibility != 0) return -1;
521
735
  return id;
522
736
  }
@@ -866,7 +1080,7 @@ private:
866
1080
  momentumAxis_ = ScrollAxis::None;
867
1081
  momentumVelocity_ = 0.0f;
868
1082
  momentumScrollAccum_ = 0.0f;
869
- treeState().inputTickRequired = false;
1083
+ treeState().inputTickRequired = snapNode_ >= 0;
870
1084
  }
871
1085
 
872
1086
  struct VelocitySample {
@@ -895,6 +1109,29 @@ private:
895
1109
  ScrollAxis activeScrollAxis_ = ScrollAxis::None;
896
1110
  int scrollLastX_ = 0;
897
1111
  int scrollLastY_ = 0;
1112
+ int downX_ = 0;
1113
+ int downY_ = 0;
1114
+ int gestureStartScroll_ = 0;
1115
+
1116
+ // Page-snap animation state (snap-page scrollers).
1117
+ // LVGL v8's LV_INDEV_DEF_SCROLL_LIMIT: the axis is decided only once the
1118
+ // finger is more than this far from where it landed, and a tie goes
1119
+ // vertical (lv_indev_scroll.c). At 6 px a finger's landing jitter often
1120
+ // read as horizontal and handed a vertical scroll to the tab pager, which
1121
+ // then slid the whole screen sideways and snapped back.
1122
+ static constexpr int kAxisSlopPx = 10;
1123
+ static constexpr int kSnapSpeedPxPerS = 400;
1124
+ static constexpr int kSnapMinMs = 200;
1125
+ static constexpr int kSnapMaxMs = 400;
1126
+ static constexpr float kPageFlingVelocity = 0.3f; // px/ms
1127
+ static constexpr int kPageTurnDivisor = 6; // drag of page / 6 turns a page
1128
+ NodeHandle snapOwner_;
1129
+ int snapNode_ = -1;
1130
+ ScrollAxis snapAxis_ = ScrollAxis::None;
1131
+ int snapFrom_ = 0;
1132
+ int snapTo_ = 0;
1133
+ int snapStartMs_ = 0;
1134
+ int snapDurationMs_ = 0;
898
1135
 
899
1136
  // Momentum-scroll state.
900
1137
  VelocitySample velocitySamples_[kVelocitySampleCount] = {};
@@ -969,6 +1206,11 @@ bool Tree::scrollByKeyStep(int dy)
969
1206
  return InputController::instance().scrollFirstContainerY(dy);
970
1207
  }
971
1208
 
1209
+ bool animateSnapPageScroll(int node, bool horizontal, int target)
1210
+ {
1211
+ return InputController::instance().animateProgrammaticScroll(node, horizontal, target);
1212
+ }
1213
+
972
1214
  void Tree::tickInput(int timestampMs)
973
1215
  {
974
1216
  InputController::instance().tick(timestampMs);
@@ -1013,6 +1255,9 @@ void Tree::setActiveInput(int nodeId)
1013
1255
  state.activeInputId = nodeId;
1014
1256
  state.caretVisible = true;
1015
1257
  state.caretLastFlipMs = state.lastFrameMs;
1258
+ state.caretPos = -1;
1259
+ state.pwdRevealUntilMs = 0;
1260
+ state.pwdRevealFrom = state.pwdRevealTo = 0;
1016
1261
  // Both the old input (caret needs to disappear) and the new input
1017
1262
  // (caret needs to appear) must be re-recorded AND their screen rects
1018
1263
  // flushed. Without render.dirty + nodeCommandDirty the rebuilt
@@ -1053,6 +1298,84 @@ bool Tree::activeInputCaretVisible() const
1053
1298
  return treeState().caretVisible;
1054
1299
  }
1055
1300
 
1301
+ #if GEA_UI_INPUT_NODES
1302
+ namespace {
1303
+ void markActiveInputRepaint(TreeState &state)
1304
+ {
1305
+ const int id = state.activeInputId;
1306
+ if (id < 0 || id >= state.nodeCount) return;
1307
+ state.nodeCommandDirty[id] = 1;
1308
+ state.displayListDirty = true;
1309
+ Node &n = state.nodes[id];
1310
+ n.render.dirty = 1;
1311
+ n.render.layout_dirty = 1;
1312
+ #if GEA_CSS_SCROLLING
1313
+ n.render.non_scroll_dirty = 1;
1314
+ #endif
1315
+ }
1316
+ } // namespace
1317
+ #endif
1318
+
1319
+ int Tree::activeInputCaret() const
1320
+ {
1321
+ #if GEA_UI_INPUT_NODES
1322
+ const auto &state = treeState();
1323
+ if (state.activeInputId < 0) return 0;
1324
+ const char *value = const_cast<Tree *>(this)->getAttribute(state.activeInputId, "value");
1325
+ const int len = value ? static_cast<int>(std::strlen(value)) : 0;
1326
+ if (state.caretPos < 0 || state.caretPos > len) return len;
1327
+ return state.caretPos;
1328
+ #else
1329
+ return 0;
1330
+ #endif
1331
+ }
1332
+
1333
+ void Tree::setActiveInputCaret(int pos)
1334
+ {
1335
+ #if GEA_UI_INPUT_NODES
1336
+ auto &state = treeState();
1337
+ if (state.activeInputId < 0) return;
1338
+ state.caretPos = pos < 0 ? 0 : pos;
1339
+ state.caretVisible = true;
1340
+ state.caretLastFlipMs = state.lastFrameMs;
1341
+ markActiveInputRepaint(state);
1342
+ #else
1343
+ (void)pos;
1344
+ #endif
1345
+ }
1346
+
1347
+ void Tree::noteActiveInputTyped(int from, int to)
1348
+ {
1349
+ #if GEA_UI_INPUT_NODES
1350
+ auto &state = treeState();
1351
+ constexpr int kPasswordShowMs = 1500;
1352
+ if (state.pwdRevealUntilMs != 0 && from == state.pwdRevealTo) {
1353
+ state.pwdRevealTo = to; // the same burst: keep showing it
1354
+ } else {
1355
+ state.pwdRevealFrom = from;
1356
+ state.pwdRevealTo = to;
1357
+ }
1358
+ state.pwdRevealUntilMs = (state.lastFrameMs ? state.lastFrameMs : 1) + kPasswordShowMs;
1359
+ #else
1360
+ (void)from;
1361
+ (void)to;
1362
+ #endif
1363
+ }
1364
+
1365
+ bool Tree::inputPasswordReveal(int id, int *from, int *to) const
1366
+ {
1367
+ #if GEA_UI_INPUT_NODES
1368
+ const auto &state = treeState();
1369
+ if (id != state.activeInputId || state.pwdRevealUntilMs == 0 || state.pwdRevealTo <= state.pwdRevealFrom) return false;
1370
+ *from = state.pwdRevealFrom;
1371
+ *to = state.pwdRevealTo;
1372
+ return true;
1373
+ #else
1374
+ (void)id; (void)from; (void)to;
1375
+ return false;
1376
+ #endif
1377
+ }
1378
+
1056
1379
  void Tree::tickInputCaret(int timestampMs)
1057
1380
  {
1058
1381
  #if GEA_UI_INPUT_NODES
@@ -1061,7 +1384,14 @@ void Tree::tickInputCaret(int timestampMs)
1061
1384
  state.caretVisible = false;
1062
1385
  return;
1063
1386
  }
1064
- constexpr int kCaretBlinkMs = 500;
1387
+ // The password characters typed last turn to bullets once their time is up.
1388
+ if (state.pwdRevealUntilMs != 0 && timestampMs >= state.pwdRevealUntilMs) {
1389
+ state.pwdRevealUntilMs = 0;
1390
+ state.pwdRevealFrom = state.pwdRevealTo = 0;
1391
+ markActiveInputRepaint(state);
1392
+ }
1393
+ // lv_theme_default's cursor: anim_time 400 ms per phase.
1394
+ constexpr int kCaretBlinkMs = 400;
1065
1395
  if (state.caretLastFlipMs == 0) state.caretLastFlipMs = timestampMs;
1066
1396
  if (timestampMs - state.caretLastFlipMs >= kCaretBlinkMs) {
1067
1397
  state.caretVisible = !state.caretVisible;