@geastack/engine 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas.cpp +126 -27
- package/package.json +1 -1
- package/touch_runtime.cpp +10 -8
- package/ui/CSS_FEATURES.md +51 -0
- package/ui/input.cpp +61 -18
- package/ui/internal.h +6 -1
- package/ui/layout.cpp +51 -2
- package/ui/node_features.h +6 -0
- package/ui/node_model.h +17 -1
- package/ui/render.cpp +107 -1
- package/ui/root_scroll_refresh.cpp +10 -1
- package/ui/style.cpp +52 -0
- package/ui/style.h +18 -1
- package/ui/svg_element.h +95 -0
- package/ui/svg_element_impl.h +1150 -0
- package/ui/svg_geometry.h +1702 -0
- package/ui/text.cpp +6 -0
- package/ui/tree_events.cpp +24 -1
- package/ui/tree_nodes.cpp +36 -2
- package/ui/tree_render.cpp +28 -0
- package/ui/tree_style.cpp +24 -0
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
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#include "internal.h"
|
|
7
7
|
#include "tree_internal.h"
|
|
8
8
|
#include "tree_state.h"
|
|
9
|
+
#include "svg_element.h"
|
|
9
10
|
#include <stdexcept>
|
|
10
11
|
|
|
11
12
|
#include <algorithm>
|
|
@@ -366,7 +367,15 @@ bool dispatchRootKeyEvent(gea::framework::events::PointerEvent &event, bool lega
|
|
|
366
367
|
using gea::framework::events::PointerEventType;
|
|
367
368
|
if (event.type != PointerEventType::KeyDown && event.type != PointerEventType::KeyUp) return false;
|
|
368
369
|
auto &tree = Tree::instance();
|
|
369
|
-
|
|
370
|
+
// With no focused input a hardware key belongs to the app: target its top
|
|
371
|
+
// element (the mount container's first child), so the event bubbles through
|
|
372
|
+
// the app root -- where apps bind onKeyDown -- and then the container. Aiming
|
|
373
|
+
// at the container itself skipped every app-level key handler.
|
|
374
|
+
if (event.targetId < 0) {
|
|
375
|
+
const int root = tree.mountedRoot();
|
|
376
|
+
const int app = tree.firstChildOf(root);
|
|
377
|
+
event.targetId = app >= 0 ? app : root;
|
|
378
|
+
}
|
|
370
379
|
event.target = gea::framework::events::EventTarget(event.targetId);
|
|
371
380
|
const auto path = captureEventPath(tree, event.targetId);
|
|
372
381
|
bool dispatched = dispatchWindowEvent(event, true);
|
|
@@ -905,6 +914,11 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
905
914
|
return;
|
|
906
915
|
}
|
|
907
916
|
ensureRareData(node).attributes.set(name, value);
|
|
917
|
+
#if GEA_UI_SVG
|
|
918
|
+
// SVG geometry/paint attributes keep their full value (path data easily
|
|
919
|
+
// exceeds the generic store's bound) and repaint the owning <svg>.
|
|
920
|
+
if (svg::noteAttribute(node, name, value ? value : "")) return;
|
|
921
|
+
#endif
|
|
908
922
|
if (state.nodes[node].type == NodeType::Image && sameName(name, "src")) {
|
|
909
923
|
const auto &style = state.nodes[node].computedStyle();
|
|
910
924
|
const bool fixedBox = (style.width != kUnset || style.width_percent != kUnset) &&
|
|
@@ -977,6 +991,9 @@ void Tree::removeAttribute(int node, const char *name)
|
|
|
977
991
|
setClassName(node, "");
|
|
978
992
|
return;
|
|
979
993
|
}
|
|
994
|
+
#if GEA_UI_SVG
|
|
995
|
+
svg::noteAttribute(node, name, nullptr);
|
|
996
|
+
#endif
|
|
980
997
|
NodeRareData *rd = rareDataFor(node);
|
|
981
998
|
if (!rd) return; // no rare-data block → no attributes to remove
|
|
982
999
|
const bool hadAttribute = rd->attributes.remove(name);
|
|
@@ -1025,6 +1042,9 @@ const char *Tree::getAttribute(int node, const char *name) const
|
|
|
1025
1042
|
classBuf = className(node);
|
|
1026
1043
|
return classBuf.c_str();
|
|
1027
1044
|
}
|
|
1045
|
+
#if GEA_UI_SVG
|
|
1046
|
+
if (const char *full = svg::attribute(node, name)) return full;
|
|
1047
|
+
#endif
|
|
1028
1048
|
const NodeRareData *rd = rareDataFor(node);
|
|
1029
1049
|
return rd ? rd->attributes.get(name) : "";
|
|
1030
1050
|
}
|
|
@@ -1034,6 +1054,9 @@ bool Tree::hasAttribute(int node, const char *name) const
|
|
|
1034
1054
|
const auto &state = treeState();
|
|
1035
1055
|
if (node < 0 || node >= state.nodeCount) return false;
|
|
1036
1056
|
if (sameName(name, "class")) return !className(node).empty();
|
|
1057
|
+
#if GEA_UI_SVG
|
|
1058
|
+
if (svg::attribute(node, name)) return true;
|
|
1059
|
+
#endif
|
|
1037
1060
|
const NodeRareData *rd = rareDataFor(node);
|
|
1038
1061
|
return rd && rd->attributes.has(name);
|
|
1039
1062
|
}
|
package/ui/tree_nodes.cpp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "internal.h"
|
|
3
|
+
#include "svg_element.h"
|
|
3
4
|
#include "node.h"
|
|
4
5
|
#include "input_retirement.h"
|
|
5
6
|
#include <stdexcept>
|
|
@@ -127,6 +128,9 @@ void resetNodeSlot(TreeState &state, int id)
|
|
|
127
128
|
#endif
|
|
128
129
|
state.classLists[id].clear();
|
|
129
130
|
state.canvases.remove(id);
|
|
131
|
+
#if GEA_UI_SVG
|
|
132
|
+
svg::releaseNode(id);
|
|
133
|
+
#endif
|
|
130
134
|
state.nodeCommandDirty[id] = 0;
|
|
131
135
|
state.nodeCommandDirtyBoundsValid[id] = 0;
|
|
132
136
|
state.nodeCommandDirtyCanOverpaint[id] = 0;
|
|
@@ -148,6 +152,10 @@ void trimInactiveTail(TreeState &state)
|
|
|
148
152
|
bool localAbsoluteLeafTreeMutation(const TreeState &state, int child)
|
|
149
153
|
{
|
|
150
154
|
if (child < 0 || child >= state.nodeCount) return false;
|
|
155
|
+
#if GEA_UI_SVG
|
|
156
|
+
// SVG shapes paint through their svg's scene; validateScenes repaints it.
|
|
157
|
+
if (svg::isShape(child)) return true;
|
|
158
|
+
#endif
|
|
151
159
|
const Node &node = state.nodes[child];
|
|
152
160
|
if (node.computedStyle().display == kDisplayNone) return false;
|
|
153
161
|
if (node.computedStyle().position != 1) return false;
|
|
@@ -177,6 +185,9 @@ void Tree::clear()
|
|
|
177
185
|
}
|
|
178
186
|
resetRareStylePool(); // drop all cold-style entries; node handles reset by the Node{} loop below
|
|
179
187
|
state.canvases.clear();
|
|
188
|
+
#if GEA_UI_SVG
|
|
189
|
+
svg::clearAll();
|
|
190
|
+
#endif
|
|
180
191
|
std::memset(state.nodeActive, 0, sizeof(state.nodeActive));
|
|
181
192
|
// Reset EVERY slot of state.nodes[], not just [0, nodeCount). If the
|
|
182
193
|
// next app's tree has fewer nodes than the previous app's tree, the
|
|
@@ -247,13 +258,29 @@ int Tree::createNode(NodeType type)
|
|
|
247
258
|
break;
|
|
248
259
|
}
|
|
249
260
|
if (id < 0) {
|
|
250
|
-
if (state.nodeCount >= kMaxNodes)
|
|
261
|
+
if (state.nodeCount >= kMaxNodes) {
|
|
262
|
+
// Callers drop the -1, so the element and everything that would
|
|
263
|
+
// hang under it are never attached, laid out or drawn: without
|
|
264
|
+
// this line a view just disappears. Reported once per process.
|
|
265
|
+
static bool reported = false;
|
|
266
|
+
if (!reported) {
|
|
267
|
+
reported = true;
|
|
268
|
+
std::printf("[tree] node pool full (%d nodes, GEA_EMBEDDED_MAX_NODES): new elements are not created "
|
|
269
|
+
"and the views they belong to are not drawn; raise GEA_EMBEDDED_MAX_NODES for this target\n",
|
|
270
|
+
kMaxNodes);
|
|
271
|
+
std::fflush(stdout);
|
|
272
|
+
}
|
|
273
|
+
return -1;
|
|
274
|
+
}
|
|
251
275
|
id = state.nodeCount++;
|
|
252
276
|
}
|
|
253
277
|
gea::framework::identity::activate(id);
|
|
254
278
|
const auto allocatedOwner = gea::framework::identity::node(id);
|
|
255
279
|
state.nodeActive[id] = 1;
|
|
256
280
|
releaseRareData(id); // free any block from a prior occupant before reinit
|
|
281
|
+
#if GEA_UI_SVG
|
|
282
|
+
svg::releaseNode(id);
|
|
283
|
+
#endif
|
|
257
284
|
if (!gea::framework::identity::current(id, allocatedOwner)) return -1;
|
|
258
285
|
NodeLifecycle::init(&state.nodes[id], type);
|
|
259
286
|
LayoutEngine::instance().resetNodeLayoutState(id);
|
|
@@ -854,7 +881,14 @@ void Tree::removeNode(int id)
|
|
|
854
881
|
!gea::framework::identity::current(id, removingOwner)) return;
|
|
855
882
|
}
|
|
856
883
|
Node *n = &state.nodes[id];
|
|
857
|
-
|
|
884
|
+
#if GEA_UI_SVG
|
|
885
|
+
// A shape draws nothing of its own: its svg repaints (validateScenes sees
|
|
886
|
+
// the subtree change), so the viewport needs no structural repaint.
|
|
887
|
+
if (svg::isShape(id))
|
|
888
|
+
markDisplayListContentDirty();
|
|
889
|
+
else
|
|
890
|
+
#endif
|
|
891
|
+
markDisplayListDirty();
|
|
858
892
|
n->render.dirty = 1;
|
|
859
893
|
n->render.layout_dirty = 1;
|
|
860
894
|
#if GEA_CSS_SCROLLING
|
package/ui/tree_render.cpp
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
#include "refresh_perf.h"
|
|
12
12
|
#include "root_scroll_refresh.h"
|
|
13
13
|
#include "tree_state.h"
|
|
14
|
+
#include "svg_element.h"
|
|
14
15
|
|
|
15
16
|
#include <cmath>
|
|
16
17
|
#include <cstddef>
|
|
@@ -2078,6 +2079,9 @@ namespace gea::embedded::ui
|
|
|
2078
2079
|
auto &state = treeState();
|
|
2079
2080
|
if (root < 0 || root >= state.nodeCount)
|
|
2080
2081
|
return;
|
|
2082
|
+
#if GEA_UI_SVG
|
|
2083
|
+
svg::validateScenes();
|
|
2084
|
+
#endif
|
|
2081
2085
|
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
2082
2086
|
debuggerOverlay.prepare();
|
|
2083
2087
|
#endif
|
|
@@ -2749,6 +2753,27 @@ namespace gea::embedded::ui
|
|
|
2749
2753
|
canvas_y1 = retained_y1;
|
|
2750
2754
|
}
|
|
2751
2755
|
}
|
|
2756
|
+
#if GEA_UI_SVG
|
|
2757
|
+
// An svg whose box is unchanged repaints only the pixels its scene
|
|
2758
|
+
// rebuild touched, through the same exact-damage path as a canvas.
|
|
2759
|
+
if (!canvas_dirty && svg::isRoot(*n))
|
|
2760
|
+
{
|
|
2761
|
+
int sx0, sy0, sx1, sy1;
|
|
2762
|
+
const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1); // always consume
|
|
2763
|
+
if (svgDamage && !n->render.layout_dirty && !n->render.transform_dirty &&
|
|
2764
|
+
n->layout.x == n->layout.previous_x && n->layout.y == n->layout.previous_y &&
|
|
2765
|
+
n->layout.width == n->layout.previous_width && n->layout.height == n->layout.previous_height &&
|
|
2766
|
+
!ViewRenderer::anyTransformActive())
|
|
2767
|
+
{
|
|
2768
|
+
canvas_dirty = true;
|
|
2769
|
+
exactCanvasPixelDamage = true;
|
|
2770
|
+
canvas_x0 = sx0;
|
|
2771
|
+
canvas_y0 = sy0;
|
|
2772
|
+
canvas_x1 = sx1;
|
|
2773
|
+
canvas_y1 = sy1;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
#endif
|
|
2752
2777
|
if (canvas_dirty && !exactCanvasPixelDamage)
|
|
2753
2778
|
{
|
|
2754
2779
|
// A style/geometry invalidation is not a content-only repaint. Both
|
|
@@ -3640,3 +3665,6 @@ namespace gea::embedded::ui
|
|
|
3640
3665
|
}
|
|
3641
3666
|
|
|
3642
3667
|
} // namespace gea::embedded::ui
|
|
3668
|
+
|
|
3669
|
+
// Inline SVG lives in this translation unit (see svg_element_impl.h).
|
|
3670
|
+
#include "svg_element_impl.h"
|
package/ui/tree_style.cpp
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include "node_lifecycle.h"
|
|
6
6
|
#include "refresh_perf.h"
|
|
7
7
|
#include "style_values.h"
|
|
8
|
+
#include "svg_element.h"
|
|
8
9
|
#include "tree_state.h"
|
|
9
10
|
|
|
10
11
|
// Skip the inline-style record for Left/Top (see setStyleValue). Default off: keep the
|
|
@@ -1150,6 +1151,21 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
|
|
|
1150
1151
|
if (rstyle(style).box_shadow_alpha != next) { rstyleMut(style).box_shadow_alpha = next; changed = 1; }
|
|
1151
1152
|
break;
|
|
1152
1153
|
}
|
|
1154
|
+
#endif
|
|
1155
|
+
#if GEA_UI_SVG
|
|
1156
|
+
#define GEA_SVG_STYLE_FIELD(PROP, FIELD, TYPE) \
|
|
1157
|
+
case Property::PROP: \
|
|
1158
|
+
if (rstyle(style).FIELD != static_cast<TYPE>(value)) { rstyleMut(style).FIELD = static_cast<TYPE>(value); changed = 1; } \
|
|
1159
|
+
break;
|
|
1160
|
+
GEA_SVG_STYLE_FIELD(SvgFill, svg_fill, int32_t)
|
|
1161
|
+
GEA_SVG_STYLE_FIELD(SvgStroke, svg_stroke, int32_t)
|
|
1162
|
+
GEA_SVG_STYLE_FIELD(SvgStrokeWidth, svg_stroke_width, int32_t)
|
|
1163
|
+
GEA_SVG_STYLE_FIELD(SvgFillOpacity, svg_fill_opacity, int16_t)
|
|
1164
|
+
GEA_SVG_STYLE_FIELD(SvgStrokeOpacity, svg_stroke_opacity, int16_t)
|
|
1165
|
+
GEA_SVG_STYLE_FIELD(SvgStrokeLinecap, svg_stroke_linecap, int8_t)
|
|
1166
|
+
GEA_SVG_STYLE_FIELD(SvgStrokeLinejoin, svg_stroke_linejoin, int8_t)
|
|
1167
|
+
GEA_SVG_STYLE_FIELD(SvgFillRule, svg_fill_rule, int8_t)
|
|
1168
|
+
#undef GEA_SVG_STYLE_FIELD
|
|
1153
1169
|
#endif
|
|
1154
1170
|
default:
|
|
1155
1171
|
GEA_REFRESH_PERF(perf.treeSetStyleNoop++);
|
|
@@ -1168,6 +1184,14 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
|
|
|
1168
1184
|
GEA_REFRESH_PERF(perf.treeSetStylePaintChanged++);
|
|
1169
1185
|
if (state.styleInvalidationSuppressionDepth > 0) return;
|
|
1170
1186
|
if (!nodeParticipatesInMountedTree(state, node)) return;
|
|
1187
|
+
#if GEA_UI_SVG
|
|
1188
|
+
// SVG paint lives in the owning <svg>'s scene, not in this node's commands:
|
|
1189
|
+
// repaint that one svg and nothing else (no layout, no list rebuild).
|
|
1190
|
+
if (svg::isPaintProperty(prop)) {
|
|
1191
|
+
svg::noteNodeChanged(node);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
#endif
|
|
1171
1195
|
n->render.canvas_pixels_only_dirty = 0;
|
|
1172
1196
|
const bool hadRecolor = n->render.bg_recolor_pending;
|
|
1173
1197
|
const bool canRecolor = !n->render.dirty || hadRecolor;
|