@geastack/engine 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/svg_geometry.h CHANGED
@@ -314,11 +314,12 @@ struct Color {
314
314
  std::uint8_t r = 0, g = 0, b = 0, a = 255;
315
315
  };
316
316
 
317
- enum class PaintKind : std::uint8_t { Unset, None, CurrentColor, Color };
317
+ enum class PaintKind : std::uint8_t { Unset, None, CurrentColor, Color, Url };
318
318
 
319
319
  struct Paint {
320
320
  PaintKind kind = PaintKind::Unset;
321
321
  Color color;
322
+ char ref[32] = {}; // Url: the referenced element's id
322
323
  };
323
324
 
324
325
  namespace detail {
@@ -483,6 +484,20 @@ inline Paint parsePaint(const char *s)
483
484
  paint.kind = PaintKind::CurrentColor;
484
485
  return paint;
485
486
  }
487
+ // url(#id): a paint server (linearGradient) in the same svg.
488
+ if (detail::iequalsPrefix(s, "url(")) {
489
+ s += 4;
490
+ while (*s == ' ' || *s == '\'' || *s == '"') ++s;
491
+ if (*s == '#') ++s;
492
+ std::size_t n = 0;
493
+ while (s[n] && s[n] != ')' && s[n] != '\'' && s[n] != '"' && s[n] != ' ' && n + 1 < sizeof(paint.ref)) {
494
+ paint.ref[n] = s[n];
495
+ ++n;
496
+ }
497
+ paint.ref[n] = '\0';
498
+ if (n > 0) paint.kind = PaintKind::Url;
499
+ return paint;
500
+ }
486
501
  if (parseColor(s, paint.color)) paint.kind = paint.color.a == 0 ? PaintKind::None : PaintKind::Color;
487
502
  return paint;
488
503
  }
@@ -495,6 +510,7 @@ inline int encodePaint(const Paint &paint)
495
510
  case PaintKind::Unset: return 0;
496
511
  case PaintKind::None: return 1;
497
512
  case PaintKind::CurrentColor: return 2;
513
+ case PaintKind::Url: return 0; // attributes only; CSS refuses it (cssDeclarationValue)
498
514
  case PaintKind::Color: break;
499
515
  }
500
516
  const int alpha7 = (paint.color.a * 126 + 127) / 255 + 1;
@@ -653,9 +669,15 @@ public:
653
669
  rx *= s;
654
670
  ry *= s;
655
671
  }
656
- const float num = rx * rx * ry * ry - rx * rx * y1p * y1p - ry * ry * x1p * x1p;
657
- const float den = rx * rx * y1p * y1p + ry * ry * x1p * x1p;
658
- float coef = den > 0 ? std::sqrt(std::max(0.0f, num / den)) : 0.0f;
672
+ // In double: near a half circle `num` is the difference of two nearly
673
+ // equal terms, and in float the centre then jitters by hundredths of a
674
+ // pixel as the end moves, so every grid point of an arc that only grew
675
+ // would move and its whole box would be damaged.
676
+ const double rx2 = static_cast<double>(rx) * rx, ry2 = static_cast<double>(ry) * ry;
677
+ const double x1p2 = static_cast<double>(x1p) * x1p, y1p2 = static_cast<double>(y1p) * y1p;
678
+ const double num = rx2 * ry2 - rx2 * y1p2 - ry2 * x1p2;
679
+ const double den = rx2 * y1p2 + ry2 * x1p2;
680
+ float coef = den > 0 ? static_cast<float>(std::sqrt(std::max(0.0, num / den))) : 0.0f;
659
681
  if (largeArc == sweep) coef = -coef;
660
682
  const float cxp = coef * rx * y1p / ry;
661
683
  const float cyp = -coef * ry * x1p / rx;
@@ -670,12 +692,33 @@ public:
670
692
  if (!sweep && dtheta > 0) dtheta -= twoPi;
671
693
  else if (sweep && dtheta < 0) dtheta += twoPi;
672
694
  const float radius = std::max(rx, ry) * m_.scale();
695
+ // The arc's points sit on a fixed grid of angles, not an even split of
696
+ // its own sweep: two arcs that share a start and differ only in where
697
+ // they end (a gauge growing by a degree) flatten to the same points up
698
+ // to the old end, so the scene rebuild damages only the changed tip.
699
+ // The grid step is 0.8 of the tolerance step because the ends skip a
700
+ // grid angle closer than a quarter step, stretching that chord.
673
701
  const float step = radius > tol_ ? 2 * std::acos(std::max(-1.0f, 1 - tol_ / radius)) : 3.14159265358979f / 2;
674
- const int n = std::clamp(static_cast<int>(std::ceil(std::fabs(dtheta) / std::max(step, 0.01f))), 1, 512);
675
- for (int i = 1; i < n; ++i) {
676
- const float t = theta1 + dtheta * i / n;
702
+ const int perTurn = std::clamp(static_cast<int>(std::ceil(twoPi / std::max(0.8f * step, 0.01f))), 4, 2048);
703
+ const float grid = twoPi / static_cast<float>(perTurn);
704
+ const float theta2 = theta1 + dtheta;
705
+ const float margin = 0.25f * grid;
706
+ auto point = [&](float t) {
677
707
  const float ex = rx * std::cos(t), ey = ry * std::sin(t);
678
708
  emit({cs * ex - sn * ey + cx, sn * ex + cs * ey + cy});
709
+ };
710
+ if (dtheta > 0) {
711
+ for (int k = static_cast<int>(std::floor(theta1 / grid)) + 1, guard = 0; guard <= perTurn + 1; ++k, ++guard) {
712
+ const float t = static_cast<float>(k) * grid;
713
+ if (t >= theta2 - margin) break;
714
+ if (t > theta1 + margin) point(t);
715
+ }
716
+ } else {
717
+ for (int k = static_cast<int>(std::ceil(theta1 / grid)) - 1, guard = 0; guard <= perTurn + 1; --k, ++guard) {
718
+ const float t = static_cast<float>(k) * grid;
719
+ if (t <= theta2 + margin) break;
720
+ if (t < theta1 - margin) point(t);
721
+ }
679
722
  }
680
723
  emit(p);
681
724
  cur_ = p;
@@ -1010,11 +1053,14 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1010
1053
  // Each segment's left normal, scaled to the half width: solved once, read
1011
1054
  // by both sides and by the joins on both its ends.
1012
1055
  ScratchVector<Point> normals(segments);
1056
+ ScratchVector<float> lengths(segments);
1013
1057
  for (std::size_t i = 0; i < segments; ++i) {
1014
1058
  const Point &a = pts[i], &b = pts[(i + 1) % n];
1015
1059
  const float dx = b.x - a.x, dy = b.y - a.y;
1016
- const float k = hw / std::sqrt(dx * dx + dy * dy);
1060
+ const float len = std::sqrt(dx * dx + dy * dy);
1061
+ const float k = hw / len;
1017
1062
  normals[i] = Point{-dy * k, dx * k};
1063
+ lengths[i] = len;
1018
1064
  }
1019
1065
  const bool roundArcs = style.cap == LineCap::Round || style.join == LineJoin::Round;
1020
1066
  const float arcStep = roundArcs ? detail::ArcStep(hw).step : 1.5707963f;
@@ -1022,7 +1068,7 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1022
1068
  out.reserve(segments * 4 + 8);
1023
1069
  // The joint at vertex p between offsets a (arriving) and b (leaving), on
1024
1070
  // the side whose offsets these are.
1025
- auto joint = [&](Point p, Point a, Point b, float cross, float dot) {
1071
+ auto joint = [&](Point p, Point a, Point b, float cross, float dot, float lenA, float lenB) {
1026
1072
  if (dot > 0 && std::fabs(cross) < 1e-4f * dot) { // straight on
1027
1073
  out.push_back({p.x + b.x, p.y + b.y});
1028
1074
  return;
@@ -1031,6 +1077,25 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1031
1077
  // the path turns away from them, where they fan apart.
1032
1078
  const bool outer = cross <= 0;
1033
1079
  const float side = a.x * b.y - a.y * b.x;
1080
+ // Where the two offset lines cross, when that point alone is the exact
1081
+ // outline: on the outer side a miter within the limit (the offset
1082
+ // points p+a and p+b lie on the lines into and out of the tip, so they
1083
+ // add only collinear edges), and on the inner side a crossing within
1084
+ // half of both segments (each segment may be cut from both ends). A
1085
+ // flattened curve then costs two outline points per vertex, not six.
1086
+ if (dot > 0 && (outer ? style.join == LineJoin::Miter : true)) {
1087
+ const float cosTurn = std::clamp(dot / (hw * hw), -1.0f, 1.0f);
1088
+ const float cosHalf = std::sqrt((1 + cosTurn) * 0.5f);
1089
+ const float sinHalf = std::sqrt(std::max(0.0f, (1 - cosTurn) * 0.5f));
1090
+ const bool fits = outer ? 1.0f / cosHalf <= style.miterLimit
1091
+ : hw * sinHalf <= cosHalf * 0.5f * std::min(lenA, lenB);
1092
+ if (cosHalf > 1e-4f && fits) {
1093
+ const Point mid{a.x + b.x, a.y + b.y};
1094
+ const float k = hw / (cosHalf * std::sqrt(mid.x * mid.x + mid.y * mid.y));
1095
+ out.push_back({p.x + mid.x * k, p.y + mid.y * k});
1096
+ return;
1097
+ }
1098
+ }
1034
1099
  out.push_back({p.x + a.x, p.y + a.y});
1035
1100
  if (!outer) {
1036
1101
  out.push_back(p);
@@ -1075,7 +1140,7 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1075
1140
  for (std::size_t v = 1; v < n - 1; ++v) {
1076
1141
  float cross, dot;
1077
1142
  turnAt(v - 1, v, cross, dot);
1078
- joint(pts[v], normals[v - 1], normals[v], cross, dot);
1143
+ joint(pts[v], normals[v - 1], normals[v], cross, dot, lengths[v - 1], lengths[v]);
1079
1144
  }
1080
1145
  // End cap, right side back, start cap.
1081
1146
  cap(pts[n - 1], normals[segments - 1]);
@@ -1083,7 +1148,7 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1083
1148
  float cross, dot;
1084
1149
  turnAt(v - 1, v, cross, dot);
1085
1150
  const Point a{-normals[v].x, -normals[v].y}, b{-normals[v - 1].x, -normals[v - 1].y};
1086
- joint(pts[v], a, b, -cross, dot);
1151
+ joint(pts[v], a, b, -cross, dot, lengths[v], lengths[v - 1]);
1087
1152
  }
1088
1153
  cap(pts[0], Point{-normals[0].x, -normals[0].y});
1089
1154
  if (style.cap != LineCap::Square) out.pop_back(); // the start cap ends where the outline began
@@ -1097,7 +1162,7 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1097
1162
  float cross, dot;
1098
1163
  const std::size_t prev = (v + segments - 1) % segments;
1099
1164
  turnAt(prev, v, cross, dot);
1100
- joint(pts[v], normals[prev], normals[v], cross, dot);
1165
+ joint(pts[v], normals[prev], normals[v], cross, dot, lengths[prev], lengths[v]);
1101
1166
  }
1102
1167
  const std::size_t leftCount = out.size();
1103
1168
  for (std::size_t k = 0; k < n; ++k) {
@@ -1106,7 +1171,7 @@ inline void strokeContour(const Contour &in, bool closed, const StrokeStyle &sty
1106
1171
  const std::size_t prev = (v + segments - 1) % segments;
1107
1172
  turnAt(prev, v, cross, dot);
1108
1173
  const Point a{-normals[v].x, -normals[v].y}, b{-normals[prev].x, -normals[prev].y};
1109
- joint(pts[v], a, b, -cross, dot);
1174
+ joint(pts[v], a, b, -cross, dot, lengths[v], lengths[prev]);
1110
1175
  }
1111
1176
  const float area = detail::polygonArea2(out.data(), leftCount) +
1112
1177
  detail::polygonArea2(out.data() + leftCount, out.size() - leftCount);
package/ui/text.cpp CHANGED
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #include "internal.h"
3
3
  #include "display.h"
4
+ #include "memory.h"
4
5
  #include "graphics/font.h"
5
6
  #include "refresh_perf.h"
6
7
  #include "tree_state.h"
@@ -134,7 +135,7 @@ struct LineBreakCacheEntry {
134
135
  std::uint16_t lineWidths[kMaxCachedLines];
135
136
  };
136
137
 
137
- LineBreakCacheEntry gLineBreakCache[kLineBreakCacheSlots];
138
+ GEA_EXT_BSS LineBreakCacheEntry gLineBreakCache[kLineBreakCacheSlots];
138
139
 
139
140
  inline std::uint32_t hashTextPrefix(const char *text)
140
141
  {
@@ -1072,7 +1073,7 @@ struct TextCoverageSink {
1072
1073
  }
1073
1074
  };
1074
1075
 
1075
- static void drawStyledTextFontFamily(const char *text,int x,int y,std::uint16_t color,int family,int size,int weight=400,int stretch=1000) {
1076
+ static void drawStyledTextFontFamily(const char *text,int x,int y,gea::framework::graphics::pixel::native_t color,int family,int size,int weight=400,int stretch=1000) {
1076
1077
  #if GEA_EMBEDDED_TTF_FREETYPE
1077
1078
  gea::platform::display::Display::drawTextFontFamily(text,x,y,color,family,size,weight,stretch);
1078
1079
  #else
@@ -1210,7 +1211,7 @@ public:
1210
1211
 
1211
1212
  private:
1212
1213
  #ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
1213
- static void drawRasterizedWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int ellipsisMaxHeight = 0, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1214
+ static void drawRasterizedWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int ellipsisMaxHeight = 0, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1214
1215
  {
1215
1216
  // Inline continuation: the run's first line starts `firstLineIndent` px in
1216
1217
  // from the box's left edge (the pen position it inherited from the box
@@ -1357,7 +1358,7 @@ private:
1357
1358
  // appending an ASCII "..." when text-overflow: ellipsis is set, or hard-
1358
1359
  // clipping at the box edge otherwise. The truncated run always fits within
1359
1360
  // maxWidth, so it never wraps and never spills past the content box.
1360
- static void drawRasterizedSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1361
+ static void drawRasterizedSingleLine(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, int textAlign, int containerWidth, int fontId, int fontSize, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1361
1362
  {
1362
1363
  gea::framework::graphics::RasterizedFont font = gea::framework::graphics::FontRegistry::rasterizedFamily(fontId, fontSize, fontWeight, fontStretch);
1363
1364
  if (!font.valid()) return;
@@ -1444,7 +1445,7 @@ private:
1444
1445
  }
1445
1446
  #endif
1446
1447
 
1447
- static void drawBitmapWrapped(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1448
+ static void drawBitmapWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign, int containerWidth, int lineHeight, int clipX0, int clipY0, int clipX1, int clipY1, int firstLineIndent = 0, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1448
1449
  {
1449
1450
  if (scale < 0.1f) scale = 1.0f;
1450
1451
  int glyphWidth = static_cast<int>(kBitmapFontWidth * scale + 0.5f);
@@ -1495,7 +1496,7 @@ private:
1495
1496
  // that is what `measureBitmap` charges for, so counting bytes here put the
1496
1497
  // truncation, the ellipsis budget and the alignment offset in different units
1497
1498
  // from the layout that placed the text.
1498
- static void drawBitmapSingleLine(const char *text, int x, int y, int maxWidth, std::uint16_t color, float scale, int textAlign, int containerWidth, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1499
+ static void drawBitmapSingleLine(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign, int containerWidth, int lineHeight, bool ellipsis, int clipX0, int clipY0, int clipX1, int clipY1, const TextCoverageSink *coverageSink = nullptr, int fontWeight = 400, int fontStretch = 1000)
1499
1500
  {
1500
1501
  (void)lineHeight;
1501
1502
  if (scale < 0.1f) scale = 1.0f;
@@ -140,6 +140,10 @@ public:
140
140
  int scrollTop(int node) const;
141
141
  void setScrollTop(int node, int scrollTop);
142
142
  void scrollIntoView(int node);
143
+ // scrollIntoView, but the target ends up inside the scroller's padding
144
+ // box rather than flush with its edge -- how LVGL scrolls a focused
145
+ // widget into view.
146
+ void scrollIntoViewKeepingPadding(int node);
143
147
  void applyPendingScrollIntoView();
144
148
 
145
149
  // Active focus for `<input>` elements. Pixel-only targets can paint the
@@ -154,6 +158,14 @@ public:
154
158
  void commitActiveInput();
155
159
  bool activeInputCaretVisible() const;
156
160
  void tickInputCaret(int timestampMs);
161
+ // Caret byte index in the active input's value, clamped to it.
162
+ int activeInputCaret() const;
163
+ // Moves the caret and restarts its blink (shown), as lv_textarea does.
164
+ void setActiveInputCaret(int pos);
165
+ // Characters [from, to) were just typed into the active (password) input.
166
+ void noteActiveInputTyped(int from, int to);
167
+ // The span of a password input's value still shown in clear, if any.
168
+ bool inputPasswordReveal(int id, int *from, int *to) const;
157
169
 
158
170
  void markDisplayListDirty();
159
171
  void markDisplayListContentDirty();
package/ui/tree_nodes.cpp CHANGED
@@ -222,6 +222,7 @@ void Tree::clear()
222
222
  std::memset(state.scrollDirtyNodes, 0, sizeof(state.scrollDirtyNodes));
223
223
  state.scrollDirtyAny = false;
224
224
  state.pendingScrollIntoViewNode = -1;
225
+ state.pendingScrollIntoViewKeepsPadding = false;
225
226
  #endif
226
227
  // Drop display-list commands and growable render scratch from the previous app.
227
228
  // Per-frame DisplayList::clear() keeps capacity for reuse; app/tree reset is the