@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/render.cpp
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "state_init.h"
|
|
11
11
|
#include "style_values.h"
|
|
12
12
|
#include "tree_state.h"
|
|
13
|
+
#include "svg_element.h"
|
|
13
14
|
#include <pixel.h>
|
|
14
15
|
|
|
15
16
|
#include <algorithm>
|
|
@@ -335,6 +336,8 @@ int gLastScrollUiFrame = -1000;
|
|
|
335
336
|
return "BlitImageProjected";
|
|
336
337
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
337
338
|
return "ReplayCanvasBatch";
|
|
339
|
+
case DisplayCommandType::DrawSvg:
|
|
340
|
+
return "DrawSvg";
|
|
338
341
|
case DisplayCommandType::BeginFilterBlur:
|
|
339
342
|
return "BeginFilterBlur";
|
|
340
343
|
case DisplayCommandType::ApplyFilterBlur:
|
|
@@ -4880,6 +4883,60 @@ int gLastScrollUiFrame = -1000;
|
|
|
4880
4883
|
return coverage;
|
|
4881
4884
|
}
|
|
4882
4885
|
|
|
4886
|
+
// Where a rounded-rect contour's left and right edges run across the pixel
|
|
4887
|
+
// row [y, y + 1): each edge is monotone within a corner, so its extremes
|
|
4888
|
+
// over the row sit at the row's ends or where a corner meets a straight
|
|
4889
|
+
// side. Mirrors roundedRectContainsFast's corner order (tl before bl, tr
|
|
4890
|
+
// before br).
|
|
4891
|
+
struct RoundedRowEdges
|
|
4892
|
+
{
|
|
4893
|
+
bool any = false; // the contour reaches into the row
|
|
4894
|
+
bool whole = false; // the row lies wholly within its vertical extent
|
|
4895
|
+
float lMin = 0, lMax = 0, rMin = 0, rMax = 0;
|
|
4896
|
+
};
|
|
4897
|
+
|
|
4898
|
+
RoundedRowEdges roundedRectRowEdges(const TransformedRoundedRectCommand &r, int y)
|
|
4899
|
+
{
|
|
4900
|
+
RoundedRowEdges e;
|
|
4901
|
+
if (r.lw <= 0 || r.lh <= 0)
|
|
4902
|
+
return e;
|
|
4903
|
+
const float left = static_cast<float>(r.lx), top = static_cast<float>(r.ly);
|
|
4904
|
+
const float right = left + static_cast<float>(r.lw), bottom = top + static_cast<float>(r.lh);
|
|
4905
|
+
const float y0 = std::max(static_cast<float>(y), top), y1 = std::min(static_cast<float>(y + 1), bottom);
|
|
4906
|
+
if (y1 <= y0)
|
|
4907
|
+
return e;
|
|
4908
|
+
e.any = true;
|
|
4909
|
+
e.whole = static_cast<float>(y) >= top && static_cast<float>(y + 1) <= bottom;
|
|
4910
|
+
const auto radius = [](int16_t r8) { return static_cast<float>(std::max(0, static_cast<int>(r8))) * 0.125f; };
|
|
4911
|
+
const float tlRx = radius(r.tlRx8), tlRy = radius(r.tlRy8), trRx = radius(r.trRx8), trRy = radius(r.trRy8);
|
|
4912
|
+
const float brRx = radius(r.brRx8), brRy = radius(r.brRy8), blRx = radius(r.blRx8), blRy = radius(r.blRy8);
|
|
4913
|
+
const auto inset = [](float rx, float ry, float dy) {
|
|
4914
|
+
const float t = dy / ry;
|
|
4915
|
+
return rx - rx * std::sqrt(std::max(0.0f, 1.0f - t * t));
|
|
4916
|
+
};
|
|
4917
|
+
const auto leftAt = [&](float sy) {
|
|
4918
|
+
if (tlRx > 0 && tlRy > 0 && sy < top + tlRy) return left + inset(tlRx, tlRy, top + tlRy - sy);
|
|
4919
|
+
if (blRx > 0 && blRy > 0 && sy >= bottom - blRy) return left + inset(blRx, blRy, sy - (bottom - blRy));
|
|
4920
|
+
return left;
|
|
4921
|
+
};
|
|
4922
|
+
const auto rightAt = [&](float sy) {
|
|
4923
|
+
if (trRx > 0 && trRy > 0 && sy < top + trRy) return right - inset(trRx, trRy, top + trRy - sy);
|
|
4924
|
+
if (brRx > 0 && brRy > 0 && sy >= bottom - brRy) return right - inset(brRx, brRy, sy - (bottom - brRy));
|
|
4925
|
+
return right;
|
|
4926
|
+
};
|
|
4927
|
+
const float probes[6] = {y0, y1, top + tlRy, bottom - blRy, top + trRy, bottom - brRy};
|
|
4928
|
+
e.lMin = e.rMin = 1e9f;
|
|
4929
|
+
e.lMax = e.rMax = -1e9f;
|
|
4930
|
+
for (int i = 0; i < 6; ++i)
|
|
4931
|
+
{
|
|
4932
|
+
const float sy = std::clamp(probes[i], y0, y1);
|
|
4933
|
+
const float l = leftAt(sy), rr = rightAt(sy);
|
|
4934
|
+
e.lMin = std::min(e.lMin, l); e.lMax = std::max(e.lMax, l);
|
|
4935
|
+
e.rMin = std::min(e.rMin, rr); e.rMax = std::max(e.rMax, rr);
|
|
4936
|
+
}
|
|
4937
|
+
return e;
|
|
4938
|
+
}
|
|
4939
|
+
|
|
4883
4940
|
void drawCssRoundedBorder(const DisplayCommand &command)
|
|
4884
4941
|
{
|
|
4885
4942
|
const auto &s = command.strokeRoundedRect;
|
|
@@ -4923,7 +4980,31 @@ int gLastScrollUiFrame = -1000;
|
|
|
4923
4980
|
for (int x = std::max(x0, innerX1); x <= x1; ++x) paintCoveragePixel(row[x], s.color, alpha, full, full);
|
|
4924
4981
|
continue;
|
|
4925
4982
|
}
|
|
4926
|
-
|
|
4983
|
+
// Only pixels within a pixel of a contour edge need the per-pixel
|
|
4984
|
+
// test; the rest of the row is plainly outside the ring, inside the
|
|
4985
|
+
// border, or inside the hole. A large ellipse is all corner box, so
|
|
4986
|
+
// testing every pixel of it costs a frame per pass.
|
|
4987
|
+
const RoundedRowEdges oe = roundedRectRowEdges(outer, y), ie = roundedRectRowEdges(inner, y);
|
|
4988
|
+
if (!oe.any)
|
|
4989
|
+
continue;
|
|
4990
|
+
const int oL0 = static_cast<int>(std::floor(oe.lMin)) - 1, oL1 = static_cast<int>(std::ceil(oe.lMax)) + 1;
|
|
4991
|
+
const int oR0 = static_cast<int>(std::floor(oe.rMin)) - 1, oR1 = static_cast<int>(std::ceil(oe.rMax)) + 1;
|
|
4992
|
+
const int iL0 = static_cast<int>(std::floor(ie.lMin)) - 1, iL1 = static_cast<int>(std::ceil(ie.lMax)) + 1;
|
|
4993
|
+
const int iR0 = static_cast<int>(std::floor(ie.rMin)) - 1, iR1 = static_cast<int>(std::ceil(ie.rMax)) + 1;
|
|
4994
|
+
for (int x = std::max(x0, oL0); x <= std::min(x1, oR1); ++x) {
|
|
4995
|
+
if (oe.whole && x > oL1 && x < oR0 && (!ie.any || ie.whole))
|
|
4996
|
+
{
|
|
4997
|
+
if (!ie.any || x < iL0 || x > iR1)
|
|
4998
|
+
{
|
|
4999
|
+
paintCoveragePixel(row[x], s.color, alpha, full, full);
|
|
5000
|
+
continue;
|
|
5001
|
+
}
|
|
5002
|
+
if (x > iL1 && x < iR0)
|
|
5003
|
+
{
|
|
5004
|
+
x = iR0 - 1; // inside the hole: nothing to paint
|
|
5005
|
+
continue;
|
|
5006
|
+
}
|
|
5007
|
+
}
|
|
4927
5008
|
int coverage;
|
|
4928
5009
|
if (cornerRow && (x < cornerX0 || x >= cornerX1))
|
|
4929
5010
|
{
|
|
@@ -5460,6 +5541,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
5460
5541
|
c->canvasBatch.x += dx;
|
|
5461
5542
|
c->canvasBatch.y += dy;
|
|
5462
5543
|
break;
|
|
5544
|
+
case DisplayCommandType::DrawSvg:
|
|
5545
|
+
c->svg.x += dx;
|
|
5546
|
+
c->svg.y += dy;
|
|
5547
|
+
break;
|
|
5463
5548
|
case DisplayCommandType::BlitImageProjected:
|
|
5464
5549
|
c->projectedBlit.x += dx;
|
|
5465
5550
|
c->projectedBlit.y += dy;
|
|
@@ -6868,6 +6953,11 @@ int gLastScrollUiFrame = -1000;
|
|
|
6868
6953
|
CanvasRenderingContext2D::replayRetainedCanvas(c.canvasBatch.nodeId, c.canvasBatch.identity,
|
|
6869
6954
|
c.canvasBatch.x, c.canvasBatch.y, c.canvasBatch.width, c.canvasBatch.height);
|
|
6870
6955
|
break;
|
|
6956
|
+
case DisplayCommandType::DrawSvg:
|
|
6957
|
+
#if GEA_UI_SVG
|
|
6958
|
+
svg::paint(c);
|
|
6959
|
+
#endif
|
|
6960
|
+
break;
|
|
6871
6961
|
case DisplayCommandType::BlitImageProjected:
|
|
6872
6962
|
drawProjectedImage(c);
|
|
6873
6963
|
break;
|
|
@@ -6963,6 +7053,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
6963
7053
|
break;
|
|
6964
7054
|
case DisplayCommandType::BlitImage:
|
|
6965
7055
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
7056
|
+
case DisplayCommandType::DrawSvg:
|
|
6966
7057
|
case DisplayCommandType::BlitImageProjected:
|
|
6967
7058
|
case DisplayCommandType::BlitImageScaled:
|
|
6968
7059
|
GEA_REFRESH_PERF(__perf.treeReplayImageUs += __replayDt);
|
|
@@ -7256,6 +7347,12 @@ int gLastScrollUiFrame = -1000;
|
|
|
7256
7347
|
{
|
|
7257
7348
|
CanvasRenderer::record(*n);
|
|
7258
7349
|
}
|
|
7350
|
+
#if GEA_UI_SVG
|
|
7351
|
+
else if (paintsOwnBox && svg::isRoot(*n))
|
|
7352
|
+
{
|
|
7353
|
+
svg::record(*n);
|
|
7354
|
+
}
|
|
7355
|
+
#endif
|
|
7259
7356
|
else if (paintsOwnBox && n->type == NodeType::Camera)
|
|
7260
7357
|
{
|
|
7261
7358
|
CameraRenderer::record(*n);
|
|
@@ -9660,6 +9757,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
9660
9757
|
// the enclosing real context. Ordinary block/inline wrappers contribute
|
|
9661
9758
|
// separate entries so block backgrounds remain below floats and text.
|
|
9662
9759
|
auto walk = [&](auto &&self, int parent, bool withinGroup) -> void {
|
|
9760
|
+
#if GEA_UI_SVG
|
|
9761
|
+
// An svg's children are its scene, painted by its DrawSvg command.
|
|
9762
|
+
if (svg::isRoot(nodes[parent])) return;
|
|
9763
|
+
#endif
|
|
9663
9764
|
std::vector<int> children;
|
|
9664
9765
|
for (int child = nodes[parent].first_child; child >= 0; child = nodes[child].next_sibling)
|
|
9665
9766
|
if (!isStructuralNodeType(nodes[child].type) && !isDisplayNone(nodes[child].computedStyle())) children.push_back(child);
|
|
@@ -11710,6 +11811,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
11710
11811
|
case DisplayCommandType::DrawText:
|
|
11711
11812
|
case DisplayCommandType::BlitImage:
|
|
11712
11813
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
11814
|
+
case DisplayCommandType::DrawSvg:
|
|
11713
11815
|
case DisplayCommandType::BlitImageProjected:
|
|
11714
11816
|
case DisplayCommandType::BlitImageScaled:
|
|
11715
11817
|
case DisplayCommandType::FillTransformedLinearGradient:
|
|
@@ -12956,6 +13058,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
12956
13058
|
CanvasRenderer::record(*n);
|
|
12957
13059
|
else if (n->type == NodeType::Camera)
|
|
12958
13060
|
CameraRenderer::record(*n);
|
|
13061
|
+
#if GEA_UI_SVG
|
|
13062
|
+
else if (svg::isRoot(*n))
|
|
13063
|
+
svg::record(*n);
|
|
13064
|
+
#endif
|
|
12959
13065
|
}
|
|
12960
13066
|
|
|
12961
13067
|
state.appendOverride = prev_override;
|
|
@@ -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
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
#include <image.h>
|
|
14
14
|
#include "css/engine.h"
|
|
15
15
|
#include "refresh_perf.h"
|
|
16
|
+
#include "svg_element.h"
|
|
16
17
|
|
|
17
18
|
#include <algorithm>
|
|
18
19
|
#include <array>
|
|
@@ -770,6 +771,13 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
|
|
|
770
771
|
Node &target = state.nodes[node];
|
|
771
772
|
if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.computedStyle()) && !firstLineChanged) return;
|
|
772
773
|
if (!nodeParticipatesInMountedTree(state, node)) return;
|
|
774
|
+
#if GEA_UI_SVG
|
|
775
|
+
// A shape's style only feeds its svg's scene: repaint that svg alone.
|
|
776
|
+
if (svg::isShape(node)) {
|
|
777
|
+
svg::noteNodeChanged(node);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
#endif
|
|
773
781
|
const bool hadRecolor = target.render.bg_recolor_pending;
|
|
774
782
|
const bool canRecolor = !target.render.dirty || hadRecolor;
|
|
775
783
|
target.render.text_partial_dirty = 0;
|
|
@@ -1245,6 +1253,16 @@ CssDeclarationId classifyDeclaration(const char *property)
|
|
|
1245
1253
|
if (std::strcmp(property, "font-family") == 0) return CssDeclarationId::FontFamily;
|
|
1246
1254
|
if (std::strcmp(property, "font-size") == 0) return CssDeclarationId::FontSize;
|
|
1247
1255
|
if (std::strcmp(property, "font-stretch") == 0) return CssDeclarationId::FontStretch;
|
|
1256
|
+
#if GEA_UI_SVG
|
|
1257
|
+
if (std::strcmp(property, "fill") == 0) return CssDeclarationId::SvgFill;
|
|
1258
|
+
if (std::strcmp(property, "stroke") == 0) return CssDeclarationId::SvgStroke;
|
|
1259
|
+
if (std::strcmp(property, "stroke-width") == 0) return CssDeclarationId::SvgStrokeWidth;
|
|
1260
|
+
if (std::strcmp(property, "fill-opacity") == 0) return CssDeclarationId::SvgFillOpacity;
|
|
1261
|
+
if (std::strcmp(property, "stroke-opacity") == 0) return CssDeclarationId::SvgStrokeOpacity;
|
|
1262
|
+
if (std::strcmp(property, "stroke-linecap") == 0) return CssDeclarationId::SvgStrokeLinecap;
|
|
1263
|
+
if (std::strcmp(property, "stroke-linejoin") == 0) return CssDeclarationId::SvgStrokeLinejoin;
|
|
1264
|
+
if (std::strcmp(property, "fill-rule") == 0) return CssDeclarationId::SvgFillRule;
|
|
1265
|
+
#endif
|
|
1248
1266
|
if (std::strcmp(property, "font-weight") == 0) return CssDeclarationId::FontWeight;
|
|
1249
1267
|
if (std::strcmp(property, "line-height") == 0) return CssDeclarationId::LineHeight;
|
|
1250
1268
|
if (std::strcmp(property, "text-align") == 0) return CssDeclarationId::TextAlign;
|
|
@@ -10075,6 +10093,21 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
|
|
|
10075
10093
|
case CssDeclarationId::Opacity:
|
|
10076
10094
|
setStyleValue(node, Property::Opacity, parseOpacity(value), source);
|
|
10077
10095
|
return true;
|
|
10096
|
+
case CssDeclarationId::SvgFill:
|
|
10097
|
+
case CssDeclarationId::SvgStroke:
|
|
10098
|
+
case CssDeclarationId::SvgStrokeWidth:
|
|
10099
|
+
case CssDeclarationId::SvgFillOpacity:
|
|
10100
|
+
case CssDeclarationId::SvgStrokeOpacity:
|
|
10101
|
+
case CssDeclarationId::SvgStrokeLinecap:
|
|
10102
|
+
case CssDeclarationId::SvgStrokeLinejoin:
|
|
10103
|
+
case CssDeclarationId::SvgFillRule: {
|
|
10104
|
+
#if GEA_UI_SVG
|
|
10105
|
+
Property property = Property::Count;
|
|
10106
|
+
int encoded = 0;
|
|
10107
|
+
if (svg::cssDeclarationValue(declaration, value.c_str(), property, encoded)) setStyleValue(node, property, encoded, source);
|
|
10108
|
+
#endif
|
|
10109
|
+
return true;
|
|
10110
|
+
}
|
|
10078
10111
|
case CssDeclarationId::BorderColor:
|
|
10079
10112
|
applyBorderColorValue(node, value, source);
|
|
10080
10113
|
return true;
|
|
@@ -17818,6 +17851,22 @@ void endStyleMountBatch()
|
|
|
17818
17851
|
if (!covered) topRoots.push_back(node);
|
|
17819
17852
|
}
|
|
17820
17853
|
|
|
17854
|
+
// `:root` matches the tree root, and mount() hangs the app under a tagless,
|
|
17855
|
+
// classless wrapper that no class change ever queues. Left unstyled, its
|
|
17856
|
+
// `:root { --x: ... }` declarations never land, every var() below it falls
|
|
17857
|
+
// back to nothing (no backgrounds, default text colour), and repaints then
|
|
17858
|
+
// draw over stale pixels. Style each pending subtree's tree root first so
|
|
17859
|
+
// its custom properties exist before descendants resolve them.
|
|
17860
|
+
std::vector<int> styledTreeRoots;
|
|
17861
|
+
for (const int node : topRoots) {
|
|
17862
|
+
int treeRoot = node;
|
|
17863
|
+
while (state.nodes[treeRoot].parent >= 0) treeRoot = state.nodes[treeRoot].parent;
|
|
17864
|
+
if (treeRoot == node || g_pendingRecomputeMark.contains(treeRoot)) continue;
|
|
17865
|
+
if (std::find(styledTreeRoots.begin(), styledTreeRoots.end(), treeRoot) != styledTreeRoots.end()) continue;
|
|
17866
|
+
styledTreeRoots.push_back(treeRoot);
|
|
17867
|
+
recomputeNodeClassStyles(treeRoot);
|
|
17868
|
+
}
|
|
17869
|
+
|
|
17821
17870
|
// Incremental recompute: a near-root class change (e.g. a theme switch) only
|
|
17822
17871
|
// re-styles nodes that actually depend on what changed; the rest keep their
|
|
17823
17872
|
// already-correct computed style. Equivalent to recomputeSubtreeClassStyles but
|
|
@@ -18776,6 +18825,9 @@ void Tree::setTagName(int node, const char *tagName)
|
|
|
18776
18825
|
const int16_t id = internTag(tagName ? tagName : "");
|
|
18777
18826
|
if (state.nodes[node].tag_id == id) return;
|
|
18778
18827
|
state.nodes[node].tag_id = id;
|
|
18828
|
+
#if GEA_UI_SVG
|
|
18829
|
+
svg::noteTagChanged(node);
|
|
18830
|
+
#endif
|
|
18779
18831
|
recomputeSubtreeClassStyles(node);
|
|
18780
18832
|
}
|
|
18781
18833
|
|
package/ui/style.h
CHANGED
|
@@ -214,6 +214,15 @@ enum class Property : int {
|
|
|
214
214
|
BorderLeftRelief,
|
|
215
215
|
BorderRelief,
|
|
216
216
|
FontStretch,
|
|
217
|
+
// SVG paint (RareStyle, GEA_UI_SVG). Encodings in svg_element.h.
|
|
218
|
+
SvgFill,
|
|
219
|
+
SvgStroke,
|
|
220
|
+
SvgStrokeWidth,
|
|
221
|
+
SvgFillOpacity,
|
|
222
|
+
SvgStrokeOpacity,
|
|
223
|
+
SvgStrokeLinecap,
|
|
224
|
+
SvgStrokeLinejoin,
|
|
225
|
+
SvgFillRule,
|
|
217
226
|
Count
|
|
218
227
|
};
|
|
219
228
|
|
|
@@ -349,7 +358,15 @@ enum class StyleDeclaration : std::uint8_t {
|
|
|
349
358
|
MarginTrim,
|
|
350
359
|
Transition,
|
|
351
360
|
AnimationPlayState,
|
|
352
|
-
FontStretch
|
|
361
|
+
FontStretch,
|
|
362
|
+
SvgFill,
|
|
363
|
+
SvgStroke,
|
|
364
|
+
SvgStrokeWidth,
|
|
365
|
+
SvgFillOpacity,
|
|
366
|
+
SvgStrokeOpacity,
|
|
367
|
+
SvgStrokeLinecap,
|
|
368
|
+
SvgStrokeLinejoin,
|
|
369
|
+
SvgFillRule
|
|
353
370
|
};
|
|
354
371
|
|
|
355
372
|
class Style {
|
package/ui/svg_element.h
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
// Inline <svg> in the node tree.
|
|
5
|
+
//
|
|
6
|
+
// Every SVG element is an ordinary node: it has the NodeHandle interface,
|
|
7
|
+
// classes, inline style, listeners and :active/:hover state. What differs is
|
|
8
|
+
// how it paints:
|
|
9
|
+
//
|
|
10
|
+
// - <svg> is a view (its CSS box, background and border paint as usual) that
|
|
11
|
+
// records ONE DrawSvg display command. That command rasterizes the svg's
|
|
12
|
+
// cached scene, anti-aliased, straight into the framebuffer at replay.
|
|
13
|
+
// - Shapes and groups (path polyline polygon line circle ellipse rect g) are
|
|
14
|
+
// out-of-flow, zero-size nodes that never paint a box of their own; they
|
|
15
|
+
// are the scene's source. The hit test descends into them by geometry, so
|
|
16
|
+
// a tap on a <circle> targets that circle and bubbles through <g> and <svg>.
|
|
17
|
+
//
|
|
18
|
+
// Paint comes from presentation attributes and from CSS (fill, stroke,
|
|
19
|
+
// stroke-width, fill-opacity, stroke-opacity, stroke-linecap,
|
|
20
|
+
// stroke-linejoin, fill-rule, opacity, color/currentColor, visibility,
|
|
21
|
+
// display, pointer-events); CSS wins over attributes, and the inheritable
|
|
22
|
+
// properties inherit through the svg subtree.
|
|
23
|
+
//
|
|
24
|
+
// A change anywhere in an svg subtree (attribute, style, class, structure)
|
|
25
|
+
// marks that svg's scene dirty; it rebuilds once, when the svg next records,
|
|
26
|
+
// and repaints only the svg's box. Everything here compiles out with
|
|
27
|
+
// GEA_UI_SVG=0, which the plugin proves for apps without <svg>.
|
|
28
|
+
|
|
29
|
+
#include "node_features.h"
|
|
30
|
+
|
|
31
|
+
#if GEA_UI_SVG
|
|
32
|
+
|
|
33
|
+
#include "style.h"
|
|
34
|
+
|
|
35
|
+
#include <cstdint>
|
|
36
|
+
|
|
37
|
+
namespace gea::embedded::ui {
|
|
38
|
+
struct Node;
|
|
39
|
+
struct DisplayCommand;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
namespace gea::embedded::ui::svg {
|
|
43
|
+
|
|
44
|
+
// True for the SVG paint properties (stored in RareStyle).
|
|
45
|
+
inline bool isPaintProperty(Property p)
|
|
46
|
+
{
|
|
47
|
+
return p >= Property::SvgFill && p <= Property::SvgFillRule;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Parses a CSS declaration value for one of the SVG paint declarations into
|
|
51
|
+
// its style property and encoded value. False leaves the property untouched.
|
|
52
|
+
bool cssDeclarationValue(StyleDeclaration declaration, const char *value, Property &property, int &encoded);
|
|
53
|
+
|
|
54
|
+
// The <svg> root test: one int compare against the interned "svg" tag id.
|
|
55
|
+
bool isRoot(const Node &node);
|
|
56
|
+
|
|
57
|
+
// True for an SVG shape, group or metadata element (anything in an svg
|
|
58
|
+
// subtree except the <svg> root). Such nodes paint nothing themselves, so
|
|
59
|
+
// inserting, removing or restyling one only repaints its svg's scene.
|
|
60
|
+
bool isShape(int node);
|
|
61
|
+
|
|
62
|
+
// The pixels (relative to the svg's box) that its last scene rebuild changed,
|
|
63
|
+
// consumed once per rebuild. False means "repaint the whole box": no rebuild
|
|
64
|
+
// since the last call, a first build or resize, a z-order change, or a change
|
|
65
|
+
// to the svg box's own style or position. An empty rect (x1 < x0) means the
|
|
66
|
+
// rebuild changed nothing on screen.
|
|
67
|
+
bool damage(int root, int &x0, int &y0, int &x1, int &y1);
|
|
68
|
+
|
|
69
|
+
// Tree hooks.
|
|
70
|
+
void noteTagChanged(int node);
|
|
71
|
+
// Records an attribute on an SVG element (value == nullptr removes it).
|
|
72
|
+
// Returns true when the node is an SVG element.
|
|
73
|
+
bool noteAttribute(int node, const char *name, const char *value);
|
|
74
|
+
// The full attribute value for an SVG element (unbounded, unlike the generic
|
|
75
|
+
// attribute store), or nullptr when the node holds no such SVG attribute.
|
|
76
|
+
const char *attribute(int node, const char *name);
|
|
77
|
+
void noteNodeChanged(int node);
|
|
78
|
+
void releaseNode(int node);
|
|
79
|
+
void clearAll();
|
|
80
|
+
|
|
81
|
+
// Refresh hook: detects changes made by any path (class recompute, :active,
|
|
82
|
+
// structure) by comparing each svg subtree's signature with its last scene.
|
|
83
|
+
void validateScenes();
|
|
84
|
+
|
|
85
|
+
// Rendering.
|
|
86
|
+
void record(const Node &svgNode);
|
|
87
|
+
void paint(const DisplayCommand &command);
|
|
88
|
+
|
|
89
|
+
// Hit test inside an svg root whose box contains (x, y): the topmost shape
|
|
90
|
+
// under the point, or -1 when no shape paints there.
|
|
91
|
+
int hitTest(int rootId, int x, int y);
|
|
92
|
+
|
|
93
|
+
} // namespace gea::embedded::ui::svg
|
|
94
|
+
|
|
95
|
+
#endif // GEA_UI_SVG
|