@geastack/engine 0.1.21 → 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.
- package/canvas.cpp +24 -0
- package/image_store.cpp +308 -1
- package/package.json +1 -1
- package/ui/canvas_element.cpp +12 -16
- package/ui/core.cpp +10 -7
- package/ui/document.cpp +25 -0
- package/ui/input.cpp +332 -11
- package/ui/input_render.cpp +62 -17
- package/ui/input_retirement.h +3 -0
- package/ui/internal.h +34 -0
- package/ui/layout.cpp +68 -16
- package/ui/layout_snapshot.cpp +119 -70
- package/ui/layout_snapshot.h +1 -0
- package/ui/node_model.h +6 -1
- package/ui/render.cpp +1126 -64
- package/ui/root_scroll_refresh.cpp +372 -66
- package/ui/root_scroll_refresh.h +4 -0
- package/ui/style.cpp +38 -21
- package/ui/svg_element.h +5 -2
- package/ui/svg_element_impl.h +475 -36
- package/ui/svg_geometry.h +78 -13
- package/ui/text.cpp +7 -6
- package/ui/tree_internal.h +12 -0
- package/ui/tree_nodes.cpp +1 -0
- package/ui/tree_render.cpp +263 -23
- package/ui/tree_state.h +9 -0
- package/ui/tree_style.cpp +8 -0
- package/ui/view.cpp +27 -9
- package/ui/viewport_region.cpp +53 -0
- package/ui/viewport_region.h +3 -0
- package/ui/virtual_keyboard.cpp +279 -23
- package/ui/virtual_keyboard_icons.h +114 -0
package/ui/input.cpp
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#include <algorithm>
|
|
13
13
|
#include <cmath>
|
|
14
14
|
#include <cstdint>
|
|
15
|
+
#include <cstring>
|
|
15
16
|
#include <cstdio>
|
|
16
17
|
#include <cstdlib>
|
|
17
18
|
#include <cstring>
|
|
@@ -111,6 +112,8 @@ public:
|
|
|
111
112
|
activeScrollNode_ = tree.nodeCount() == 0 ? -1 : findScrollNodeId(0, x, y);
|
|
112
113
|
activeScrollOwner_=NodeHandle(activeScrollNode_);
|
|
113
114
|
snapAccumDy_ = 0;
|
|
115
|
+
downX_ = x;
|
|
116
|
+
downY_ = y;
|
|
114
117
|
activeScrollAxis_ = ScrollAxis::None;
|
|
115
118
|
scrollLastX_ = x;
|
|
116
119
|
scrollLastY_ = y;
|
|
@@ -180,7 +183,7 @@ public:
|
|
|
180
183
|
return 0;
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
Node &
|
|
186
|
+
const Node &innerNode = tree.nodes()[activeScrollNode_];
|
|
184
187
|
const int dx = x - scrollLastX_;
|
|
185
188
|
const int dy = y - scrollLastY_;
|
|
186
189
|
scrollLastX_ = x;
|
|
@@ -191,17 +194,57 @@ public:
|
|
|
191
194
|
pushVelocitySample(x, y);
|
|
192
195
|
if (dx == 0 && dy == 0) return 0;
|
|
193
196
|
|
|
194
|
-
const bool canScrollX = nodeCanScrollX(activeScrollNode_, node);
|
|
195
|
-
const bool canScrollY = nodeCanScrollY(activeScrollNode_, node);
|
|
196
197
|
if (activeScrollAxis_ == ScrollAxis::None) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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);
|
|
203
240
|
}
|
|
241
|
+
activeScrollAxis_ = chosenAxis;
|
|
242
|
+
if (snapNode_ == chosen) cancelSnap();
|
|
243
|
+
gestureStartScroll_ = chosenAxis == ScrollAxis::X ? scrollLeft(chosen) : scrollTop(chosen);
|
|
204
244
|
}
|
|
245
|
+
Node &node = tree.nodes()[activeScrollNode_];
|
|
246
|
+
const bool canScrollX = nodeCanScrollX(activeScrollNode_, node);
|
|
247
|
+
const bool canScrollY = nodeCanScrollY(activeScrollNode_, node);
|
|
205
248
|
|
|
206
249
|
bool changed = false;
|
|
207
250
|
if (dx != 0 && canScrollX && activeScrollAxis_ == ScrollAxis::X) {
|
|
@@ -281,6 +324,13 @@ public:
|
|
|
281
324
|
return -1;
|
|
282
325
|
}
|
|
283
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
|
+
}
|
|
284
334
|
if (scrollNode >= 0 && nodeHasMomentumOptIn(scrollNode)) {
|
|
285
335
|
pushVelocitySample(scrollLastX_, scrollLastY_);
|
|
286
336
|
startMomentum(scrollNode, scrollAxis);
|
|
@@ -340,6 +390,7 @@ public:
|
|
|
340
390
|
scrollLastX_ = 0;
|
|
341
391
|
scrollLastY_ = 0;
|
|
342
392
|
resetVelocitySamples();
|
|
393
|
+
cancelSnap();
|
|
343
394
|
cancelMomentum();
|
|
344
395
|
carryOverVelocity_ = 0.0f;
|
|
345
396
|
carryOverAxis_ = ScrollAxis::None;
|
|
@@ -356,6 +407,7 @@ public:
|
|
|
356
407
|
auto leaving=[&](const NodeHandle &owner){return inputOwnerLeaving(owner,removed,retained);};
|
|
357
408
|
if(leaving(activeTouchOwner_) || leaving(activeScrollOwner_)) cancelActiveGesture();
|
|
358
409
|
if(leaving(momentumOwner_)) cancelMomentum();
|
|
410
|
+
if(leaving(snapOwner_)) cancelSnap();
|
|
359
411
|
if(leaving(hoveredOwner_)){treeState().hoveredNodeId=-1;hoveredOwner_={};StyleSheet::instance().hoverChanged();}
|
|
360
412
|
}
|
|
361
413
|
|
|
@@ -364,6 +416,7 @@ public:
|
|
|
364
416
|
|
|
365
417
|
void tick(int timestampMs)
|
|
366
418
|
{
|
|
419
|
+
if (snapNode_ >= 0) tickSnap(timestampMs);
|
|
367
420
|
if (momentumNode_ < 0) return;
|
|
368
421
|
Tree &tree = Tree::instance();
|
|
369
422
|
if (!momentumOwner_.valid() || momentumOwner_.id()!=momentumNode_) {
|
|
@@ -439,6 +492,158 @@ public:
|
|
|
439
492
|
}
|
|
440
493
|
}
|
|
441
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
|
+
|
|
442
647
|
private:
|
|
443
648
|
InputController() = default;
|
|
444
649
|
|
|
@@ -875,7 +1080,7 @@ private:
|
|
|
875
1080
|
momentumAxis_ = ScrollAxis::None;
|
|
876
1081
|
momentumVelocity_ = 0.0f;
|
|
877
1082
|
momentumScrollAccum_ = 0.0f;
|
|
878
|
-
treeState().inputTickRequired =
|
|
1083
|
+
treeState().inputTickRequired = snapNode_ >= 0;
|
|
879
1084
|
}
|
|
880
1085
|
|
|
881
1086
|
struct VelocitySample {
|
|
@@ -904,6 +1109,29 @@ private:
|
|
|
904
1109
|
ScrollAxis activeScrollAxis_ = ScrollAxis::None;
|
|
905
1110
|
int scrollLastX_ = 0;
|
|
906
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;
|
|
907
1135
|
|
|
908
1136
|
// Momentum-scroll state.
|
|
909
1137
|
VelocitySample velocitySamples_[kVelocitySampleCount] = {};
|
|
@@ -978,6 +1206,11 @@ bool Tree::scrollByKeyStep(int dy)
|
|
|
978
1206
|
return InputController::instance().scrollFirstContainerY(dy);
|
|
979
1207
|
}
|
|
980
1208
|
|
|
1209
|
+
bool animateSnapPageScroll(int node, bool horizontal, int target)
|
|
1210
|
+
{
|
|
1211
|
+
return InputController::instance().animateProgrammaticScroll(node, horizontal, target);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
981
1214
|
void Tree::tickInput(int timestampMs)
|
|
982
1215
|
{
|
|
983
1216
|
InputController::instance().tick(timestampMs);
|
|
@@ -1022,6 +1255,9 @@ void Tree::setActiveInput(int nodeId)
|
|
|
1022
1255
|
state.activeInputId = nodeId;
|
|
1023
1256
|
state.caretVisible = true;
|
|
1024
1257
|
state.caretLastFlipMs = state.lastFrameMs;
|
|
1258
|
+
state.caretPos = -1;
|
|
1259
|
+
state.pwdRevealUntilMs = 0;
|
|
1260
|
+
state.pwdRevealFrom = state.pwdRevealTo = 0;
|
|
1025
1261
|
// Both the old input (caret needs to disappear) and the new input
|
|
1026
1262
|
// (caret needs to appear) must be re-recorded AND their screen rects
|
|
1027
1263
|
// flushed. Without render.dirty + nodeCommandDirty the rebuilt
|
|
@@ -1062,6 +1298,84 @@ bool Tree::activeInputCaretVisible() const
|
|
|
1062
1298
|
return treeState().caretVisible;
|
|
1063
1299
|
}
|
|
1064
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
|
+
|
|
1065
1379
|
void Tree::tickInputCaret(int timestampMs)
|
|
1066
1380
|
{
|
|
1067
1381
|
#if GEA_UI_INPUT_NODES
|
|
@@ -1070,7 +1384,14 @@ void Tree::tickInputCaret(int timestampMs)
|
|
|
1070
1384
|
state.caretVisible = false;
|
|
1071
1385
|
return;
|
|
1072
1386
|
}
|
|
1073
|
-
|
|
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;
|
|
1074
1395
|
if (state.caretLastFlipMs == 0) state.caretLastFlipMs = timestampMs;
|
|
1075
1396
|
if (timestampMs - state.caretLastFlipMs >= kCaretBlinkMs) {
|
|
1076
1397
|
state.caretVisible = !state.caretVisible;
|
package/ui/input_render.cpp
CHANGED
|
@@ -28,14 +28,20 @@
|
|
|
28
28
|
#include "pixel.h"
|
|
29
29
|
#include "tree_internal.h"
|
|
30
30
|
|
|
31
|
+
#include <cstdlib>
|
|
31
32
|
#include <cstring>
|
|
33
|
+
#include <string>
|
|
34
|
+
#include <unordered_map>
|
|
32
35
|
|
|
33
36
|
namespace gea::embedded::ui {
|
|
34
37
|
|
|
35
38
|
namespace {
|
|
36
39
|
|
|
40
|
+
// lv_theme_default's textarea cursor: a 2 px left border, pad_left -1, so it
|
|
41
|
+
// sits one pixel left of the letter and spans the font's line height plus the
|
|
42
|
+
// border above and below.
|
|
37
43
|
constexpr int kInputCaretWidth = 2;
|
|
38
|
-
constexpr int
|
|
44
|
+
constexpr int kInputCaretOutset = 2;
|
|
39
45
|
// Match text.cpp's local kBitmapFontHeight — used as the implicit font size
|
|
40
46
|
// when an input doesn't have an explicit font_size set, so the vertical
|
|
41
47
|
// centering formula here matches the height the framework's bitmap text path
|
|
@@ -47,12 +53,47 @@ inline gea::framework::graphics::pixel::native_t kPlaceholderColor()
|
|
|
47
53
|
return gea::framework::graphics::pixel::nativeColor(71, 85, 105);
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
bool isPasswordInput(int id)
|
|
57
|
+
{
|
|
58
|
+
const char *type = Tree::instance().getAttribute(id, "type");
|
|
59
|
+
return type && std::strcmp(type, "password") == 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// lv_textarea's password bullet (LV_TEXTAREA_PWD_BULLET_UNICODE).
|
|
63
|
+
constexpr const char *kPasswordBullet = "\xE2\x80\xA2";
|
|
64
|
+
|
|
65
|
+
// What a password input shows for value[0, end): a bullet per character,
|
|
66
|
+
// except the ones typed in the last burst, still shown in clear.
|
|
67
|
+
std::string passwordDisplay(int id, const char *value, int end)
|
|
68
|
+
{
|
|
69
|
+
int from = 0, to = 0;
|
|
70
|
+
const bool reveal = Tree::instance().inputPasswordReveal(id, &from, &to);
|
|
71
|
+
std::string out;
|
|
72
|
+
for (int i = 0; i < end && value[i]; ++i) {
|
|
73
|
+
if (reveal && i >= from && i < to) out.push_back(value[i]);
|
|
74
|
+
else out += kPasswordBullet;
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The display string of each password input, kept alive for its DrawText.
|
|
80
|
+
std::unordered_map<int, std::string> &passwordTexts()
|
|
81
|
+
{
|
|
82
|
+
static std::unordered_map<int, std::string> texts;
|
|
83
|
+
return texts;
|
|
84
|
+
}
|
|
85
|
+
|
|
50
86
|
const char *inputContentText(int id, gea::framework::graphics::pixel::native_t *outColor, gea::framework::graphics::pixel::native_t textColor)
|
|
51
87
|
{
|
|
52
88
|
auto &tree = Tree::instance();
|
|
53
89
|
const char *value = tree.getAttribute(id, "value");
|
|
54
90
|
if (value && value[0]) {
|
|
55
91
|
if (outColor) *outColor = textColor;
|
|
92
|
+
if (isPasswordInput(id)) {
|
|
93
|
+
std::string &text = passwordTexts()[id];
|
|
94
|
+
text = passwordDisplay(id, value, static_cast<int>(std::strlen(value)));
|
|
95
|
+
return text.c_str();
|
|
96
|
+
}
|
|
56
97
|
return value;
|
|
57
98
|
}
|
|
58
99
|
const char *placeholder = tree.getAttribute(id, "placeholder");
|
|
@@ -178,26 +219,30 @@ void InputRenderer::record(int id)
|
|
|
178
219
|
// unfocused would be misleading on targets where the framework handles
|
|
179
220
|
// the input's visual editing state.
|
|
180
221
|
if (tree.activeInputId() == id && tree.activeInputCaretVisible()) {
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
// goes at the START of the content box — typing the first
|
|
185
|
-
// character would land there, and the placeholder gets visually
|
|
186
|
-
// pushed aside by the appearing glyph. Measuring the placeholder
|
|
187
|
-
// here would be wrong: it'd put the caret at the end of a
|
|
188
|
-
// string the user isn't actually editing.
|
|
222
|
+
// At the caret: the width of what is shown before it (bullets on a
|
|
223
|
+
// password), from the content's left edge; at the start when the
|
|
224
|
+
// placeholder shows.
|
|
189
225
|
const char *valueAttr = tree.getAttribute(id, "value");
|
|
190
226
|
const bool hasValue = valueAttr && valueAttr[0];
|
|
191
|
-
int caretX = contentX;
|
|
227
|
+
int caretX = contentX - 1;
|
|
192
228
|
if (hasValue) {
|
|
193
|
-
const int
|
|
194
|
-
|
|
195
|
-
|
|
229
|
+
const int caret = tree.activeInputCaret();
|
|
230
|
+
const std::string prefix = isPasswordInput(id) ? passwordDisplay(id, valueAttr, caret) : std::string(valueAttr, caret);
|
|
231
|
+
const int prefixWidth = TextRenderer::measureWidth(prefix.c_str(), n.computedStyle().font_id, n.computedStyle().font_size, n.computedStyle().text_transform);
|
|
232
|
+
caretX += prefixWidth < contentW ? prefixWidth : contentW - kInputCaretWidth;
|
|
233
|
+
}
|
|
234
|
+
const int fontSize = n.computedStyle().font_size > 0 ? n.computedStyle().font_size : 16;
|
|
235
|
+
const int lineHeight = TextRenderer::measureHeight("M", n.computedStyle().font_id, n.computedStyle().font_size, n.computedStyle().text_transform, n.computedStyle().line_height);
|
|
236
|
+
int textY = contentY + (contentH - fontSize) / 2;
|
|
237
|
+
if (textY < contentY) textY = contentY;
|
|
238
|
+
const int caretY = textY - kInputCaretOutset;
|
|
239
|
+
const int caretH = lineHeight + kInputCaretOutset * 2;
|
|
240
|
+
// caret-color, else the text colour (a placeholder's grey is not it).
|
|
241
|
+
gea::framework::graphics::pixel::native_t caretColor = n.computedStyle().text_color ? n.computedStyle().text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
242
|
+
if (const char *cc = tree.getAttribute(id, "caret-color"); cc && cc[0] == '#' && std::strlen(cc) >= 7) {
|
|
243
|
+
const unsigned long rgb = std::strtoul(cc + 1, nullptr, 16);
|
|
244
|
+
caretColor = gea::framework::graphics::pixel::nativeColor((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
|
|
196
245
|
}
|
|
197
|
-
const int caretY = contentY + kInputCaretInsetY;
|
|
198
|
-
int caretH = contentH - kInputCaretInsetY * 2;
|
|
199
|
-
if (caretH < 4) caretH = contentH > 4 ? contentH - 2 : contentH;
|
|
200
|
-
const gea::framework::graphics::pixel::native_t caretColor = n.computedStyle().text_color ? n.computedStyle().text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
201
246
|
|
|
202
247
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
203
248
|
if (cmd) {
|
package/ui/input_retirement.h
CHANGED
|
@@ -16,6 +16,9 @@ inline bool inputOwnerLeaving(const NodeHandle &owner,const InputRetirementRoots
|
|
|
16
16
|
}
|
|
17
17
|
void retirePointerInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
|
|
18
18
|
void cancelPrimaryPointerInput();
|
|
19
|
+
// A programmatic scroll of a `snap-page` scroller animates to its target
|
|
20
|
+
// (engine/ui/input.cpp); false when the node does not snap to pages.
|
|
21
|
+
bool animateSnapPageScroll(int node, bool horizontal, int target);
|
|
19
22
|
void retireTouchInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
|
|
20
23
|
// Weak Core default; actual native platform providers must override this.
|
|
21
24
|
void retirePlatformInputForSubtrees(const InputRetirementRoots &,const InputRetirementRoots &);
|
package/ui/internal.h
CHANGED
|
@@ -328,6 +328,27 @@ void rootScrollImageHoldTick();
|
|
|
328
328
|
void recordNodeWithExpandedClip(int id, uint8_t parentAlpha, int clipNode,
|
|
329
329
|
int clipX0, int clipY0, int clipX1, int clipY1);
|
|
330
330
|
void replay();
|
|
331
|
+
// The occlusion-cull start replay() would use under the clip now in
|
|
332
|
+
// force; setReplayCullStart(n) makes replay() use n (-1: compute again).
|
|
333
|
+
int replayCullStart();
|
|
334
|
+
void setReplayCullStart(int start);
|
|
335
|
+
// Whether the last replayCullStart() found an opaque fill covering the clip.
|
|
336
|
+
bool replayCullCovered();
|
|
337
|
+
// Filters the list once for the clip now in force: replay() then walks only
|
|
338
|
+
// the commands that can paint inside it until endRegionReplay(). Computes
|
|
339
|
+
// the cull too (replayCullCovered() reports it). False: not filtered, and
|
|
340
|
+
// replay() walks the whole list as before.
|
|
341
|
+
bool beginRegionReplay();
|
|
342
|
+
// Per viewport row: what a horizontal scroll leaves unchanged, or 0
|
|
343
|
+
// (DisplayCommandReplayer::scrollRowSignatures).
|
|
344
|
+
bool scrollRowSignatures(int vx, int vy, int vw, int vh, std::uint32_t *sig);
|
|
345
|
+
void endRegionReplay();
|
|
346
|
+
// A list filtered by beginRegionReplay() is in force (replay() uses it for
|
|
347
|
+
// any clip inside the rect it was filtered for).
|
|
348
|
+
bool regionReplayActive();
|
|
349
|
+
// Whether the list in force was filtered for a rect holding this one, and
|
|
350
|
+
// whether an opaque fill covered that rect.
|
|
351
|
+
bool regionReplayHolds(int x, int y, int w, int h, bool *covered);
|
|
331
352
|
bool canReplayDirectDirtyRegions(int width, int height) const;
|
|
332
353
|
void translateNodeCommands(int node, int dx, int dy);
|
|
333
354
|
void translateSubtreeCommands(int node, int dx, int dy);
|
|
@@ -338,6 +359,9 @@ void rootScrollImageHoldTick();
|
|
|
338
359
|
// full record. Returns true when such a reveal exists.
|
|
339
360
|
bool subtreeRevealsUnrecordedContent(int node, int width, int height) const;
|
|
340
361
|
bool rerecordNodeCommands(int node);
|
|
362
|
+
// rerecordNodeCommands for a node recorded under recordNodeWithExpandedClip:
|
|
363
|
+
// the expanded-clip node's children see the coverage window, as they did then.
|
|
364
|
+
bool rerecordNodeCommandsWithExpandedClip(int node, int clipNode, int clipX0, int clipY0, int clipX1, int clipY1);
|
|
341
365
|
// A pixel buffer referenced by retained blit commands is about to be freed
|
|
342
366
|
// (canvas surface mode flip / resize / removal). The owning node is only
|
|
343
367
|
// *marked* dirty — its re-record happens later — so any replay in the gap
|
|
@@ -385,6 +409,10 @@ void rootScrollImageHoldTick();
|
|
|
385
409
|
void replayDirectDirtyRegions(const DisplayReplayRegion *regions, int count);
|
|
386
410
|
bool canReplaySimpleDirtyRegions(int width, int height) const;
|
|
387
411
|
bool canReplaySimpleDirtyRegions(int width, int height, const DisplayReplayRegion *regions, int count) const;
|
|
412
|
+
// Between begin and end the tree and display list must not change: the
|
|
413
|
+
// region-independent half of the simple-replay verdict is computed once.
|
|
414
|
+
void beginSimpleReplayScope();
|
|
415
|
+
void endSimpleReplayScope();
|
|
388
416
|
void replaySimpleClippedDirtyRegion(int x0, int y0, int x1, int y1, int origin = -1);
|
|
389
417
|
// Static-backdrop cache: bake every non-dirty (static) node into the bg cache
|
|
390
418
|
// buffer once it's stable, so the dirty-region replay can blit that backdrop and
|
|
@@ -427,6 +455,12 @@ void rootScrollImageHoldTick();
|
|
|
427
455
|
void filterBlurCacheStats(int *hits, int *misses) const;
|
|
428
456
|
int commandCount() const;
|
|
429
457
|
bool hasTextClippedBackgrounds() const;
|
|
458
|
+
// Scrollbar thumbs are recorded outside every node's command range;
|
|
459
|
+
// see DisplayListState::scrollbarBoxes.
|
|
460
|
+
void noteScrollbarBox(int node, int x, int y, int w, int h);
|
|
461
|
+
bool scrollbarOverlapsRegion(int x0, int y0, int x1, int y1) const;
|
|
462
|
+
bool scrollbarThumbsPaintLast() const;
|
|
463
|
+
void replayScrollbarThumbsInRegion(int x0, int y0, int x1, int y1);
|
|
430
464
|
int nodeCommandCount(int node) const;
|
|
431
465
|
const DisplayCommand *nodeCommandAt(int node, int index) const;
|
|
432
466
|
bool nodeCommandBounds(int node, int *x0, int *y0, int *x1, int *y1) const;
|