@geastack/engine 0.1.18 → 0.1.20
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/package.json +2 -2
- package/touch_runtime.cpp +10 -8
- package/ui/input.cpp +52 -18
- package/ui/internal.h +2 -0
- package/ui/layout.cpp +51 -2
- package/ui/node.cpp +2 -1
- package/ui/node.h +104 -7
- package/ui/node_features.h +4 -0
- package/ui/render.cpp +79 -1
- package/ui/root_scroll_refresh.cpp +10 -1
- package/ui/style.cpp +120 -68
- package/ui/style.h +3 -2
- package/ui/text.cpp +6 -0
- package/ui/tree_events.cpp +9 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@geastack/core": "^0.1.
|
|
60
|
+
"@geastack/core": "^0.1.46"
|
|
61
61
|
}
|
|
62
62
|
}
|
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,
|
package/ui/input.cpp
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
#define GEA_SCROLL_MOMENTUM_MAX_VELOCITY 24.0f
|
|
28
28
|
#endif
|
|
29
29
|
#ifndef GEA_SCROLL_MOMENTUM_MIN_VELOCITY
|
|
30
|
-
#define GEA_SCROLL_MOMENTUM_MIN_VELOCITY 0.
|
|
30
|
+
#define GEA_SCROLL_MOMENTUM_MIN_VELOCITY 0.2f
|
|
31
31
|
#endif
|
|
32
32
|
#ifndef GEA_SCROLL_MOMENTUM_DECAY_MS
|
|
33
33
|
#define GEA_SCROLL_MOMENTUM_DECAY_MS 680.0f
|
|
@@ -106,6 +106,7 @@ public:
|
|
|
106
106
|
carryOverVelocity_ = momentumVelocity_;
|
|
107
107
|
carryOverAxis_ = momentumAxis_;
|
|
108
108
|
cancelMomentum();
|
|
109
|
+
pointerDownMs_ = gea::framework::services::FrameScheduler::nowMs();
|
|
109
110
|
activeScrollNode_ = tree.nodeCount() == 0 ? -1 : findScrollNodeId(0, x, y);
|
|
110
111
|
activeScrollOwner_=NodeHandle(activeScrollNode_);
|
|
111
112
|
snapAccumDy_ = 0;
|
|
@@ -766,27 +767,53 @@ private:
|
|
|
766
767
|
if (scrollNode < 0 || scrollNode >= tree.nodeCount()) return;
|
|
767
768
|
if (!nodeCanScrollAxis(scrollNode, tree.node(scrollNode), axis)) return;
|
|
768
769
|
|
|
769
|
-
//
|
|
770
|
-
//
|
|
771
|
-
//
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
770
|
+
// Release velocity is the finger's speed over the last
|
|
771
|
+
// kVelocityWindowMs before lift-off, not over the whole ring: a flick
|
|
772
|
+
// that started fast and slowed before release must launch at the slow
|
|
773
|
+
// speed. The newest sample is the lift itself (pushed at pointer up),
|
|
774
|
+
// so a pause before lifting counts as standing still. The window start
|
|
775
|
+
// is interpolated between the two samples that straddle it, which
|
|
776
|
+
// keeps the estimate independent of the touch report rate.
|
|
777
|
+
auto sampleAt = [this](int back) -> const VelocitySample & {
|
|
778
|
+
return velocitySamples_[(velocitySampleNext_ + kVelocitySampleCount - 1 - back) %
|
|
779
|
+
kVelocitySampleCount];
|
|
780
|
+
};
|
|
781
|
+
auto along = [axis](const VelocitySample &s) {
|
|
782
|
+
return static_cast<float>(axis == ScrollAxis::X ? s.x : s.y);
|
|
783
|
+
};
|
|
784
|
+
const VelocitySample &newest = sampleAt(0);
|
|
785
|
+
const int windowStartMs = newest.timestampMs - kVelocityWindowMs;
|
|
786
|
+
int dtMs = 0;
|
|
787
|
+
float deltaF = 0.0f;
|
|
788
|
+
for (int back = 1; back < velocitySampleCount_; back++) {
|
|
789
|
+
const VelocitySample &older = sampleAt(back);
|
|
790
|
+
if (older.timestampMs > windowStartMs && back + 1 < velocitySampleCount_) continue;
|
|
791
|
+
if (older.timestampMs >= windowStartMs) {
|
|
792
|
+
// The ring does not reach back a whole window: use what it holds.
|
|
793
|
+
dtMs = newest.timestampMs - older.timestampMs;
|
|
794
|
+
deltaF = along(newest) - along(older);
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
const VelocitySample &newer = sampleAt(back - 1);
|
|
798
|
+
const int span = newer.timestampMs - older.timestampMs;
|
|
799
|
+
const float t = span > 0
|
|
800
|
+
? static_cast<float>(windowStartMs - older.timestampMs) / span
|
|
801
|
+
: 1.0f;
|
|
802
|
+
const float startPos = along(older) + (along(newer) - along(older)) * t;
|
|
803
|
+
dtMs = kVelocityWindowMs;
|
|
804
|
+
deltaF = along(newest) - startPos;
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
781
807
|
if (dtMs <= 0) return;
|
|
782
808
|
|
|
783
809
|
const int nowMs = gea::framework::services::FrameScheduler::nowMs();
|
|
784
810
|
|
|
785
|
-
const int delta =
|
|
786
|
-
float velocityPxPerMs =
|
|
811
|
+
const int delta = static_cast<int>(deltaF);
|
|
812
|
+
float velocityPxPerMs = deltaF / static_cast<float>(dtMs);
|
|
787
813
|
|
|
788
|
-
// Below ~0.
|
|
789
|
-
//
|
|
814
|
+
// Below ~0.2 px/ms = 200 px/sec over the release window the finger was
|
|
815
|
+
// not flicking: a finger that stopped still rolls a few px as it lifts,
|
|
816
|
+
// and launching that roll reads as the list moving on by itself.
|
|
790
817
|
// A tap (no drag, weak velocity) also lands here, which is what we
|
|
791
818
|
// want: a tap should NOT resume a stashed fling.
|
|
792
819
|
if (std::fabs(velocityPxPerMs) < kMinFlingVelocity) {
|
|
@@ -805,7 +832,11 @@ private:
|
|
|
805
832
|
// the new flick goes in the same direction, add the leftover
|
|
806
833
|
// velocity to the new one. Opposite direction → user is reversing
|
|
807
834
|
// course, drop the stash.
|
|
835
|
+
// Only a quick re-flick carries: a finger that caught the fling and held
|
|
836
|
+
// or dragged slowly before lifting would otherwise launch faster than
|
|
837
|
+
// it moved.
|
|
808
838
|
if (carryOverAxis_ == axis && carryOverVelocity_ != 0.0f &&
|
|
839
|
+
nowMs - pointerDownMs_ <= kCarryOverWindowMs &&
|
|
809
840
|
(carryOverVelocity_ > 0.0f) == (velocityPxPerMs > 0.0f)) {
|
|
810
841
|
velocityPxPerMs += carryOverVelocity_ * kCarryOverBoost;
|
|
811
842
|
}
|
|
@@ -843,9 +874,11 @@ private:
|
|
|
843
874
|
int x;
|
|
844
875
|
int y;
|
|
845
876
|
};
|
|
846
|
-
static constexpr int kVelocitySampleCount =
|
|
877
|
+
static constexpr int kVelocitySampleCount = 8;
|
|
878
|
+
static constexpr int kVelocityWindowMs = 50;
|
|
847
879
|
static constexpr float kLaunchVelocityBoost = GEA_SCROLL_MOMENTUM_LAUNCH_BOOST;
|
|
848
880
|
static constexpr float kCarryOverBoost = GEA_SCROLL_MOMENTUM_CARRY_BOOST;
|
|
881
|
+
static constexpr int kCarryOverWindowMs = 250;
|
|
849
882
|
static constexpr float kMaxMomentumVelocity = GEA_SCROLL_MOMENTUM_MAX_VELOCITY; // px/ms
|
|
850
883
|
static constexpr float kMinFlingVelocity = GEA_SCROLL_MOMENTUM_MIN_VELOCITY; // px/ms
|
|
851
884
|
static constexpr float kMomentumDecayMs = GEA_SCROLL_MOMENTUM_DECAY_MS;
|
|
@@ -877,6 +910,7 @@ private:
|
|
|
877
910
|
// Folded into the next flick if same-direction so successive flicks
|
|
878
911
|
// accelerate (iOS-style).
|
|
879
912
|
float carryOverVelocity_ = 0.0f;
|
|
913
|
+
int pointerDownMs_ = 0;
|
|
880
914
|
ScrollAxis carryOverAxis_ = ScrollAxis::None;
|
|
881
915
|
};
|
|
882
916
|
|
package/ui/internal.h
CHANGED
|
@@ -578,6 +578,8 @@ void rootScrollImageHoldTick();
|
|
|
578
578
|
static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
|
|
579
579
|
static int firstUnbreakableWidth(const Node &node);
|
|
580
580
|
static int minContentWidth(const Node &node, int *pendingWord = nullptr);
|
|
581
|
+
// The run laid out on one line (no soft wraps): CSS max-content width.
|
|
582
|
+
static int maxContentWidth(const Node &node);
|
|
581
583
|
static int measureHeight(const char *text, int fontId, int fontSize, int textTransform = 0, int lineHeight = 0);
|
|
582
584
|
// In-place box re-measure for a rebound text node on refresh paths that
|
|
583
585
|
// 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.
|
|
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()
|
package/ui/node.cpp
CHANGED
|
@@ -283,7 +283,8 @@ const char *NodeHandle::tagName() const
|
|
|
283
283
|
// node, TEXT_NODE (3), COMMENT_NODE (8), or DOCUMENT_FRAGMENT_NODE (11).
|
|
284
284
|
NodeHandle::NodeTypeProperty::operator int() const
|
|
285
285
|
{
|
|
286
|
-
if (!gea::framework::identity::current(
|
|
286
|
+
if (!gea::framework::identity::current(id_, token())) return 0;
|
|
287
|
+
const int id = id_;
|
|
287
288
|
const auto &tree=Tree::instance();
|
|
288
289
|
// The template renderer's list/conditional anchors are hidden nodes tagged
|
|
289
290
|
// "#comment"; DOM queries must see them as the comments they stand for.
|
package/ui/node.h
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "style.h"
|
|
6
6
|
|
|
7
7
|
#include <cstddef>
|
|
8
|
+
#include <cstdint>
|
|
8
9
|
#include <string>
|
|
9
10
|
#include <utility>
|
|
10
11
|
#include <vector>
|
|
@@ -48,13 +49,63 @@ public:
|
|
|
48
49
|
// Structural comments/fragments report 8/11 and never become visual boxes.
|
|
49
50
|
// A retired handle reports 0, distinct from a live empty fragment.
|
|
50
51
|
// Resolved lazily on read (cheap, rare) rather than at every handle
|
|
51
|
-
// construction (hot path)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
// construction (hot path). Inside a handle the property borrows the
|
|
53
|
+
// handle's identity token instead of owning a second reference: handles
|
|
54
|
+
// are copied constantly, and each shared_ptr copy is an atomic
|
|
55
|
+
// read-modify-write (a critical section on targets without hardware
|
|
56
|
+
// atomics). The handle rebuilds it on copy and move. A property copied
|
|
57
|
+
// out of its handle takes its own owner, so it can outlive the handle.
|
|
58
|
+
class NodeTypeProperty {
|
|
59
|
+
public:
|
|
55
60
|
operator int() const;
|
|
56
61
|
bool operator==(int other) const { return static_cast<int>(*this) == other; }
|
|
57
62
|
bool operator!=(int other) const { return static_cast<int>(*this) != other; }
|
|
63
|
+
|
|
64
|
+
// A standalone copy owns the node's current token when it is still
|
|
65
|
+
// the same allocation; a retired one stays retired (reports 0).
|
|
66
|
+
NodeTypeProperty(const NodeTypeProperty &other) : id_(other.id_), bits_(0) { adopt(other.token()); }
|
|
67
|
+
NodeTypeProperty &operator=(const NodeTypeProperty &other)
|
|
68
|
+
{
|
|
69
|
+
if (this != &other) {
|
|
70
|
+
const auto *token = other.token();
|
|
71
|
+
release();
|
|
72
|
+
id_ = other.id_;
|
|
73
|
+
adopt(token);
|
|
74
|
+
}
|
|
75
|
+
return *this;
|
|
76
|
+
}
|
|
77
|
+
~NodeTypeProperty() { release(); }
|
|
78
|
+
|
|
79
|
+
private:
|
|
80
|
+
friend class NodeHandle;
|
|
81
|
+
using Token = gea::framework::identity::Token;
|
|
82
|
+
using Owner = gea::framework::identity::Owner;
|
|
83
|
+
NodeTypeProperty(int id, const Token *token) : id_(id), bits_(reinterpret_cast<std::uintptr_t>(token)) {}
|
|
84
|
+
const Token *token() const
|
|
85
|
+
{
|
|
86
|
+
if (bits_ & 1) return reinterpret_cast<const Owner *>(bits_ & ~std::uintptr_t{1})->get();
|
|
87
|
+
return reinterpret_cast<const Token *>(bits_);
|
|
88
|
+
}
|
|
89
|
+
void borrow(int id, const Token *token)
|
|
90
|
+
{
|
|
91
|
+
release();
|
|
92
|
+
id_ = id;
|
|
93
|
+
bits_ = reinterpret_cast<std::uintptr_t>(token);
|
|
94
|
+
}
|
|
95
|
+
void release()
|
|
96
|
+
{
|
|
97
|
+
if (bits_ & 1) delete reinterpret_cast<Owner *>(bits_ & ~std::uintptr_t{1});
|
|
98
|
+
bits_ = 0;
|
|
99
|
+
}
|
|
100
|
+
void adopt(const Token *token)
|
|
101
|
+
{
|
|
102
|
+
Owner owner = gea::framework::identity::node(id_);
|
|
103
|
+
bits_ = token && owner.get() == token ? reinterpret_cast<std::uintptr_t>(new Owner(std::move(owner))) | 1 : 0;
|
|
104
|
+
}
|
|
105
|
+
int id_;
|
|
106
|
+
// The handle's borrowed Token*, or (low bit set) a standalone copy's own
|
|
107
|
+
// heap Owner*: the handle stays as small as one pointer here.
|
|
108
|
+
std::uintptr_t bits_;
|
|
58
109
|
};
|
|
59
110
|
|
|
60
111
|
// A real default constructor (not a defaulted-arg explicit ctor): records
|
|
@@ -63,14 +114,44 @@ public:
|
|
|
63
114
|
// constructor, so `explicit NodeHandle(int = -1)` alone breaks every
|
|
64
115
|
// generated `__gea_type_X __gea_out{};`.
|
|
65
116
|
NodeHandle() : NodeHandle(-1) {}
|
|
66
|
-
explicit NodeHandle(int id) : id_(id), identity_(gea::framework::identity::node(id)), nodeType{id, identity_} {}
|
|
117
|
+
explicit NodeHandle(int id) : id_(id), identity_(gea::framework::identity::node(id)), nodeType{id, identity_.get()} {}
|
|
118
|
+
// A handle for an owner already in hand (a Style's, another handle's),
|
|
119
|
+
// without a registry lookup. Validity is still checked on use.
|
|
120
|
+
NodeHandle(int id, gea::framework::identity::Owner owner)
|
|
121
|
+
: id_(id), identity_(std::move(owner)), nodeType{id, identity_.get()} {}
|
|
122
|
+
// Copies and moves rebuild nodeType from this handle's own owner.
|
|
123
|
+
NodeHandle(const NodeHandle &other) : id_(other.id_), identity_(other.identity_), nodeType{other.id_, identity_.get()} {}
|
|
124
|
+
NodeHandle(NodeHandle &&other) noexcept
|
|
125
|
+
: id_(other.id_), identity_(std::move(other.identity_)), nodeType{other.id_, identity_.get()}
|
|
126
|
+
{
|
|
127
|
+
other.nodeType.borrow(other.id_, nullptr);
|
|
128
|
+
}
|
|
129
|
+
NodeHandle &operator=(const NodeHandle &other)
|
|
130
|
+
{
|
|
131
|
+
if (this != &other) {
|
|
132
|
+
id_ = other.id_;
|
|
133
|
+
identity_ = other.identity_;
|
|
134
|
+
nodeType.borrow(id_, identity_.get());
|
|
135
|
+
}
|
|
136
|
+
return *this;
|
|
137
|
+
}
|
|
138
|
+
NodeHandle &operator=(NodeHandle &&other) noexcept
|
|
139
|
+
{
|
|
140
|
+
if (this != &other) {
|
|
141
|
+
id_ = other.id_;
|
|
142
|
+
identity_ = std::move(other.identity_);
|
|
143
|
+
nodeType.borrow(id_, identity_.get());
|
|
144
|
+
other.nodeType.borrow(other.id_, nullptr);
|
|
145
|
+
}
|
|
146
|
+
return *this;
|
|
147
|
+
}
|
|
67
148
|
const void *identity() const { return identity_.get(); }
|
|
68
149
|
std::shared_ptr<const void> weakIdentityOwner() const { return identity_; }
|
|
69
150
|
// Event targets and DOM elements are two views of the same tree identity.
|
|
70
151
|
// Pointer/touch event targets declared as Element therefore project to a
|
|
71
152
|
// full node handle without boxing or losing the source node id.
|
|
72
153
|
NodeHandle(const gea::framework::events::EventTarget &target)
|
|
73
|
-
: id_(target.id()), identity_(target.identityOwner()), nodeType{target.id(), identity_} {}
|
|
154
|
+
: id_(target.id()), identity_(target.identityOwner()), nodeType{target.id(), identity_.get()} {}
|
|
74
155
|
// Implicit build from a boxed node value (record carrying "__gea_node_id"),
|
|
75
156
|
// so the compiled-component emitters' `NodeHandle x = <gea_cpp_value>` copy-
|
|
76
157
|
// inits and NodeHandle-typed args accept a boxed node. SFINAE'd on
|
|
@@ -118,11 +199,27 @@ public:
|
|
|
118
199
|
NodeHandle querySelector(const std::string &s) const { return querySelector(selectorText(s)); }
|
|
119
200
|
std::vector<NodeHandle> querySelectorAll(const std::string &s) const { return querySelectorAll(selectorText(s)); }
|
|
120
201
|
explicit operator bool() const { return valid(); }
|
|
121
|
-
|
|
202
|
+
// Shares this handle's owner instead of looking the id up again; the
|
|
203
|
+
// Style validates it on every use, as it validated its own lookup.
|
|
204
|
+
Style style() const { return Style(id_, identity_); }
|
|
205
|
+
// `style().setNumberProperty(...)` without the Style: it would take a
|
|
206
|
+
// second owner of this handle's identity just to forward the write.
|
|
207
|
+
bool setStyleNumberProperty(const std::string &property, double value) const;
|
|
122
208
|
ClassList classList() const { return ClassList(id()); }
|
|
123
209
|
|
|
124
210
|
NodeTypeProperty nodeType;
|
|
125
211
|
|
|
212
|
+
private:
|
|
213
|
+
friend class Style;
|
|
214
|
+
struct Borrowed {};
|
|
215
|
+
// Shares `owner`'s token without a reference count, for a handle that
|
|
216
|
+
// lives only inside one call while the caller (a Style) holds `owner`.
|
|
217
|
+
// Copies of it do not keep the token alive, so it is never stored.
|
|
218
|
+
NodeHandle(int id, const gea::framework::identity::Owner &owner, Borrowed)
|
|
219
|
+
: id_(id), identity_(gea::framework::identity::Owner{}, owner.get()), nodeType{id, identity_.get()} {}
|
|
220
|
+
|
|
221
|
+
public:
|
|
222
|
+
|
|
126
223
|
NodeHandle cloneNode(bool deep = true) const;
|
|
127
224
|
// Named *Handle to avoid colliding with the DOM `firstChild` PROPERTY
|
|
128
225
|
// lowering (gea_ir::domFirstChild), which geatsc resolves on Node-typed
|
package/ui/node_features.h
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
#ifndef GEA_UI_INPUT_NODES
|
|
9
9
|
#define GEA_UI_INPUT_NODES 1
|
|
10
10
|
#endif
|
|
11
|
+
// Without a <video> node the build omits the video host and its frame phase.
|
|
12
|
+
#ifndef GEA_UI_VIDEO_NODES
|
|
13
|
+
#define GEA_UI_VIDEO_NODES 1
|
|
14
|
+
#endif
|
|
11
15
|
|
|
12
16
|
// Generated from the whole-source class-token bound. Unknown programs retain
|
|
13
17
|
// four inline entries. Overflow support is independent of this capacity.
|
package/ui/render.cpp
CHANGED
|
@@ -4880,6 +4880,60 @@ int gLastScrollUiFrame = -1000;
|
|
|
4880
4880
|
return coverage;
|
|
4881
4881
|
}
|
|
4882
4882
|
|
|
4883
|
+
// Where a rounded-rect contour's left and right edges run across the pixel
|
|
4884
|
+
// row [y, y + 1): each edge is monotone within a corner, so its extremes
|
|
4885
|
+
// over the row sit at the row's ends or where a corner meets a straight
|
|
4886
|
+
// side. Mirrors roundedRectContainsFast's corner order (tl before bl, tr
|
|
4887
|
+
// before br).
|
|
4888
|
+
struct RoundedRowEdges
|
|
4889
|
+
{
|
|
4890
|
+
bool any = false; // the contour reaches into the row
|
|
4891
|
+
bool whole = false; // the row lies wholly within its vertical extent
|
|
4892
|
+
float lMin = 0, lMax = 0, rMin = 0, rMax = 0;
|
|
4893
|
+
};
|
|
4894
|
+
|
|
4895
|
+
RoundedRowEdges roundedRectRowEdges(const TransformedRoundedRectCommand &r, int y)
|
|
4896
|
+
{
|
|
4897
|
+
RoundedRowEdges e;
|
|
4898
|
+
if (r.lw <= 0 || r.lh <= 0)
|
|
4899
|
+
return e;
|
|
4900
|
+
const float left = static_cast<float>(r.lx), top = static_cast<float>(r.ly);
|
|
4901
|
+
const float right = left + static_cast<float>(r.lw), bottom = top + static_cast<float>(r.lh);
|
|
4902
|
+
const float y0 = std::max(static_cast<float>(y), top), y1 = std::min(static_cast<float>(y + 1), bottom);
|
|
4903
|
+
if (y1 <= y0)
|
|
4904
|
+
return e;
|
|
4905
|
+
e.any = true;
|
|
4906
|
+
e.whole = static_cast<float>(y) >= top && static_cast<float>(y + 1) <= bottom;
|
|
4907
|
+
const auto radius = [](int16_t r8) { return static_cast<float>(std::max(0, static_cast<int>(r8))) * 0.125f; };
|
|
4908
|
+
const float tlRx = radius(r.tlRx8), tlRy = radius(r.tlRy8), trRx = radius(r.trRx8), trRy = radius(r.trRy8);
|
|
4909
|
+
const float brRx = radius(r.brRx8), brRy = radius(r.brRy8), blRx = radius(r.blRx8), blRy = radius(r.blRy8);
|
|
4910
|
+
const auto inset = [](float rx, float ry, float dy) {
|
|
4911
|
+
const float t = dy / ry;
|
|
4912
|
+
return rx - rx * std::sqrt(std::max(0.0f, 1.0f - t * t));
|
|
4913
|
+
};
|
|
4914
|
+
const auto leftAt = [&](float sy) {
|
|
4915
|
+
if (tlRx > 0 && tlRy > 0 && sy < top + tlRy) return left + inset(tlRx, tlRy, top + tlRy - sy);
|
|
4916
|
+
if (blRx > 0 && blRy > 0 && sy >= bottom - blRy) return left + inset(blRx, blRy, sy - (bottom - blRy));
|
|
4917
|
+
return left;
|
|
4918
|
+
};
|
|
4919
|
+
const auto rightAt = [&](float sy) {
|
|
4920
|
+
if (trRx > 0 && trRy > 0 && sy < top + trRy) return right - inset(trRx, trRy, top + trRy - sy);
|
|
4921
|
+
if (brRx > 0 && brRy > 0 && sy >= bottom - brRy) return right - inset(brRx, brRy, sy - (bottom - brRy));
|
|
4922
|
+
return right;
|
|
4923
|
+
};
|
|
4924
|
+
const float probes[6] = {y0, y1, top + tlRy, bottom - blRy, top + trRy, bottom - brRy};
|
|
4925
|
+
e.lMin = e.rMin = 1e9f;
|
|
4926
|
+
e.lMax = e.rMax = -1e9f;
|
|
4927
|
+
for (int i = 0; i < 6; ++i)
|
|
4928
|
+
{
|
|
4929
|
+
const float sy = std::clamp(probes[i], y0, y1);
|
|
4930
|
+
const float l = leftAt(sy), rr = rightAt(sy);
|
|
4931
|
+
e.lMin = std::min(e.lMin, l); e.lMax = std::max(e.lMax, l);
|
|
4932
|
+
e.rMin = std::min(e.rMin, rr); e.rMax = std::max(e.rMax, rr);
|
|
4933
|
+
}
|
|
4934
|
+
return e;
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4883
4937
|
void drawCssRoundedBorder(const DisplayCommand &command)
|
|
4884
4938
|
{
|
|
4885
4939
|
const auto &s = command.strokeRoundedRect;
|
|
@@ -4923,7 +4977,31 @@ int gLastScrollUiFrame = -1000;
|
|
|
4923
4977
|
for (int x = std::max(x0, innerX1); x <= x1; ++x) paintCoveragePixel(row[x], s.color, alpha, full, full);
|
|
4924
4978
|
continue;
|
|
4925
4979
|
}
|
|
4926
|
-
|
|
4980
|
+
// Only pixels within a pixel of a contour edge need the per-pixel
|
|
4981
|
+
// test; the rest of the row is plainly outside the ring, inside the
|
|
4982
|
+
// border, or inside the hole. A large ellipse is all corner box, so
|
|
4983
|
+
// testing every pixel of it costs a frame per pass.
|
|
4984
|
+
const RoundedRowEdges oe = roundedRectRowEdges(outer, y), ie = roundedRectRowEdges(inner, y);
|
|
4985
|
+
if (!oe.any)
|
|
4986
|
+
continue;
|
|
4987
|
+
const int oL0 = static_cast<int>(std::floor(oe.lMin)) - 1, oL1 = static_cast<int>(std::ceil(oe.lMax)) + 1;
|
|
4988
|
+
const int oR0 = static_cast<int>(std::floor(oe.rMin)) - 1, oR1 = static_cast<int>(std::ceil(oe.rMax)) + 1;
|
|
4989
|
+
const int iL0 = static_cast<int>(std::floor(ie.lMin)) - 1, iL1 = static_cast<int>(std::ceil(ie.lMax)) + 1;
|
|
4990
|
+
const int iR0 = static_cast<int>(std::floor(ie.rMin)) - 1, iR1 = static_cast<int>(std::ceil(ie.rMax)) + 1;
|
|
4991
|
+
for (int x = std::max(x0, oL0); x <= std::min(x1, oR1); ++x) {
|
|
4992
|
+
if (oe.whole && x > oL1 && x < oR0 && (!ie.any || ie.whole))
|
|
4993
|
+
{
|
|
4994
|
+
if (!ie.any || x < iL0 || x > iR1)
|
|
4995
|
+
{
|
|
4996
|
+
paintCoveragePixel(row[x], s.color, alpha, full, full);
|
|
4997
|
+
continue;
|
|
4998
|
+
}
|
|
4999
|
+
if (x > iL1 && x < iR0)
|
|
5000
|
+
{
|
|
5001
|
+
x = iR0 - 1; // inside the hole: nothing to paint
|
|
5002
|
+
continue;
|
|
5003
|
+
}
|
|
5004
|
+
}
|
|
4927
5005
|
int coverage;
|
|
4928
5006
|
if (cornerRow && (x < cornerX0 || x >= cornerX1))
|
|
4929
5007
|
{
|
|
@@ -721,9 +721,18 @@ int RootScrollOnlyRefresh::refresh(int root, int width, int height)
|
|
|
721
721
|
// the post-shift positions, so for a masked scroller we skip the blit and
|
|
722
722
|
// re-rasterize the whole viewport from that list — the fade stays anchored.
|
|
723
723
|
const bool contentHasRightFadeMask = hasRightFadeMask(state, scroll_node);
|
|
724
|
+
// A software-rotated canvas (e.g. a 172x640 panel driven as 640x172)
|
|
725
|
+
// stores logical rows as framebuffer columns; neither the scroll-register
|
|
726
|
+
// row remap nor the pixel blit shifts it correctly, and the stale pixels
|
|
727
|
+
// left behind showed as content drawn over itself. Re-rasterize the whole
|
|
728
|
+
// viewport from the rebuilt display list instead.
|
|
729
|
+
bool blitScroll = !contentHasRightFadeMask;
|
|
730
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
731
|
+
if (auto *canvas = gea::platform::display::Display::canvas(); canvas && canvas->isLandscapeRotated()) blitScroll = false;
|
|
732
|
+
#endif
|
|
724
733
|
|
|
725
734
|
const int viewportExtent = horizontal ? vw : vh;
|
|
726
|
-
if (
|
|
735
|
+
if (blitScroll && abs_move > 0 && abs_move < viewportExtent) {
|
|
727
736
|
const std::int64_t scrollRectStartUs = refreshPerfNowUs();
|
|
728
737
|
gea::platform::display::Display::scrollRect(vx, vy, vw, vh, horizontal ? move : 0, horizontal ? 0 : move);
|
|
729
738
|
GEA_REFRESH_PERF(perf.rootScrollScrollRectUs += refreshPerfNowUs() - scrollRectStartUs);
|
package/ui/style.cpp
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
#include <algorithm>
|
|
18
18
|
#include <array>
|
|
19
|
+
#include <atomic>
|
|
19
20
|
#include <cctype>
|
|
20
21
|
#include <cmath>
|
|
21
22
|
#include <cstdint>
|
|
@@ -1656,7 +1657,9 @@ enum class LengthAxis {
|
|
|
1656
1657
|
bool propertyAffectsDescendantStyle(Property property);
|
|
1657
1658
|
void recomputeDescendantClassStyles(int node);
|
|
1658
1659
|
void recomputeSubtreeClassStyles(int node);
|
|
1659
|
-
void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source);
|
|
1660
|
+
void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source);
|
|
1661
|
+
void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source);
|
|
1662
|
+
void setInlineStyleValue(int nodeId, Property property, int value);
|
|
1660
1663
|
struct ActiveRulePlan;
|
|
1661
1664
|
#if GEA_CSS_ANIMATIONS
|
|
1662
1665
|
void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan = nullptr);
|
|
@@ -8518,16 +8521,24 @@ bool setClassRuleValueFast(NodeHandle node, Property property, int value)
|
|
|
8518
8521
|
return setClassRuleValueFastUnchecked(target, property, value);
|
|
8519
8522
|
}
|
|
8520
8523
|
|
|
8521
|
-
void setStyleValue(NodeHandle node, Property property, int value, StyleApplicationSource source)
|
|
8524
|
+
void setStyleValue(const NodeHandle &node, Property property, int value, StyleApplicationSource source)
|
|
8525
|
+
{
|
|
8526
|
+
// One validity check; a Style would copy the owner only to check it again.
|
|
8527
|
+
const int id = node.id();
|
|
8528
|
+
if (id < 0) return;
|
|
8529
|
+
setValidatedStyleValue(node, id, property, value, source);
|
|
8530
|
+
}
|
|
8531
|
+
|
|
8532
|
+
// setStyleValue for a caller that has already resolved `node`'s live `id`.
|
|
8533
|
+
void setValidatedStyleValue(const NodeHandle &node, int id, Property property, int value, StyleApplicationSource source)
|
|
8522
8534
|
{
|
|
8523
|
-
if (!node) return;
|
|
8524
8535
|
if (source == StyleApplicationSource::ClassRule) {
|
|
8525
|
-
if (
|
|
8526
|
-
if (
|
|
8536
|
+
if (id == g_resolvedFontNode && isFontMetricProperty(property)) return;
|
|
8537
|
+
if (id == g_resolvedLineHeightNode && isLineHeightProperty(property)) return;
|
|
8527
8538
|
if (setClassRuleValueFast(node, property, value)) return;
|
|
8528
|
-
Tree::instance().setStyleFromClass(
|
|
8539
|
+
Tree::instance().setStyleFromClass(id, property, value);
|
|
8529
8540
|
} else {
|
|
8530
|
-
|
|
8541
|
+
setInlineStyleValue(id, property, value);
|
|
8531
8542
|
}
|
|
8532
8543
|
}
|
|
8533
8544
|
|
|
@@ -9236,6 +9247,24 @@ bool applyAnimatedTransformStyleValueFast(int nodeId, Property property, int val
|
|
|
9236
9247
|
return true;
|
|
9237
9248
|
}
|
|
9238
9249
|
|
|
9250
|
+
// Style::set for a node id its caller has validated.
|
|
9251
|
+
void setInlineStyleValue(int nodeId, Property property, int value)
|
|
9252
|
+
{
|
|
9253
|
+
if (nodeId < 0) return;
|
|
9254
|
+
#if GEA_CSS_ANIMATIONS
|
|
9255
|
+
double before = 0;
|
|
9256
|
+
const bool transition = inlineTransitionBefore(nodeId, property, before);
|
|
9257
|
+
#endif
|
|
9258
|
+
Tree::instance().setStyle(nodeId, property, value);
|
|
9259
|
+
#if GEA_CSS_ANIMATIONS
|
|
9260
|
+
if (transition) applyInlineTransition(nodeId, property, before);
|
|
9261
|
+
#endif
|
|
9262
|
+
// This element's cascaded lengths can depend on its own font too. Updating
|
|
9263
|
+
// descendants alone leaves, for example, class padding in ch at old metrics.
|
|
9264
|
+
if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId);
|
|
9265
|
+
else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId);
|
|
9266
|
+
}
|
|
9267
|
+
|
|
9239
9268
|
} // namespace
|
|
9240
9269
|
|
|
9241
9270
|
StorageUsage styleDependencyStorageUsage()
|
|
@@ -9330,19 +9359,7 @@ bool resolveLayoutBoxLengths(int nodeId, int percentageBasis)
|
|
|
9330
9359
|
|
|
9331
9360
|
void Style::set(Property property, int value) const
|
|
9332
9361
|
{
|
|
9333
|
-
|
|
9334
|
-
#if GEA_CSS_ANIMATIONS
|
|
9335
|
-
double before = 0;
|
|
9336
|
-
const bool transition = inlineTransitionBefore(nodeId(), property, before);
|
|
9337
|
-
#endif
|
|
9338
|
-
Tree::instance().setStyle(nodeId(), property, value);
|
|
9339
|
-
#if GEA_CSS_ANIMATIONS
|
|
9340
|
-
if (transition) applyInlineTransition(nodeId(), property, before);
|
|
9341
|
-
#endif
|
|
9342
|
-
// This element's cascaded lengths can depend on its own font too. Updating
|
|
9343
|
-
// descendants alone leaves, for example, class padding in ch at old metrics.
|
|
9344
|
-
if (isFontMetricProperty(property) || isLineHeightProperty(property)) recomputeSubtreeClassStyles(nodeId());
|
|
9345
|
-
else if (propertyAffectsDescendantStyle(property)) recomputeDescendantClassStyles(nodeId());
|
|
9362
|
+
setInlineStyleValue(nodeId(), property, value);
|
|
9346
9363
|
}
|
|
9347
9364
|
|
|
9348
9365
|
void Style::backgroundColor(int rgb565) const
|
|
@@ -9354,19 +9371,29 @@ void Style::backgroundColor(int rgb565) const
|
|
|
9354
9371
|
void Style::setProperty(const std::string &property, const std::string &value) const
|
|
9355
9372
|
{
|
|
9356
9373
|
if (nodeId() < 0) return;
|
|
9357
|
-
StyleSheet::instance().applyProperty(NodeHandle(
|
|
9374
|
+
StyleSheet::instance().applyProperty(NodeHandle(nodeId_, identity_), property, value);
|
|
9375
|
+
}
|
|
9376
|
+
|
|
9377
|
+
bool NodeHandle::setStyleNumberProperty(const std::string &property, double value) const
|
|
9378
|
+
{
|
|
9379
|
+
// applyNumberDeclarationWithSource validates this handle; no Style, so no
|
|
9380
|
+
// second identity owner for the write.
|
|
9381
|
+
return StyleSheet::instance().applyNumberProperty(*this, property.c_str(), value);
|
|
9358
9382
|
}
|
|
9359
9383
|
|
|
9360
9384
|
bool Style::setNumberProperty(const std::string &property, double value) const
|
|
9361
9385
|
{
|
|
9362
9386
|
if (nodeId() < 0) return false;
|
|
9363
|
-
|
|
9387
|
+
// This Style holds the validated owner for the whole call, and numeric
|
|
9388
|
+
// style application keeps node ids, not handles, so the handle borrows it.
|
|
9389
|
+
return StyleSheet::instance().applyNumberProperty(NodeHandle(nodeId_, identity_, NodeHandle::Borrowed{}),
|
|
9390
|
+
property.c_str(), value);
|
|
9364
9391
|
}
|
|
9365
9392
|
|
|
9366
9393
|
bool Style::removeProperty(const std::string &property) const
|
|
9367
9394
|
{
|
|
9368
9395
|
if (nodeId() < 0) return false;
|
|
9369
|
-
return StyleSheet::instance().removeProperty(NodeHandle(
|
|
9396
|
+
return StyleSheet::instance().removeProperty(NodeHandle(nodeId_, identity_), property);
|
|
9370
9397
|
}
|
|
9371
9398
|
|
|
9372
9399
|
void applyAnimatedStyleValue(int nodeId, Property property, int value)
|
|
@@ -9434,145 +9461,147 @@ void applyInheritedStyleDefaults(int node)
|
|
|
9434
9461
|
#endif
|
|
9435
9462
|
}
|
|
9436
9463
|
|
|
9437
|
-
bool applyNumberDeclarationWithSource(NodeHandle node,
|
|
9464
|
+
bool applyNumberDeclarationWithSource(const NodeHandle &node,
|
|
9438
9465
|
CssDeclarationId declaration,
|
|
9439
9466
|
double value,
|
|
9440
9467
|
StyleApplicationSource source)
|
|
9441
9468
|
{
|
|
9442
|
-
|
|
9469
|
+
// The node is validated once here; its writes below reuse the live id.
|
|
9470
|
+
const int id = node.id();
|
|
9471
|
+
if (id < 0) return false;
|
|
9443
9472
|
const int length = numericLength(value);
|
|
9444
9473
|
switch (declaration) {
|
|
9445
9474
|
case CssDeclarationId::Order:
|
|
9446
9475
|
if (std::isfinite(value) && std::trunc(value) == value)
|
|
9447
|
-
|
|
9476
|
+
setValidatedStyleValue(node, id, Property::Order, static_cast<int>(std::clamp(value, -2147483648.0, 2147483647.0)), source);
|
|
9448
9477
|
return true;
|
|
9449
9478
|
case CssDeclarationId::Gap:
|
|
9450
|
-
|
|
9479
|
+
setValidatedStyleValue(node, id, Property::Gap, length, source);
|
|
9451
9480
|
return true;
|
|
9452
9481
|
case CssDeclarationId::Width:
|
|
9453
|
-
|
|
9482
|
+
setValidatedStyleValue(node, id, Property::Width, length, source);
|
|
9454
9483
|
return true;
|
|
9455
9484
|
case CssDeclarationId::Height:
|
|
9456
|
-
|
|
9485
|
+
setValidatedStyleValue(node, id, Property::Height, length, source);
|
|
9457
9486
|
return true;
|
|
9458
9487
|
case CssDeclarationId::MinWidth:
|
|
9459
|
-
|
|
9488
|
+
setValidatedStyleValue(node, id, Property::MinWidth, length, source);
|
|
9460
9489
|
return true;
|
|
9461
9490
|
case CssDeclarationId::MinHeight:
|
|
9462
|
-
|
|
9491
|
+
setValidatedStyleValue(node, id, Property::MinHeight, length, source);
|
|
9463
9492
|
return true;
|
|
9464
9493
|
case CssDeclarationId::MaxWidth:
|
|
9465
|
-
|
|
9494
|
+
setValidatedStyleValue(node, id, Property::MaxWidth, length, source);
|
|
9466
9495
|
return true;
|
|
9467
9496
|
case CssDeclarationId::MaxHeight:
|
|
9468
|
-
|
|
9497
|
+
setValidatedStyleValue(node, id, Property::MaxHeight, length, source);
|
|
9469
9498
|
return true;
|
|
9470
9499
|
case CssDeclarationId::Flex:
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9500
|
+
setValidatedStyleValue(node, id, Property::Flex, rawNumber(value), source);
|
|
9501
|
+
setValidatedStyleValue(node, id, Property::FlexShrink, rawNumber(1.0), source);
|
|
9502
|
+
setValidatedStyleValue(node, id, Property::FlexBasis, kUnset, source); // numeric `flex: N` has no explicit basis
|
|
9474
9503
|
return true;
|
|
9475
9504
|
case CssDeclarationId::Padding:
|
|
9476
9505
|
setAllPadding(node, length, source);
|
|
9477
9506
|
return true;
|
|
9478
9507
|
case CssDeclarationId::PaddingTop:
|
|
9479
|
-
|
|
9508
|
+
setValidatedStyleValue(node, id, Property::PaddingTop, length, source);
|
|
9480
9509
|
return true;
|
|
9481
9510
|
case CssDeclarationId::PaddingRight:
|
|
9482
|
-
|
|
9511
|
+
setValidatedStyleValue(node, id, Property::PaddingRight, length, source);
|
|
9483
9512
|
return true;
|
|
9484
9513
|
case CssDeclarationId::PaddingBottom:
|
|
9485
|
-
|
|
9514
|
+
setValidatedStyleValue(node, id, Property::PaddingBottom, length, source);
|
|
9486
9515
|
return true;
|
|
9487
9516
|
case CssDeclarationId::PaddingLeft:
|
|
9488
|
-
|
|
9517
|
+
setValidatedStyleValue(node, id, Property::PaddingLeft, length, source);
|
|
9489
9518
|
return true;
|
|
9490
9519
|
case CssDeclarationId::Margin:
|
|
9491
9520
|
setAllMargin(node, length, source);
|
|
9492
9521
|
return true;
|
|
9493
9522
|
case CssDeclarationId::MarginTop:
|
|
9494
|
-
|
|
9523
|
+
setValidatedStyleValue(node, id, Property::MarginTop, length, source);
|
|
9495
9524
|
return true;
|
|
9496
9525
|
case CssDeclarationId::MarginRight:
|
|
9497
|
-
|
|
9526
|
+
setValidatedStyleValue(node, id, Property::MarginRight, length, source);
|
|
9498
9527
|
return true;
|
|
9499
9528
|
case CssDeclarationId::MarginBottom:
|
|
9500
|
-
|
|
9529
|
+
setValidatedStyleValue(node, id, Property::MarginBottom, length, source);
|
|
9501
9530
|
return true;
|
|
9502
9531
|
case CssDeclarationId::MarginLeft:
|
|
9503
|
-
|
|
9532
|
+
setValidatedStyleValue(node, id, Property::MarginLeft, length, source);
|
|
9504
9533
|
return true;
|
|
9505
9534
|
case CssDeclarationId::Top:
|
|
9506
|
-
|
|
9535
|
+
setValidatedStyleValue(node, id, Property::Top, length, source);
|
|
9507
9536
|
return true;
|
|
9508
9537
|
case CssDeclarationId::Right:
|
|
9509
|
-
|
|
9538
|
+
setValidatedStyleValue(node, id, Property::Right, length, source);
|
|
9510
9539
|
return true;
|
|
9511
9540
|
case CssDeclarationId::Bottom:
|
|
9512
|
-
|
|
9541
|
+
setValidatedStyleValue(node, id, Property::Bottom, length, source);
|
|
9513
9542
|
return true;
|
|
9514
9543
|
case CssDeclarationId::Left:
|
|
9515
|
-
|
|
9544
|
+
setValidatedStyleValue(node, id, Property::Left, length, source);
|
|
9516
9545
|
return true;
|
|
9517
9546
|
case CssDeclarationId::ZIndex:
|
|
9518
|
-
|
|
9547
|
+
setValidatedStyleValue(node, id, Property::ZIndex, rawNumber(value), source);
|
|
9519
9548
|
return true;
|
|
9520
9549
|
case CssDeclarationId::Opacity:
|
|
9521
|
-
|
|
9550
|
+
setValidatedStyleValue(node, id, Property::Opacity, numericOpacity(value), source);
|
|
9522
9551
|
return true;
|
|
9523
9552
|
case CssDeclarationId::BorderWidth:
|
|
9524
9553
|
if (value >= 0.0 && std::isfinite(value)) setUniformBorderWidth(node, snapBorderWidth(value), source);
|
|
9525
9554
|
return true;
|
|
9526
9555
|
case CssDeclarationId::BorderTopWidth:
|
|
9527
|
-
if (value >= 0.0 && std::isfinite(value))
|
|
9556
|
+
if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderTopWidth, snapBorderWidth(value), source);
|
|
9528
9557
|
return true;
|
|
9529
9558
|
case CssDeclarationId::BorderRightWidth:
|
|
9530
|
-
if (value >= 0.0 && std::isfinite(value))
|
|
9559
|
+
if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderRightWidth, snapBorderWidth(value), source);
|
|
9531
9560
|
return true;
|
|
9532
9561
|
case CssDeclarationId::BorderBottomWidth:
|
|
9533
|
-
if (value >= 0.0 && std::isfinite(value))
|
|
9562
|
+
if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderBottomWidth, snapBorderWidth(value), source);
|
|
9534
9563
|
return true;
|
|
9535
9564
|
case CssDeclarationId::BorderLeftWidth:
|
|
9536
|
-
if (value >= 0.0 && std::isfinite(value))
|
|
9565
|
+
if (value >= 0.0 && std::isfinite(value)) setValidatedStyleValue(node, id, Property::BorderLeftWidth, snapBorderWidth(value), source);
|
|
9537
9566
|
return true;
|
|
9538
9567
|
case CssDeclarationId::BorderRadius:
|
|
9539
9568
|
setAllBorderRadius(node, length, source);
|
|
9540
9569
|
return true;
|
|
9541
9570
|
case CssDeclarationId::BorderTopLeftRadius:
|
|
9542
|
-
|
|
9571
|
+
setValidatedStyleValue(node, id, Property::BorderRadiusTopLeft, length, source);
|
|
9543
9572
|
return true;
|
|
9544
9573
|
case CssDeclarationId::BorderTopRightRadius:
|
|
9545
|
-
|
|
9574
|
+
setValidatedStyleValue(node, id, Property::BorderRadiusTopRight, length, source);
|
|
9546
9575
|
return true;
|
|
9547
9576
|
case CssDeclarationId::BorderBottomRightRadius:
|
|
9548
|
-
|
|
9577
|
+
setValidatedStyleValue(node, id, Property::BorderRadiusBottomRight, length, source);
|
|
9549
9578
|
return true;
|
|
9550
9579
|
case CssDeclarationId::BorderBottomLeftRadius:
|
|
9551
|
-
|
|
9580
|
+
setValidatedStyleValue(node, id, Property::BorderRadiusBottomLeft, length, source);
|
|
9552
9581
|
return true;
|
|
9553
9582
|
case CssDeclarationId::FontSize:
|
|
9554
|
-
|
|
9583
|
+
setValidatedStyleValue(node, id, Property::FontSize, length, source);
|
|
9555
9584
|
return true;
|
|
9556
9585
|
#if GEA_CSS_FONT_STRETCH
|
|
9557
9586
|
case CssDeclarationId::FontStretch:
|
|
9558
9587
|
if (!std::isfinite(value) || value <= 0) return false;
|
|
9559
|
-
|
|
9588
|
+
setValidatedStyleValue(node, id, Property::FontStretch, std::clamp(roundToInt(std::clamp(value, 0.1, 3276.7) * 10), 1, 32767), source);
|
|
9560
9589
|
return true;
|
|
9561
9590
|
#endif
|
|
9562
9591
|
case CssDeclarationId::FontWeight:
|
|
9563
|
-
|
|
9592
|
+
setValidatedStyleValue(node, id, Property::FontWeight, std::clamp(roundToInt(value), 1, 1000), source);
|
|
9564
9593
|
return true;
|
|
9565
9594
|
case CssDeclarationId::LineHeight: {
|
|
9566
9595
|
const float multiplier = static_cast<float>(value);
|
|
9567
9596
|
if (!std::isfinite(multiplier) || multiplier < 0) return false;
|
|
9568
9597
|
int bits = 0; if (multiplier != 0) std::memcpy(&bits, &multiplier, sizeof(bits));
|
|
9569
|
-
|
|
9598
|
+
setValidatedStyleValue(node, id, Property::LineHeightMultiplier, bits, source);
|
|
9570
9599
|
return true;
|
|
9571
9600
|
}
|
|
9572
9601
|
#if GEA_CSS_TRANSFORMS
|
|
9573
9602
|
case CssDeclarationId::Transform:
|
|
9574
|
-
|
|
9575
|
-
|
|
9603
|
+
setValidatedStyleValue(node, id, Property::TransformPresent, 1, source);
|
|
9604
|
+
setValidatedStyleValue(node, id, Property::TransformRotate, numericRotateTenths(value), source);
|
|
9576
9605
|
return true;
|
|
9577
9606
|
case CssDeclarationId::Rotate: {
|
|
9578
9607
|
IndividualRotation rotation; rotation.angle = numericRotateTenths(value);
|
|
@@ -9589,9 +9618,10 @@ bool applyNumberDeclarationWithSource(NodeHandle node,
|
|
|
9589
9618
|
}
|
|
9590
9619
|
}
|
|
9591
9620
|
|
|
9592
|
-
bool applyNumberPropertyWithSource(NodeHandle node, const char *property, double value, StyleApplicationSource source)
|
|
9621
|
+
bool applyNumberPropertyWithSource(const NodeHandle &node, const char *property, double value, StyleApplicationSource source)
|
|
9593
9622
|
{
|
|
9594
|
-
|
|
9623
|
+
// applyNumberDeclarationWithSource validates the node first.
|
|
9624
|
+
if (!property) return false;
|
|
9595
9625
|
return applyNumberDeclarationWithSource(node, classifyDeclaration(property), value, source);
|
|
9596
9626
|
}
|
|
9597
9627
|
|
|
@@ -17788,6 +17818,22 @@ void endStyleMountBatch()
|
|
|
17788
17818
|
if (!covered) topRoots.push_back(node);
|
|
17789
17819
|
}
|
|
17790
17820
|
|
|
17821
|
+
// `:root` matches the tree root, and mount() hangs the app under a tagless,
|
|
17822
|
+
// classless wrapper that no class change ever queues. Left unstyled, its
|
|
17823
|
+
// `:root { --x: ... }` declarations never land, every var() below it falls
|
|
17824
|
+
// back to nothing (no backgrounds, default text colour), and repaints then
|
|
17825
|
+
// draw over stale pixels. Style each pending subtree's tree root first so
|
|
17826
|
+
// its custom properties exist before descendants resolve them.
|
|
17827
|
+
std::vector<int> styledTreeRoots;
|
|
17828
|
+
for (const int node : topRoots) {
|
|
17829
|
+
int treeRoot = node;
|
|
17830
|
+
while (state.nodes[treeRoot].parent >= 0) treeRoot = state.nodes[treeRoot].parent;
|
|
17831
|
+
if (treeRoot == node || g_pendingRecomputeMark.contains(treeRoot)) continue;
|
|
17832
|
+
if (std::find(styledTreeRoots.begin(), styledTreeRoots.end(), treeRoot) != styledTreeRoots.end()) continue;
|
|
17833
|
+
styledTreeRoots.push_back(treeRoot);
|
|
17834
|
+
recomputeNodeClassStyles(treeRoot);
|
|
17835
|
+
}
|
|
17836
|
+
|
|
17791
17837
|
// Incremental recompute: a near-root class change (e.g. a theme switch) only
|
|
17792
17838
|
// re-styles nodes that actually depend on what changed; the rest keep their
|
|
17793
17839
|
// already-correct computed style. Equivalent to recomputeSubtreeClassStyles but
|
|
@@ -18545,12 +18591,12 @@ bool StyleSheet::applyPixelLengthProperty(NodeHandle node, StyleDeclaration decl
|
|
|
18545
18591
|
return false;
|
|
18546
18592
|
}
|
|
18547
18593
|
|
|
18548
|
-
bool StyleSheet::applyNumberProperty(NodeHandle node, const char *property, double value) const
|
|
18594
|
+
bool StyleSheet::applyNumberProperty(const NodeHandle &node, const char *property, double value) const
|
|
18549
18595
|
{
|
|
18550
18596
|
return applyNumberPropertyWithSource(node, property, value, StyleApplicationSource::Inline);
|
|
18551
18597
|
}
|
|
18552
18598
|
|
|
18553
|
-
bool StyleSheet::applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const
|
|
18599
|
+
bool StyleSheet::applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const
|
|
18554
18600
|
{
|
|
18555
18601
|
return applyNumberDeclarationWithSource(node, declaration, value, StyleApplicationSource::Inline);
|
|
18556
18602
|
}
|
|
@@ -18625,9 +18671,15 @@ void Tree::setClassName(int node, const char *className)
|
|
|
18625
18671
|
// growth, so tagFromId can hand out c_str() pointers that stay valid. Index 0
|
|
18626
18672
|
// is the empty tag, matching Node::tag_id's zero default.
|
|
18627
18673
|
namespace {
|
|
18674
|
+
// tagFromId runs for every node on every frame. Without hardware atomics
|
|
18675
|
+
// (ESP32-S3) a guarded function-local static takes an RTOS mutex on each
|
|
18676
|
+
// access, so later calls read the table through an acquire-loaded pointer.
|
|
18628
18677
|
std::deque<std::string> &tagTable()
|
|
18629
18678
|
{
|
|
18679
|
+
static std::atomic<std::deque<std::string> *> ready{nullptr};
|
|
18680
|
+
if (auto *table = ready.load(std::memory_order_acquire)) return *table;
|
|
18630
18681
|
static std::deque<std::string> table = {std::string()};
|
|
18682
|
+
ready.store(&table, std::memory_order_release);
|
|
18631
18683
|
return table;
|
|
18632
18684
|
}
|
|
18633
18685
|
} // namespace
|
package/ui/style.h
CHANGED
|
@@ -356,6 +356,7 @@ class Style {
|
|
|
356
356
|
public:
|
|
357
357
|
explicit Style(int nodeId = -1)
|
|
358
358
|
: nodeId_(nodeId), identity_(gea::framework::identity::node(nodeId)) {}
|
|
359
|
+
Style(int nodeId, gea::framework::identity::Owner owner) : nodeId_(nodeId), identity_(std::move(owner)) {}
|
|
359
360
|
|
|
360
361
|
int nodeId() const { return gea::framework::identity::current(nodeId_, identity_) ? nodeId_ : -1; }
|
|
361
362
|
void set(Property property, int value) const;
|
|
@@ -864,8 +865,8 @@ public:
|
|
|
864
865
|
void applyProperty(NodeHandle node, const std::string &property, const std::string &value) const;
|
|
865
866
|
// Preserve CSS px units through device scaling before property-specific rounding.
|
|
866
867
|
bool applyPixelLengthProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
|
|
867
|
-
bool applyNumberProperty(NodeHandle node, StyleDeclaration declaration, double value) const;
|
|
868
|
-
bool applyNumberProperty(NodeHandle node, const char *property, double value) const;
|
|
868
|
+
bool applyNumberProperty(const NodeHandle &node, StyleDeclaration declaration, double value) const;
|
|
869
|
+
bool applyNumberProperty(const NodeHandle &node, const char *property, double value) const;
|
|
869
870
|
bool removeProperty(NodeHandle node, const std::string &property) const;
|
|
870
871
|
void recomputeSubtree(int nodeId) const;
|
|
871
872
|
void hoverChanged() const;
|
package/ui/text.cpp
CHANGED
|
@@ -1895,6 +1895,12 @@ int TextRenderer::minContentWidth(const Node &node, int *pendingWord)
|
|
|
1895
1895
|
return width;
|
|
1896
1896
|
}
|
|
1897
1897
|
|
|
1898
|
+
int TextRenderer::maxContentWidth(const Node &node)
|
|
1899
|
+
{
|
|
1900
|
+
// The same unbounded measure remeasureContentBox gives natural-width text.
|
|
1901
|
+
return measureTextLayoutForNode(node, node.text.c_str(), 0x4000).width;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1898
1904
|
const char *TextRenderer::prepareText(const char *text, int textTransform, int whiteSpace, std::string &storage)
|
|
1899
1905
|
{
|
|
1900
1906
|
return textWithTransform(text, textTransform, storage, whiteSpace);
|
package/ui/tree_events.cpp
CHANGED
|
@@ -366,7 +366,15 @@ bool dispatchRootKeyEvent(gea::framework::events::PointerEvent &event, bool lega
|
|
|
366
366
|
using gea::framework::events::PointerEventType;
|
|
367
367
|
if (event.type != PointerEventType::KeyDown && event.type != PointerEventType::KeyUp) return false;
|
|
368
368
|
auto &tree = Tree::instance();
|
|
369
|
-
|
|
369
|
+
// With no focused input a hardware key belongs to the app: target its top
|
|
370
|
+
// element (the mount container's first child), so the event bubbles through
|
|
371
|
+
// the app root -- where apps bind onKeyDown -- and then the container. Aiming
|
|
372
|
+
// at the container itself skipped every app-level key handler.
|
|
373
|
+
if (event.targetId < 0) {
|
|
374
|
+
const int root = tree.mountedRoot();
|
|
375
|
+
const int app = tree.firstChildOf(root);
|
|
376
|
+
event.targetId = app >= 0 ? app : root;
|
|
377
|
+
}
|
|
370
378
|
event.target = gea::framework::events::EventTarget(event.targetId);
|
|
371
379
|
const auto path = captureEventPath(tree, event.targetId);
|
|
372
380
|
bool dispatched = dispatchWindowEvent(event, true);
|