@geastack/engine 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas.cpp +34 -0
- package/css/animation.h +64 -0
- package/css/engine.h +6 -1
- package/package.json +2 -2
- package/ui/absolute_leaf_refresh.cpp +32 -31
- package/ui/core.cpp +9 -1
- package/ui/display_invalidation.cpp +29 -0
- package/ui/flex_balance.h +73 -0
- package/ui/image_node.cpp +24 -20
- package/ui/input.cpp +66 -36
- package/ui/input_render.cpp +13 -13
- package/ui/internal.h +51 -5
- package/ui/layout.cpp +2472 -400
- package/ui/layout_snapshot.cpp +21 -5
- package/ui/node_lifecycle.cpp +28 -3
- package/ui/node_model.h +323 -23
- package/ui/render.cpp +638 -265
- package/ui/root_scroll_refresh.cpp +15 -10
- package/ui/style.cpp +3254 -935
- package/ui/style.h +143 -6
- package/ui/style_values.h +16 -0
- package/ui/text.cpp +378 -103
- package/ui/tree_events.cpp +6 -3
- package/ui/tree_events.h +1 -0
- package/ui/tree_internal.h +19 -0
- package/ui/tree_nodes.cpp +6 -0
- package/ui/tree_render.cpp +71 -21
- package/ui/tree_state.h +54 -0
- package/ui/tree_style.cpp +287 -27
- package/ui/view.cpp +612 -251
package/canvas.cpp
CHANGED
|
@@ -945,6 +945,40 @@ private:
|
|
|
945
945
|
int circleBoxSpanNext_ = 0;
|
|
946
946
|
};
|
|
947
947
|
|
|
948
|
+
pixel::native_t Canvas::readPixelNative(int x, int y) const
|
|
949
|
+
{
|
|
950
|
+
if (!pixels_ || x < 0 || x >= width_ || y < 0 || y >= height_) return 0;
|
|
951
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
952
|
+
if (landscapeRot_) return rotGet(x, y);
|
|
953
|
+
#endif
|
|
954
|
+
#if GEA_PIXEL_STORAGE_PACKED
|
|
955
|
+
return pixel::packed::get(packedRow(rowToPhysical(y)), x);
|
|
956
|
+
#else
|
|
957
|
+
return pixels_[rowToPhysical(y) * stride_ + x];
|
|
958
|
+
#endif
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
void Canvas::writePixelNativeExact(int x, int y, pixel::native_t value)
|
|
962
|
+
{
|
|
963
|
+
if (!pixels_ || x < 0 || x >= width_ || y < 0 || y >= height_) return;
|
|
964
|
+
if (x < clipStack_[clipDepth_].x0 || x > clipStack_[clipDepth_].x1 ||
|
|
965
|
+
y < clipStack_[clipDepth_].y0 || y > clipStack_[clipDepth_].y1)
|
|
966
|
+
return;
|
|
967
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
968
|
+
if (landscapeRot_) {
|
|
969
|
+
rotSet(x, y, value);
|
|
970
|
+
markDirty(x, y, x, y);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
#endif
|
|
974
|
+
#if GEA_PIXEL_STORAGE_PACKED
|
|
975
|
+
pixel::packed::set(packedRow(rowToPhysical(y)), x, value);
|
|
976
|
+
#else
|
|
977
|
+
pixels_[rowToPhysical(y) * stride_ + x] = value;
|
|
978
|
+
#endif
|
|
979
|
+
markDirty(x, y, x, y);
|
|
980
|
+
}
|
|
981
|
+
|
|
948
982
|
void Canvas::writePixelNative(int x, int y, pixel::native_t c)
|
|
949
983
|
{
|
|
950
984
|
if (!pixels_) return;
|
package/css/animation.h
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// (inline). Part of the gea CSS animation engine. See docs/geaos-grand-vision.md (M1).
|
|
8
8
|
|
|
9
9
|
#include <cmath>
|
|
10
|
+
#include <algorithm>
|
|
10
11
|
#include <cstdint>
|
|
11
12
|
#include <initializer_list>
|
|
12
13
|
#include <vector>
|
|
@@ -30,6 +31,7 @@ inline ValueKind kindOf(Property p)
|
|
|
30
31
|
case Property::Color:
|
|
31
32
|
case Property::BorderColor:
|
|
32
33
|
return ValueKind::Color;
|
|
34
|
+
case Property::RotateAngle:
|
|
33
35
|
case Property::TransformRotate:
|
|
34
36
|
case Property::TransformRotateX:
|
|
35
37
|
case Property::TransformRotateY:
|
|
@@ -119,11 +121,17 @@ private:
|
|
|
119
121
|
|
|
120
122
|
// One animated property on one node. A 2-keyframe track is a CSS transition; an
|
|
121
123
|
// N-keyframe track is a @keyframes rule. Easing applies per segment (CSS default).
|
|
124
|
+
struct RotationAxis { double x = 0, y = 0, z = 1; };
|
|
125
|
+
struct RotationValue { double angle; RotationAxis axis; };
|
|
126
|
+
|
|
122
127
|
struct Animation {
|
|
123
128
|
int nodeId = -1;
|
|
124
129
|
Property property = Property::Opacity;
|
|
125
130
|
ValueKind kind = ValueKind::Scalar;
|
|
126
131
|
KeyframeList keyframes; // >= 2, sorted by offset
|
|
132
|
+
// Only an individual rotate track owns axes. Keep its angle and axis coupled
|
|
133
|
+
// during interpolation; independent scalar axis tracks produce wrong turns.
|
|
134
|
+
std::vector<RotationAxis> rotationAxes;
|
|
127
135
|
Easing easing = Easing::ease();
|
|
128
136
|
uint32_t durationMs = 300;
|
|
129
137
|
uint32_t delayMs = 0;
|
|
@@ -147,6 +155,62 @@ struct Animation {
|
|
|
147
155
|
}
|
|
148
156
|
};
|
|
149
157
|
|
|
158
|
+
inline RotationValue sampleRotation(const Animation &a, double p)
|
|
159
|
+
{
|
|
160
|
+
const auto &kf = a.keyframes;
|
|
161
|
+
std::size_t i = 0;
|
|
162
|
+
while (i + 1 < kf.size() && kf[i + 1].offset <= p) ++i;
|
|
163
|
+
if (i + 1 == kf.size() || p <= kf.front().offset)
|
|
164
|
+
return {kf[i].value, a.rotationAxes[i]};
|
|
165
|
+
const double span = kf[i + 1].offset - kf[i].offset;
|
|
166
|
+
const double t = span > 0 ? (p - kf[i].offset) / span : 0;
|
|
167
|
+
const double u = a.easing.kind() == EasingKind::Linear ? t : a.easing(t);
|
|
168
|
+
RotationValue from{kf[i].value, a.rotationAxes[i]}, to{kf[i + 1].value, a.rotationAxes[i + 1]};
|
|
169
|
+
auto normalize = [](RotationValue &r) {
|
|
170
|
+
const double length = std::sqrt(r.axis.x*r.axis.x + r.axis.y*r.axis.y + r.axis.z*r.axis.z);
|
|
171
|
+
if (length == 0) { r.angle = 0; r.axis = {}; }
|
|
172
|
+
else { r.axis.x /= length; r.axis.y /= length; r.axis.z /= length; }
|
|
173
|
+
};
|
|
174
|
+
normalize(from); normalize(to);
|
|
175
|
+
const bool sameAxis = std::abs(from.axis.x-to.axis.x) < 1e-9 &&
|
|
176
|
+
std::abs(from.axis.y-to.axis.y) < 1e-9 && std::abs(from.axis.z-to.axis.z) < 1e-9;
|
|
177
|
+
// Preserve full turns about a common axis. An identity endpoint adopts the
|
|
178
|
+
// other endpoint's axis (CSS Transforms 2, interpolation of rotate3d).
|
|
179
|
+
if (sameAxis || from.angle == 0 || to.angle == 0)
|
|
180
|
+
return {lerp(from.angle, to.angle, u), from.angle != 0 ? from.axis : to.axis};
|
|
181
|
+
constexpr double radians = 3.14159265358979323846 / 180;
|
|
182
|
+
const double s0 = std::sin(from.angle*radians/2), s1 = std::sin(to.angle*radians/2);
|
|
183
|
+
double q0[4] = {from.axis.x*s0, from.axis.y*s0, from.axis.z*s0, std::cos(from.angle*radians/2)};
|
|
184
|
+
double q1[4] = {to.axis.x*s1, to.axis.y*s1, to.axis.z*s1, std::cos(to.angle*radians/2)};
|
|
185
|
+
double dot = 0;
|
|
186
|
+
for (int k = 0; k < 4; ++k) dot += q0[k]*q1[k];
|
|
187
|
+
if (dot < 0) { for (double &v : q1) v = -v; dot = -dot; }
|
|
188
|
+
dot = std::clamp(dot, 0.0, 1.0);
|
|
189
|
+
double w0 = 1-u, w1 = u;
|
|
190
|
+
if (dot < 0.999999) {
|
|
191
|
+
const double theta = std::acos(dot), divisor = std::sin(theta);
|
|
192
|
+
w0 = std::sin((1-u)*theta)/divisor; w1 = std::sin(u*theta)/divisor;
|
|
193
|
+
}
|
|
194
|
+
double q[4], norm = 0;
|
|
195
|
+
for (int k = 0; k < 4; ++k) { q[k] = w0*q0[k] + w1*q1[k]; norm += q[k]*q[k]; }
|
|
196
|
+
norm = std::sqrt(norm);
|
|
197
|
+
if (norm == 0) return {0, {}};
|
|
198
|
+
for (double &v : q) v /= norm;
|
|
199
|
+
const double axisLength = std::sqrt(q[0]*q[0]+q[1]*q[1]+q[2]*q[2]);
|
|
200
|
+
if (axisLength < 1e-12) return {0, {}};
|
|
201
|
+
return {2*std::atan2(axisLength, q[3])/radians, {q[0]/axisLength,q[1]/axisLength,q[2]/axisLength}};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
template <typename Apply>
|
|
205
|
+
inline void applyRotationSample(const Animation &a, double p, Apply apply)
|
|
206
|
+
{
|
|
207
|
+
const auto r = sampleRotation(a, p);
|
|
208
|
+
apply(Property::RotateAngle, static_cast<int>(std::llround(r.angle*10)));
|
|
209
|
+
apply(Property::RotateAxisX, static_cast<int>(std::llround(r.axis.x*1000000)));
|
|
210
|
+
apply(Property::RotateAxisY, static_cast<int>(std::llround(r.axis.y*1000000)));
|
|
211
|
+
apply(Property::RotateAxisZ, static_cast<int>(std::llround(r.axis.z*1000000)));
|
|
212
|
+
}
|
|
213
|
+
|
|
150
214
|
inline double sampleSegment(const Animation &a, const Keyframe &k0, const Keyframe &k1, double p)
|
|
151
215
|
{
|
|
152
216
|
const double span = k1.offset - k0.offset;
|
package/css/engine.h
CHANGED
|
@@ -65,7 +65,12 @@ public:
|
|
|
65
65
|
while (groupEnd < running_.size() && sameTimeline(first, running_[groupEnd])) ++groupEnd;
|
|
66
66
|
if (pr.active) {
|
|
67
67
|
for (std::size_t j = i; j < groupEnd; ++j) {
|
|
68
|
-
|
|
68
|
+
const auto &a = running_[j].anim;
|
|
69
|
+
if (!a.rotationAxes.empty())
|
|
70
|
+
applyRotationSample(a, pr.p, [&](Property property, int value) {
|
|
71
|
+
gea::embedded::ui::applyAnimatedStyleValue(a.nodeId, property, value);
|
|
72
|
+
});
|
|
73
|
+
else applyValue(a, sampleTrack(a, pr.p));
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
if (pr.done)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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.26"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -35,56 +35,42 @@ bool hasTransformState(const Node &node)
|
|
|
35
35
|
// fps before. A transform ADD routes through setStyle → clears the durable cache.
|
|
36
36
|
if (!ViewRenderer::anyTransformActive()) return false;
|
|
37
37
|
const RareStyle &rs = rstyle(node.style); // one pool lookup, not 11
|
|
38
|
-
return rs
|
|
38
|
+
return hasIndividualLinearTransform(rs) || hadIndividualLinearTransform(node.render) ||
|
|
39
|
+
rs.transform_rotate != 0 ||
|
|
39
40
|
node.render.previous_transform_rotate != 0 ||
|
|
40
41
|
rs.transform_rotate_x != 0 ||
|
|
41
42
|
node.render.previous_transform_rotate_x != 0 ||
|
|
42
43
|
rs.transform_rotate_y != 0 ||
|
|
43
44
|
node.render.previous_transform_rotate_y != 0 ||
|
|
44
|
-
rs
|
|
45
|
+
composedTranslateX(rs) != 0 ||
|
|
45
46
|
node.render.previous_transform_translate_x != 0 ||
|
|
46
|
-
rs
|
|
47
|
+
composedTranslateY(rs) != 0 ||
|
|
47
48
|
node.render.previous_transform_translate_y != 0 ||
|
|
48
|
-
rs
|
|
49
|
+
composedTranslateZ(rs) != 0 ||
|
|
49
50
|
node.render.previous_transform_translate_z != 0 ||
|
|
50
|
-
rs
|
|
51
|
+
composedTranslateXPercent(rs) != 0 ||
|
|
51
52
|
node.render.previous_transform_translate_x_percent != 0 ||
|
|
52
|
-
rs
|
|
53
|
+
composedTranslateYPercent(rs) != 0 ||
|
|
53
54
|
node.render.previous_transform_translate_y_percent != 0 ||
|
|
54
55
|
rs.transform_scale_x != 1000 ||
|
|
55
56
|
node.render.previous_transform_scale_x != 1000 ||
|
|
56
57
|
rs.transform_scale_y != 1000 ||
|
|
58
|
+
rs.transform_scale_z != 1000 ||
|
|
57
59
|
node.render.previous_transform_scale_y != 1000 ||
|
|
60
|
+
node.render.previous_transform_scale_z != 1000 ||
|
|
58
61
|
rs.perspective > 0 ||
|
|
59
62
|
node.render.previous_perspective > 0;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
int alignedAbsoluteOffset(const Node &parent, const Node &child, bool horizontal)
|
|
63
66
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
? (row ? parent.style.justify_content : crossAlign)
|
|
68
|
-
: (row ? crossAlign : parent.style.justify_content);
|
|
69
|
-
const int parentSize = horizontal ? parent.layout.width : parent.layout.height;
|
|
70
|
-
const int childSize = horizontal ? child.layout.width : child.layout.height;
|
|
71
|
-
const int beforeMargin = horizontal ? child.style.margin[3] : child.style.margin[0];
|
|
72
|
-
const int afterMargin = horizontal ? child.style.margin[1] : child.style.margin[2];
|
|
73
|
-
int available = parentSize;
|
|
74
|
-
if (available < 0) available = 0;
|
|
75
|
-
const int occupied = childSize + beforeMargin + afterMargin;
|
|
76
|
-
int free = available - occupied;
|
|
77
|
-
if (free < 0) free = 0;
|
|
78
|
-
|
|
79
|
-
int offset = beforeMargin;
|
|
80
|
-
if (align == 1) offset += free / 2;
|
|
81
|
-
else if (align == 2) offset += free;
|
|
82
|
-
return offset;
|
|
67
|
+
int x, y, width, height;
|
|
68
|
+
LayoutEngine::absoluteContainingArea(parent, child, x, y, width, height);
|
|
69
|
+
return LayoutEngine::alignedAbsoluteOffset(parent, child, horizontal, &parent, horizontal ? x : y, horizontal ? width : height);
|
|
83
70
|
}
|
|
84
71
|
|
|
85
|
-
int resolvedPositionOffset(const Node &
|
|
72
|
+
int resolvedPositionOffset(const Node &child, int side, int basis)
|
|
86
73
|
{
|
|
87
|
-
const int basis = (side == 0 || side == 2) ? parent.layout.height : parent.layout.width;
|
|
88
74
|
int offset = child.style.pos_offsets[side] != kUnset ? child.style.pos_offsets[side] : 0;
|
|
89
75
|
const int percent = child.style.pos_offset_percent[side];
|
|
90
76
|
if (percent != kUnset) {
|
|
@@ -113,6 +99,12 @@ bool retainableAbsoluteLayoutNode(const Node &node)
|
|
|
113
99
|
{
|
|
114
100
|
if ((!isViewLikeNodeType(node.type) && node.type != NodeType::Image) || node.style.position != 1) return false;
|
|
115
101
|
if (node.parent < 0) return false;
|
|
102
|
+
const Node &parent = Tree::instance().nodes()[node.parent];
|
|
103
|
+
// A static wrapper cannot supply the offsets for a more distant containing
|
|
104
|
+
// block. Let the full positioning pass resolve that ancestor instead.
|
|
105
|
+
if (parent.parent >= 0 && parent.style.position == 0) return false;
|
|
106
|
+
// Grid area geometry and its percentage bases belong to the grid pass.
|
|
107
|
+
if (isDisplayGrid(Tree::instance().nodes()[node.parent].style)) return false;
|
|
116
108
|
if (!hasExplicitWidth(node) || !hasExplicitHeight(node)) return false;
|
|
117
109
|
if (node.first_child >= 0) {
|
|
118
110
|
if (node.style.width != kUnset && node.style.width != node.layout.width) return false;
|
|
@@ -195,7 +187,14 @@ int AbsoluteLeafRefresh::mode()
|
|
|
195
187
|
Node *n = &state.nodes[i];
|
|
196
188
|
if (!n->render.dirty) continue;
|
|
197
189
|
if (n->render.transform_dirty) {
|
|
190
|
+
// A transform can create/remove a fixed descendant's containing block.
|
|
191
|
+
// Reprojecting retained commands alone leaves its percentage sizes and
|
|
192
|
+
// offsets tied to the previous block, so resolve layout first.
|
|
193
|
+
if (state.fixedPositionUsed) return reject(i, 8);
|
|
198
194
|
if (retainableAbsoluteLayoutNode(*n)) continue;
|
|
195
|
+
// A transform update cannot stand in for an accompanying geometry
|
|
196
|
+
// update. This node cannot use refreshPositions(), so lay it out.
|
|
197
|
+
if (n->render.layout_dirty) return reject(i, 9);
|
|
199
198
|
if (n->layout.x != n->layout.previous_x ||
|
|
200
199
|
n->layout.y != n->layout.previous_y ||
|
|
201
200
|
n->layout.width != n->layout.previous_width ||
|
|
@@ -253,23 +252,25 @@ void AbsoluteLeafRefresh::refreshPositions()
|
|
|
253
252
|
if (n->style.width != kUnset) n->layout.width = n->style.width;
|
|
254
253
|
if (n->style.height != kUnset) n->layout.height = n->style.height;
|
|
255
254
|
Node *p = &state.nodes[n->parent];
|
|
255
|
+
int areaX, areaY, areaWidth, areaHeight;
|
|
256
|
+
LayoutEngine::absoluteContainingArea(*p, *n, areaX, areaY, areaWidth, areaHeight);
|
|
256
257
|
const int before_x = n->layout.x;
|
|
257
258
|
const int before_y = n->layout.y;
|
|
258
259
|
int parent_x = p->layout.x;
|
|
259
260
|
if (p->style.overflow == 2 && scrollsOverflowX(p->style)) parent_x -= p->layout.scroll_x;
|
|
260
261
|
if (hasPositionOffset(*n, 3))
|
|
261
|
-
n->layout.x = parent_x + resolvedPositionOffset(*
|
|
262
|
+
n->layout.x = parent_x + areaX + resolvedPositionOffset(*n, 3, areaWidth);
|
|
262
263
|
else if (hasPositionOffset(*n, 1))
|
|
263
|
-
n->layout.x = parent_x +
|
|
264
|
+
n->layout.x = parent_x + areaX + areaWidth - n->layout.width - resolvedPositionOffset(*n, 1, areaWidth);
|
|
264
265
|
else
|
|
265
266
|
n->layout.x = parent_x + alignedAbsoluteOffset(*p, *n, true);
|
|
266
267
|
|
|
267
268
|
int parent_y = p->layout.y;
|
|
268
269
|
if (p->style.overflow == 2 && scrollsOverflowY(p->style)) parent_y -= p->layout.scroll_y;
|
|
269
270
|
if (hasPositionOffset(*n, 0))
|
|
270
|
-
n->layout.y = parent_y + resolvedPositionOffset(*
|
|
271
|
+
n->layout.y = parent_y + areaY + resolvedPositionOffset(*n, 0, areaHeight);
|
|
271
272
|
else if (hasPositionOffset(*n, 2))
|
|
272
|
-
n->layout.y = parent_y +
|
|
273
|
+
n->layout.y = parent_y + areaY + areaHeight - n->layout.height - resolvedPositionOffset(*n, 2, areaHeight);
|
|
273
274
|
else
|
|
274
275
|
n->layout.y = parent_y + alignedAbsoluteOffset(*p, *n, false);
|
|
275
276
|
translateDescendantLayouts(state, i, n->layout.x - before_x, n->layout.y - before_y);
|
package/ui/core.cpp
CHANGED
|
@@ -37,7 +37,15 @@ void Tree::markNodeDisplayCommandsDirty(int node)
|
|
|
37
37
|
{
|
|
38
38
|
if (node < 0 || node >= kMaxNodes) return;
|
|
39
39
|
refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++;
|
|
40
|
-
treeState()
|
|
40
|
+
auto &state = treeState();
|
|
41
|
+
state.nodeCommandDirty[node] = 1;
|
|
42
|
+
const int root = state.mountedRoot;
|
|
43
|
+
if (root >= 0 && root < state.nodeCount && node < state.nodeCount && isDocumentCanvasRoot(state.nodes[root]) &&
|
|
44
|
+
(node == root || (state.nodes[node].parent == root && std::string_view(tagFromId(state.nodes[node].tag_id)) == "body"))) {
|
|
45
|
+
// The affected canvas pixels extend beyond the root/body layout boxes.
|
|
46
|
+
// A body mutation can also move background ownership to or from html.
|
|
47
|
+
markDisplayListDirty();
|
|
48
|
+
}
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
void Tree::markScrollDirty(int node)
|
|
@@ -41,8 +41,23 @@ bool DisplayInvalidation::rebuildsNodeDisplayCommands(Property prop)
|
|
|
41
41
|
case Property::Display:
|
|
42
42
|
case Property::Opacity:
|
|
43
43
|
case Property::BackgroundColor:
|
|
44
|
+
case Property::BackgroundAlpha:
|
|
45
|
+
case Property::BackgroundClip:
|
|
46
|
+
case Property::BackgroundImage:
|
|
47
|
+
case Property::Containment:
|
|
44
48
|
case Property::ActiveBackgroundColor:
|
|
45
49
|
case Property::Color:
|
|
50
|
+
case Property::ColorAlpha:
|
|
51
|
+
case Property::BorderAlpha:
|
|
52
|
+
case Property::BorderTopAlpha:
|
|
53
|
+
case Property::BorderRightAlpha:
|
|
54
|
+
case Property::BorderBottomAlpha:
|
|
55
|
+
case Property::BorderLeftAlpha:
|
|
56
|
+
case Property::BorderColorCurrent:
|
|
57
|
+
case Property::BorderTopColorCurrent:
|
|
58
|
+
case Property::BorderRightColorCurrent:
|
|
59
|
+
case Property::BorderBottomColorCurrent:
|
|
60
|
+
case Property::BorderLeftColorCurrent:
|
|
46
61
|
case Property::BorderColor:
|
|
47
62
|
case Property::BorderTopWidth:
|
|
48
63
|
case Property::BorderRightWidth:
|
|
@@ -63,6 +78,19 @@ bool DisplayInvalidation::rebuildsNodeDisplayCommands(Property prop)
|
|
|
63
78
|
case Property::TransformRotate:
|
|
64
79
|
case Property::TransformRotateX:
|
|
65
80
|
case Property::TransformRotateY:
|
|
81
|
+
case Property::TranslateX:
|
|
82
|
+
case Property::RotateAngle:
|
|
83
|
+
case Property::RotateAxisX:
|
|
84
|
+
case Property::RotateAxisY:
|
|
85
|
+
case Property::RotateAxisZ:
|
|
86
|
+
case Property::ScaleX:
|
|
87
|
+
case Property::ScaleY:
|
|
88
|
+
case Property::ScaleZ:
|
|
89
|
+
case Property::TransformTranslateOuterAxes:
|
|
90
|
+
case Property::TranslateY:
|
|
91
|
+
case Property::TranslateZ:
|
|
92
|
+
case Property::TranslateXPercent:
|
|
93
|
+
case Property::TranslateYPercent:
|
|
66
94
|
case Property::TransformTranslateX:
|
|
67
95
|
case Property::TransformTranslateY:
|
|
68
96
|
case Property::TransformTranslateZ:
|
|
@@ -70,6 +98,7 @@ bool DisplayInvalidation::rebuildsNodeDisplayCommands(Property prop)
|
|
|
70
98
|
case Property::TransformTranslateYPercent:
|
|
71
99
|
case Property::TransformScaleX:
|
|
72
100
|
case Property::TransformScaleY:
|
|
101
|
+
case Property::TransformScaleZ:
|
|
73
102
|
case Property::TransformOriginX:
|
|
74
103
|
case Property::TransformOriginY:
|
|
75
104
|
case Property::Perspective:
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
namespace gea::embedded::ui {
|
|
9
|
+
|
|
10
|
+
// CSS Flexbox 2, 9.7: contiguous, nonempty lines minimizing squared unused
|
|
11
|
+
// space. Sizes include margins and are floored at zero only for balancing.
|
|
12
|
+
// Returns exclusive line ends. An oversized item occupies a line by itself.
|
|
13
|
+
inline std::vector<int> balancedFlexLineEnds(const std::vector<int> &sizes, int available, int gap, int minimumLines)
|
|
14
|
+
{
|
|
15
|
+
const int n = static_cast<int>(sizes.size());
|
|
16
|
+
if (!n) return {};
|
|
17
|
+
std::vector<std::int64_t> prefix(n + 1);
|
|
18
|
+
for (int i = 0; i < n; ++i) prefix[i + 1] = prefix[i] + std::max(0, sizes[i]) + gap;
|
|
19
|
+
std::vector<int> furthest(n), required(n + 1);
|
|
20
|
+
for (int i = n - 1; i >= 0; --i) {
|
|
21
|
+
const auto bound = std::upper_bound(prefix.begin() + i + 1, prefix.end(), prefix[i] + available + gap);
|
|
22
|
+
furthest[i] = std::max(i + 1, static_cast<int>(bound - prefix.begin()) - 1);
|
|
23
|
+
required[i] = 1 + required[furthest[i]];
|
|
24
|
+
}
|
|
25
|
+
const int count = std::max(required[0], std::min(n, minimumLines));
|
|
26
|
+
if (count == 1) return {n};
|
|
27
|
+
std::vector<int> ends(count);
|
|
28
|
+
if (count == n) {
|
|
29
|
+
for (int i = 0; i < n; ++i) ends[i] = i + 1;
|
|
30
|
+
return ends;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
constexpr std::int64_t infinity = INT64_MAX / 4;
|
|
34
|
+
std::vector<std::int64_t> previous(n + 1, infinity), current(n + 1, infinity);
|
|
35
|
+
std::vector<int> choices((count + 1) * (n + 1), -1);
|
|
36
|
+
previous[n] = 0;
|
|
37
|
+
int previousFirst = n;
|
|
38
|
+
for (int lines = 1; lines <= count; ++lines) {
|
|
39
|
+
int first = 0;
|
|
40
|
+
while (required[first] > lines) ++first;
|
|
41
|
+
std::fill(current.begin(), current.end(), infinity);
|
|
42
|
+
// Squared interval sums form a Monge cost matrix: optimal next breaks
|
|
43
|
+
// are monotone. Divide-and-conquer computes a row in O(n log n), avoiding
|
|
44
|
+
// a quadratic search per line. Suffix costs let ties favor the largest
|
|
45
|
+
// FIRST break, then recursively apply the same preference to later lines.
|
|
46
|
+
auto solve = [&](auto &&self, int lo, int hi, int optLo, int optHi) -> void {
|
|
47
|
+
if (lo > hi) return;
|
|
48
|
+
const int start = (lo + hi) / 2;
|
|
49
|
+
const int begin = std::max({start + 1, previousFirst, optLo});
|
|
50
|
+
const int end = std::min({furthest[start], n - lines + 1, optHi});
|
|
51
|
+
int best = begin;
|
|
52
|
+
for (int next = begin; next <= end; ++next) {
|
|
53
|
+
const std::int64_t error = available - (prefix[next] - prefix[start] - gap);
|
|
54
|
+
const std::int64_t cost = previous[next] + error * error;
|
|
55
|
+
if (cost <= current[start]) { current[start] = cost; best = next; }
|
|
56
|
+
}
|
|
57
|
+
choices[lines * (n + 1) + start] = best;
|
|
58
|
+
self(self, lo, start - 1, optLo, best);
|
|
59
|
+
self(self, start + 1, hi, best, optHi);
|
|
60
|
+
};
|
|
61
|
+
solve(solve, first, n - lines, first + 1, n - lines + 1);
|
|
62
|
+
previous.swap(current);
|
|
63
|
+
previousFirst = first;
|
|
64
|
+
}
|
|
65
|
+
int start = 0;
|
|
66
|
+
for (int line = 0; line < count; ++line) {
|
|
67
|
+
start = choices[(count - line) * (n + 1) + start];
|
|
68
|
+
ends[line] = start;
|
|
69
|
+
}
|
|
70
|
+
return ends;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
} // namespace gea::embedded::ui
|
package/ui/image_node.cpp
CHANGED
|
@@ -19,21 +19,23 @@ class ImageFitResolver {
|
|
|
19
19
|
public:
|
|
20
20
|
static ImageFitRect resolve(const Node &node, int imageWidth, int imageHeight)
|
|
21
21
|
{
|
|
22
|
+
const int contentWidth = node.layout.width - boxInsets(node.style, true);
|
|
23
|
+
const int contentHeight = node.layout.height - boxInsets(node.style, false);
|
|
22
24
|
ImageFitRect rect{
|
|
23
|
-
node.layout.x,
|
|
24
|
-
node.layout.y,
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
node.layout.x + boxInset(node.style, 3),
|
|
26
|
+
node.layout.y + boxInset(node.style, 0),
|
|
27
|
+
contentWidth,
|
|
28
|
+
contentHeight,
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
if (node.style.image_fit == 1 || node.style.image_fit == 4) {
|
|
30
|
-
const int scaledWidth = (imageWidth *
|
|
31
|
-
const int scaledHeight = (imageHeight *
|
|
32
|
-
if (scaledWidth <=
|
|
32
|
+
const int scaledWidth = (imageWidth * contentHeight) / imageHeight;
|
|
33
|
+
const int scaledHeight = (imageHeight * contentWidth) / imageWidth;
|
|
34
|
+
if (scaledWidth <= contentWidth) {
|
|
33
35
|
rect.width = scaledWidth;
|
|
34
|
-
rect.height =
|
|
36
|
+
rect.height = contentHeight;
|
|
35
37
|
} else {
|
|
36
|
-
rect.width =
|
|
38
|
+
rect.width = contentWidth;
|
|
37
39
|
rect.height = scaledHeight;
|
|
38
40
|
}
|
|
39
41
|
if (node.style.image_fit == 4 && rect.width >= imageWidth && rect.height >= imageHeight) {
|
|
@@ -42,13 +44,13 @@ public:
|
|
|
42
44
|
}
|
|
43
45
|
center(node, rect);
|
|
44
46
|
} else if (node.style.image_fit == 2) {
|
|
45
|
-
const int scaledWidth = (imageWidth *
|
|
46
|
-
const int scaledHeight = (imageHeight *
|
|
47
|
-
if (scaledWidth >=
|
|
47
|
+
const int scaledWidth = (imageWidth * contentHeight) / imageHeight;
|
|
48
|
+
const int scaledHeight = (imageHeight * contentWidth) / imageWidth;
|
|
49
|
+
if (scaledWidth >= contentWidth) {
|
|
48
50
|
rect.width = scaledWidth;
|
|
49
|
-
rect.height =
|
|
51
|
+
rect.height = contentHeight;
|
|
50
52
|
} else {
|
|
51
|
-
rect.width =
|
|
53
|
+
rect.width = contentWidth;
|
|
52
54
|
rect.height = scaledHeight;
|
|
53
55
|
}
|
|
54
56
|
center(node, rect);
|
|
@@ -64,8 +66,8 @@ public:
|
|
|
64
66
|
private:
|
|
65
67
|
static void center(const Node &node, ImageFitRect &rect)
|
|
66
68
|
{
|
|
67
|
-
rect.x = node.layout.x + (node.layout.width - rect.width) / 2;
|
|
68
|
-
rect.y = node.layout.y + (node.layout.height - rect.height) / 2;
|
|
69
|
+
rect.x = node.layout.x + boxInset(node.style, 3) + (node.layout.width - boxInsets(node.style, true) - rect.width) / 2;
|
|
70
|
+
rect.y = node.layout.y + boxInset(node.style, 0) + (node.layout.height - boxInsets(node.style, false) - rect.height) / 2;
|
|
69
71
|
}
|
|
70
72
|
};
|
|
71
73
|
|
|
@@ -109,10 +111,12 @@ void ImageRenderer::layout(int id)
|
|
|
109
111
|
int iw = images.width(n->image_id);
|
|
110
112
|
int ih = images.height(n->image_id);
|
|
111
113
|
|
|
112
|
-
if (n->style.width == kUnset && n->style.width_percent == kUnset && iw > 0)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
if (n->style.width == kUnset && n->style.width_percent == kUnset && n->style.width_expression < 0 && iw > 0)
|
|
115
|
+
n->layout.width = iw + boxInsets(n->style, true);
|
|
116
|
+
if (n->style.height == kUnset && n->style.height_percent == kUnset && n->style.height_expression < 0 && ih > 0)
|
|
117
|
+
n->layout.height = ih + boxInsets(n->style, false);
|
|
118
|
+
n->layout.width = clampBorderBoxSize(n->style, n->layout.width, true);
|
|
119
|
+
n->layout.height = clampBorderBoxSize(n->style, n->layout.height, false);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
void ImageRenderer::record(const Node &node)
|