@geastack/engine 0.1.15 → 0.1.16
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 +270 -139
- package/css/engine.h +23 -3
- package/image_store.cpp +35 -2
- package/package.json +2 -2
- package/rasterized_font.cpp +42 -2
- package/touch_runtime.cpp +231 -178
- package/ui/canvas_element.cpp +432 -125
- package/ui/canvas_element.h +84 -16
- package/ui/core.cpp +1 -0
- package/ui/debugger_listeners.h +80 -0
- package/ui/debugger_overlay.h +79 -0
- package/ui/debugger_picker.h +105 -0
- package/ui/document.cpp +1 -1
- package/ui/image_node.cpp +33 -1
- package/ui/input.cpp +27 -6
- package/ui/input_render.cpp +6 -8
- package/ui/internal.h +20 -0
- package/ui/layout.cpp +130 -17
- package/ui/layout_snapshot.cpp +1 -0
- package/ui/node.h +4 -0
- package/ui/node_lifecycle.cpp +7 -0
- package/ui/node_model.h +38 -16
- package/ui/render.cpp +259 -26
- package/ui/style.cpp +571 -66
- package/ui/style.h +16 -1
- package/ui/text.cpp +113 -65
- package/ui/tree_events.cpp +55 -13
- package/ui/tree_internal.h +5 -0
- package/ui/tree_nodes.cpp +16 -1
- package/ui/tree_render.cpp +153 -13
- package/ui/tree_style.cpp +25 -3
- package/ui/view.cpp +8 -8
package/ui/style.h
CHANGED
|
@@ -4,9 +4,22 @@
|
|
|
4
4
|
#include <cstdint>
|
|
5
5
|
#include <initializer_list>
|
|
6
6
|
#include <string>
|
|
7
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
8
|
+
#include <vector>
|
|
9
|
+
#endif
|
|
7
10
|
|
|
8
11
|
namespace gea::embedded::ui {
|
|
9
12
|
|
|
13
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
14
|
+
struct DebuggerCssRule {
|
|
15
|
+
std::string selector, property, value, media;
|
|
16
|
+
bool userAgent;
|
|
17
|
+
};
|
|
18
|
+
std::vector<DebuggerCssRule> debuggerMatchedCssRules(int nodeId);
|
|
19
|
+
std::vector<DebuggerCssRule> debuggerCssRules();
|
|
20
|
+
bool debuggerSetCssRule(const std::string &selector, const std::string &media, const std::string &property, const std::string &value);
|
|
21
|
+
#endif
|
|
22
|
+
|
|
10
23
|
int resolveLayoutSizeExpression(int nodeId, int expression, bool horizontal);
|
|
11
24
|
int resolveLineHeightExpression(int nodeId, int expression);
|
|
12
25
|
int resolveLineHeightMultiplier(int nodeId, int bits);
|
|
@@ -331,7 +344,9 @@ enum class StyleDeclaration : std::uint8_t {
|
|
|
331
344
|
BackgroundRepeat,
|
|
332
345
|
BackgroundAttachment,
|
|
333
346
|
BackgroundOrigin,
|
|
334
|
-
MarginTrim
|
|
347
|
+
MarginTrim,
|
|
348
|
+
Transition,
|
|
349
|
+
AnimationPlayState
|
|
335
350
|
};
|
|
336
351
|
|
|
337
352
|
class Style {
|
package/ui/text.cpp
CHANGED
|
@@ -344,10 +344,17 @@ inline bool canBreakAfter(int cp)
|
|
|
344
344
|
return cp == '-' || cp == '/' || cp == 0x2010 || cp == 0x2013 || cp == 0x2014;
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
int followingTextCodepoint(const char *text)
|
|
348
|
+
{
|
|
349
|
+
if (!text || !*text || *text == '\n') return 0;
|
|
350
|
+
return nextUtf8Codepoint(text);
|
|
351
|
+
}
|
|
352
|
+
|
|
347
353
|
// CSS white-space: normal/pre-line line breaking for the embedded renderer.
|
|
348
354
|
// Break at legal word boundaries. An unbreakable word can overflow the line;
|
|
349
|
-
// normal wrapping must never manufacture a break inside that word.
|
|
350
|
-
//
|
|
355
|
+
// normal wrapping must never manufacture a break inside that word.
|
|
356
|
+
// `consumedBytes` includes discarded wrapping spaces or an explicit newline,
|
|
357
|
+
// while `renderBytes` contains only the visible run.
|
|
351
358
|
template <typename AdvanceForCodepoint>
|
|
352
359
|
WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint advanceForCodepoint)
|
|
353
360
|
{
|
|
@@ -362,19 +369,23 @@ WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint
|
|
|
362
369
|
int breakConsumedBytes = -1;
|
|
363
370
|
int breakWidth = 0;
|
|
364
371
|
bool extendingSpaceBreak = false;
|
|
372
|
+
int previousCodepoint = 0;
|
|
373
|
+
int previousAdvance = 0;
|
|
365
374
|
|
|
366
|
-
while (*p)
|
|
375
|
+
while (*p)
|
|
376
|
+
{
|
|
367
377
|
const char *glyphStart = p;
|
|
368
378
|
const int cp = nextUtf8Codepoint(p);
|
|
369
379
|
const int glyphBytes = static_cast<int>(p - glyphStart);
|
|
370
|
-
if (cp == '\n')
|
|
380
|
+
if (cp == '\n')
|
|
381
|
+
{
|
|
371
382
|
line.renderBytes = bytes;
|
|
372
383
|
line.consumedBytes = bytes + glyphBytes;
|
|
373
384
|
line.width = width;
|
|
374
385
|
return line;
|
|
375
386
|
}
|
|
376
387
|
|
|
377
|
-
const int advance = advanceForCodepoint(cp);
|
|
388
|
+
const int advance = advanceForCodepoint(cp, followingTextCodepoint(p));
|
|
378
389
|
// A collapsible space at the end of a line HANGS: CSS trims it when the
|
|
379
390
|
// line is positioned, so it never overflows and never forces the break
|
|
380
391
|
// itself. Letting it break the line makes this wrapper non-idempotent —
|
|
@@ -386,7 +397,8 @@ WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint
|
|
|
386
397
|
// more line than the box was tall and the run overlapped its next
|
|
387
398
|
// sibling (typography's specimen paragraphs).
|
|
388
399
|
// Leading collapsible spaces cannot be an empty soft-wrapped line.
|
|
389
|
-
if (!isWrappingSpace(cp) && width + advance > maxWidth && bytes > 0 && breakRenderBytes > 0)
|
|
400
|
+
if (!isWrappingSpace(cp) && width + advance > maxWidth && bytes > 0 && breakRenderBytes > 0)
|
|
401
|
+
{
|
|
390
402
|
line.renderBytes = breakRenderBytes;
|
|
391
403
|
line.consumedBytes = breakConsumedBytes;
|
|
392
404
|
line.width = breakWidth;
|
|
@@ -398,21 +410,29 @@ WrappedLine nextWrappedLine(const char *text, int maxWidth, AdvanceForCodepoint
|
|
|
398
410
|
width += advance;
|
|
399
411
|
bytes += glyphBytes;
|
|
400
412
|
|
|
401
|
-
if (isWrappingSpace(cp))
|
|
402
|
-
|
|
413
|
+
if (isWrappingSpace(cp))
|
|
414
|
+
{
|
|
415
|
+
if (!extendingSpaceBreak)
|
|
416
|
+
{
|
|
403
417
|
breakRenderBytes = bytesBefore;
|
|
404
|
-
breakWidth =
|
|
418
|
+
breakWidth =
|
|
419
|
+
widthBefore + (previousCodepoint ? advanceForCodepoint(previousCodepoint, 0) - previousAdvance : 0);
|
|
405
420
|
}
|
|
406
421
|
breakConsumedBytes = bytes;
|
|
407
422
|
extendingSpaceBreak = true;
|
|
408
|
-
}
|
|
423
|
+
}
|
|
424
|
+
else
|
|
425
|
+
{
|
|
409
426
|
extendingSpaceBreak = false;
|
|
410
|
-
if (canBreakAfter(cp))
|
|
427
|
+
if (canBreakAfter(cp))
|
|
428
|
+
{
|
|
411
429
|
breakRenderBytes = bytes;
|
|
412
430
|
breakConsumedBytes = bytes;
|
|
413
|
-
breakWidth = width;
|
|
431
|
+
breakWidth = width + advanceForCodepoint(cp, 0) - advance;
|
|
414
432
|
}
|
|
415
433
|
}
|
|
434
|
+
previousCodepoint = cp;
|
|
435
|
+
previousAdvance = advance;
|
|
416
436
|
}
|
|
417
437
|
|
|
418
438
|
line.renderBytes = bytes;
|
|
@@ -550,10 +570,8 @@ bool rasterizedTextInkBounds(const char *text,
|
|
|
550
570
|
const char *lineStart = text;
|
|
551
571
|
int penY = 0;
|
|
552
572
|
while (*lineStart) {
|
|
553
|
-
const WrappedLine line =
|
|
554
|
-
|
|
555
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
556
|
-
});
|
|
573
|
+
const WrappedLine line =
|
|
574
|
+
nextWrappedLine(lineStart, maxWidth, [&](int cp, int nextCp) { return font.advance(cp, nextCp); });
|
|
557
575
|
|
|
558
576
|
int penX = alignedOffset(textAlign, containerWidth, line.width);
|
|
559
577
|
const int lineY = penY + lineBoxOffset;
|
|
@@ -564,8 +582,9 @@ bool rasterizedTextInkBounds(const char *text,
|
|
|
564
582
|
const int cp = nextUtf8Codepoint(glyphPtr);
|
|
565
583
|
consumed += static_cast<int>(glyphPtr - glyphStart);
|
|
566
584
|
gea::framework::graphics::Glyph glyph{};
|
|
567
|
-
if (!font.glyph(cp, &glyph))
|
|
568
|
-
|
|
585
|
+
if (!font.glyph(cp, &glyph))
|
|
586
|
+
{
|
|
587
|
+
penX += font.advance(cp, consumed < line.renderBytes ? followingTextCodepoint(glyphPtr) : 0);
|
|
569
588
|
continue;
|
|
570
589
|
}
|
|
571
590
|
const int gx0 = penX + glyph.bearingX;
|
|
@@ -584,7 +603,7 @@ bool rasterizedTextInkBounds(const char *text,
|
|
|
584
603
|
if (gx1 > bx1) bx1 = gx1;
|
|
585
604
|
if (gy1 > by1) by1 = gy1;
|
|
586
605
|
}
|
|
587
|
-
penX +=
|
|
606
|
+
penX += font.advance(cp, consumed < line.renderBytes ? followingTextCodepoint(glyphPtr) : 0);
|
|
588
607
|
}
|
|
589
608
|
|
|
590
609
|
lineStart += line.consumedBytes;
|
|
@@ -718,9 +737,8 @@ bool recordProjectedRasterText(const Node &node, const char *text, uint8_t /*par
|
|
|
718
737
|
|
|
719
738
|
int lineWidth = 0;
|
|
720
739
|
for (const char *p = text; *p;) {
|
|
721
|
-
gea::framework::graphics::Glyph glyph{};
|
|
722
740
|
const int cp = nextUtf8Codepoint(p);
|
|
723
|
-
lineWidth += font.
|
|
741
|
+
lineWidth += font.advance(cp, followingTextCodepoint(p));
|
|
724
742
|
}
|
|
725
743
|
|
|
726
744
|
int bx0, by0, bx1, by1;
|
|
@@ -881,7 +899,7 @@ public:
|
|
|
881
899
|
if (maxWidth <= 0) maxWidth = 32767;
|
|
882
900
|
const char *lineStart = text;
|
|
883
901
|
while (*lineStart) {
|
|
884
|
-
const WrappedLine line = nextWrappedLine(lineStart, maxWidth, [&](int) { return glyphWidth; });
|
|
902
|
+
const WrappedLine line = nextWrappedLine(lineStart, maxWidth, [&](int, int) { return glyphWidth; });
|
|
885
903
|
if (line.width > maxLineWidth) maxLineWidth = line.width;
|
|
886
904
|
lineStart += line.consumedBytes;
|
|
887
905
|
if (*lineStart) lines++;
|
|
@@ -906,10 +924,8 @@ public:
|
|
|
906
924
|
if (maxWidth <= 0) maxWidth = 32767;
|
|
907
925
|
const char *lineStart = text;
|
|
908
926
|
while (*lineStart) {
|
|
909
|
-
const WrappedLine line =
|
|
910
|
-
|
|
911
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
912
|
-
});
|
|
927
|
+
const WrappedLine line =
|
|
928
|
+
nextWrappedLine(lineStart, maxWidth, [&](int cp, int nextCp) { return font.advance(cp, nextCp); });
|
|
913
929
|
if (line.width > maxLineWidth) maxLineWidth = line.width;
|
|
914
930
|
lineStart += line.consumedBytes;
|
|
915
931
|
if (*lineStart) lines++;
|
|
@@ -935,15 +951,15 @@ struct GlyphAdvanceSource {
|
|
|
935
951
|
#endif
|
|
936
952
|
int glyphWidth = 0;
|
|
937
953
|
|
|
938
|
-
int operator()(int cp) const
|
|
954
|
+
int operator()(int cp, int nextCp = 0) const
|
|
939
955
|
{
|
|
940
956
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
941
957
|
if (rasterized) {
|
|
942
|
-
|
|
943
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
958
|
+
return font.advance(cp, nextCp);
|
|
944
959
|
}
|
|
945
960
|
#else
|
|
946
961
|
(void)cp;
|
|
962
|
+
(void)nextCp;
|
|
947
963
|
#endif
|
|
948
964
|
return glyphWidth;
|
|
949
965
|
}
|
|
@@ -1089,14 +1105,18 @@ public:
|
|
|
1089
1105
|
for (const char *p = text; p && *p;) {
|
|
1090
1106
|
const int cp = nextUtf8Codepoint(p);
|
|
1091
1107
|
gea::framework::graphics::Glyph glyph{};
|
|
1092
|
-
if (!font.glyph(cp, &glyph))
|
|
1108
|
+
if (!font.glyph(cp, &glyph))
|
|
1109
|
+
{
|
|
1110
|
+
penX += font.advance(cp, followingTextCodepoint(p));
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1093
1113
|
const int gx = penX + glyph.bearingX;
|
|
1094
1114
|
const int gy = y + font.ascender() - glyph.bearingY;
|
|
1095
1115
|
const int row = sink.screenY - gy;
|
|
1096
1116
|
if (row >= 0 && row < glyph.height)
|
|
1097
1117
|
for (int col = 0; col < glyph.width; ++col)
|
|
1098
1118
|
sink.add(gx + col, sink.screenY, font.coverage(glyph, row, col));
|
|
1099
|
-
penX +=
|
|
1119
|
+
penX += font.advance(cp, followingTextCodepoint(p));
|
|
1100
1120
|
}
|
|
1101
1121
|
}
|
|
1102
1122
|
#endif
|
|
@@ -1224,10 +1244,8 @@ private:
|
|
|
1224
1244
|
|
|
1225
1245
|
const char *p = text;
|
|
1226
1246
|
while (*p && entry.lineCount < kMaxCachedLines) {
|
|
1227
|
-
const WrappedLine line = nextWrappedLine(p, lineBudget_(entry.lineCount),
|
|
1228
|
-
|
|
1229
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
1230
|
-
});
|
|
1247
|
+
const WrappedLine line = nextWrappedLine(p, lineBudget_(entry.lineCount),
|
|
1248
|
+
[&](int cp, int nextCp) { return font.advance(cp, nextCp); });
|
|
1231
1249
|
entry.renderBytes[entry.lineCount] = static_cast<std::uint16_t>(line.renderBytes > 65535 ? 65535 : line.renderBytes);
|
|
1232
1250
|
entry.consumedBytes[entry.lineCount] = static_cast<std::uint16_t>(line.consumedBytes > 65535 ? 65535 : line.consumedBytes);
|
|
1233
1251
|
entry.lineWidths[entry.lineCount] = static_cast<std::uint16_t>(line.width > 65535 ? 65535 : line.width);
|
|
@@ -1291,10 +1309,8 @@ private:
|
|
|
1291
1309
|
const int lineIndex = li;
|
|
1292
1310
|
li++;
|
|
1293
1311
|
|
|
1294
|
-
const WrappedLine line = nextWrappedLine(lineStart, lineBudget_(lineIndex),
|
|
1295
|
-
|
|
1296
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
1297
|
-
});
|
|
1312
|
+
const WrappedLine line = nextWrappedLine(lineStart, lineBudget_(lineIndex),
|
|
1313
|
+
[&](int cp, int nextCp) { return font.advance(cp, nextCp); });
|
|
1298
1314
|
|
|
1299
1315
|
const int lineBoxY = penY + lineBoxOffset;
|
|
1300
1316
|
if (lineBoxY + glyphHeight - 1 >= clipY0) {
|
|
@@ -1331,14 +1347,15 @@ private:
|
|
|
1331
1347
|
if (lineBoxY > clipY1 || lineBoxY + glyphHeight - 1 < clipY0) return;
|
|
1332
1348
|
if (maxWidth <= 0) maxWidth = 32767;
|
|
1333
1349
|
|
|
1334
|
-
const auto advanceOf = [&font](int cp) {
|
|
1335
|
-
gea::framework::graphics::Glyph glyph{};
|
|
1336
|
-
return font.glyph(cp, &glyph) ? glyph.advance : (font.sizePx() / 2);
|
|
1337
|
-
};
|
|
1350
|
+
const auto advanceOf = [&font](int cp, int nextCp = 0) { return font.advance(cp, nextCp); };
|
|
1338
1351
|
|
|
1339
1352
|
// Full single-line advance width (stop at the first newline).
|
|
1340
1353
|
int fullWidth = 0;
|
|
1341
|
-
for (const char *p = text; *p && *p != '\n';)
|
|
1354
|
+
for (const char *p = text; *p && *p != '\n';)
|
|
1355
|
+
{
|
|
1356
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1357
|
+
fullWidth += advanceOf(cp, followingTextCodepoint(p));
|
|
1358
|
+
}
|
|
1342
1359
|
|
|
1343
1360
|
char buf[256];
|
|
1344
1361
|
int len = 0;
|
|
@@ -1348,36 +1365,51 @@ private:
|
|
|
1348
1365
|
if (fullWidth <= maxWidth) {
|
|
1349
1366
|
for (const char *p = text; *p && *p != '\n' && len < kBufCap - 1; ++p) buf[len++] = *p;
|
|
1350
1367
|
drawnWidth = fullWidth;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const int
|
|
1368
|
+
}
|
|
1369
|
+
else if (ellipsis)
|
|
1370
|
+
{
|
|
1371
|
+
const int ellipsisWidth = advanceOf('.', '.') * 2 + advanceOf('.');
|
|
1355
1372
|
int w = 0;
|
|
1373
|
+
int previousCp = 0;
|
|
1356
1374
|
const char *p = text;
|
|
1357
|
-
while (*p && *p != '\n')
|
|
1375
|
+
while (*p && *p != '\n')
|
|
1376
|
+
{
|
|
1358
1377
|
const char *glyphStart = p;
|
|
1359
|
-
const int
|
|
1360
|
-
|
|
1378
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1379
|
+
const int candidateWidth =
|
|
1380
|
+
w + advanceOf(cp) + (previousCp ? advanceOf(previousCp, cp) - advanceOf(previousCp) : 0);
|
|
1381
|
+
const int withEllipsis = candidateWidth - advanceOf(cp) + advanceOf(cp, '.') + ellipsisWidth;
|
|
1382
|
+
if (withEllipsis > maxWidth) break;
|
|
1361
1383
|
const int bytes = static_cast<int>(p - glyphStart);
|
|
1362
|
-
if (len + bytes > kBufCap - 4) break;
|
|
1363
|
-
for (int i = 0; i < bytes; ++i)
|
|
1364
|
-
|
|
1384
|
+
if (len + bytes > kBufCap - 4) break; // leave room for "..." + NUL
|
|
1385
|
+
for (int i = 0; i < bytes; ++i)
|
|
1386
|
+
buf[len++] = glyphStart[i];
|
|
1387
|
+
w = candidateWidth;
|
|
1388
|
+
previousCp = cp;
|
|
1365
1389
|
}
|
|
1366
1390
|
buf[len++] = '.';
|
|
1367
1391
|
buf[len++] = '.';
|
|
1368
1392
|
buf[len++] = '.';
|
|
1369
|
-
drawnWidth = w + ellipsisWidth;
|
|
1370
|
-
}
|
|
1393
|
+
drawnWidth = w + ellipsisWidth + (previousCp ? advanceOf(previousCp, '.') - advanceOf(previousCp) : 0);
|
|
1394
|
+
}
|
|
1395
|
+
else
|
|
1396
|
+
{
|
|
1371
1397
|
int w = 0;
|
|
1398
|
+
int previousCp = 0;
|
|
1372
1399
|
const char *p = text;
|
|
1373
|
-
while (*p && *p != '\n')
|
|
1400
|
+
while (*p && *p != '\n')
|
|
1401
|
+
{
|
|
1374
1402
|
const char *glyphStart = p;
|
|
1375
|
-
const int
|
|
1376
|
-
|
|
1403
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1404
|
+
const int candidateWidth =
|
|
1405
|
+
w + advanceOf(cp) + (previousCp ? advanceOf(previousCp, cp) - advanceOf(previousCp) : 0);
|
|
1406
|
+
if (candidateWidth > maxWidth && len > 0) break;
|
|
1377
1407
|
const int bytes = static_cast<int>(p - glyphStart);
|
|
1378
1408
|
if (len + bytes > kBufCap - 1) break;
|
|
1379
|
-
for (int i = 0; i < bytes; ++i)
|
|
1380
|
-
|
|
1409
|
+
for (int i = 0; i < bytes; ++i)
|
|
1410
|
+
buf[len++] = glyphStart[i];
|
|
1411
|
+
w = candidateWidth;
|
|
1412
|
+
previousCp = cp;
|
|
1381
1413
|
}
|
|
1382
1414
|
drawnWidth = w;
|
|
1383
1415
|
}
|
|
@@ -1409,7 +1441,8 @@ private:
|
|
|
1409
1441
|
// the inherited pen and has that much less room.
|
|
1410
1442
|
const int budget = lineIndex == 0 ? maxWidth - firstLineIndent : maxWidth;
|
|
1411
1443
|
const int lineOriginX = lineIndex == 0 ? x + firstLineIndent : x;
|
|
1412
|
-
const WrappedLine line =
|
|
1444
|
+
const WrappedLine line =
|
|
1445
|
+
nextWrappedLine(lineStart, budget < 1 ? 1 : budget, [&](int, int) { return glyphWidth; });
|
|
1413
1446
|
lineIndex++;
|
|
1414
1447
|
|
|
1415
1448
|
if (penY + glyphHeight - 1 >= clipY0) {
|
|
@@ -1762,7 +1795,11 @@ InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAva
|
|
|
1762
1795
|
const char *p = text;
|
|
1763
1796
|
const char *end = text + lead;
|
|
1764
1797
|
int width = 0;
|
|
1765
|
-
while (p < end)
|
|
1798
|
+
while (p < end)
|
|
1799
|
+
{
|
|
1800
|
+
const int cp = nextUtf8Codepoint(p);
|
|
1801
|
+
width += advance(cp, followingTextCodepoint(p));
|
|
1802
|
+
}
|
|
1766
1803
|
out.firstLineIndentAdjust = -width;
|
|
1767
1804
|
}
|
|
1768
1805
|
}
|
|
@@ -1780,8 +1817,10 @@ InlineFlowMeasure TextRenderer::measureInlineFlow(const Node &node, int firstAva
|
|
|
1780
1817
|
const char *end = p + line.renderBytes;
|
|
1781
1818
|
for (const char *glyph = p; glyph < end;) {
|
|
1782
1819
|
const int cp = nextUtf8Codepoint(glyph);
|
|
1783
|
-
out.firstLineTrailingSpace =
|
|
1784
|
-
|
|
1820
|
+
out.firstLineTrailingSpace =
|
|
1821
|
+
isWrappingSpace(cp)
|
|
1822
|
+
? out.firstLineTrailingSpace + advance(cp, glyph < end ? followingTextCodepoint(glyph) : 0)
|
|
1823
|
+
: 0;
|
|
1785
1824
|
}
|
|
1786
1825
|
}
|
|
1787
1826
|
}
|
|
@@ -1886,6 +1925,15 @@ bool TextRenderer::remeasureContentBox(int id, bool keepBoxWidth)
|
|
|
1886
1925
|
return true;
|
|
1887
1926
|
}
|
|
1888
1927
|
|
|
1928
|
+
int TextRenderer::reflowToBoxWidth(int id)
|
|
1929
|
+
{
|
|
1930
|
+
Node &n = Tree::instance().nodes()[id];
|
|
1931
|
+
const int content_w = std::max(1, n.layout.width - boxInsets(n.computedStyle(), true));
|
|
1932
|
+
const TextLayoutMeasure measured = measureTextLayoutForNode(n, n.text.c_str(), content_w);
|
|
1933
|
+
n.layout.height = static_cast<int16_t>(std::min(measured.height, 32767));
|
|
1934
|
+
return measured.width;
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1889
1937
|
void TextRenderer::drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int text_align, int containerWidth, int fontId, int textTransform, int lineHeight, int whiteSpace, int textOverflow, int maxHeight, int firstLineIndent)
|
|
1890
1938
|
{
|
|
1891
1939
|
TextDrawer::drawWrapped(text, x, y, maxWidth, color, scale, text_align, containerWidth, fontId, textTransform, lineHeight, whiteSpace, textOverflow, maxHeight, firstLineIndent);
|
package/ui/tree_events.cpp
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#include "tree_events.h"
|
|
3
3
|
|
|
4
4
|
#include "audio.h"
|
|
5
|
+
#include <image.h>
|
|
5
6
|
#include "internal.h"
|
|
6
7
|
#include "tree_internal.h"
|
|
7
8
|
#include "tree_state.h"
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
#include <utility>
|
|
15
16
|
#include <vector>
|
|
16
17
|
|
|
17
|
-
extern "C" double
|
|
18
|
+
extern "C" double gea_host_image_acquire_asset_path(const char *path, bool *owned);
|
|
18
19
|
|
|
19
20
|
namespace gea::embedded::ui {
|
|
20
21
|
|
|
@@ -58,7 +59,7 @@ void applyAudioAttribute(Tree &tree, int node, const char *name, const char *val
|
|
|
58
59
|
// Index order mirrors NodeEventListeners' slots and is kept in sync by
|
|
59
60
|
// setEventListener (on the empty->set transition) and NodeEventListeners::clear()
|
|
60
61
|
// (which every removal path calls).
|
|
61
|
-
constexpr int kEventTypeCount =
|
|
62
|
+
constexpr int kEventTypeCount = 8;
|
|
62
63
|
#if GEA_UI_NODE_LISTENERS
|
|
63
64
|
int g_listenerTypeCounts[kEventTypeCount] = {};
|
|
64
65
|
EventListenerId g_nextEventListenerId = 1;
|
|
@@ -79,6 +80,7 @@ int eventTypeIndex(const char *type)
|
|
|
79
80
|
if (sameName(type, "input")) return 4;
|
|
80
81
|
if (sameName(type, "keydown")) return 5;
|
|
81
82
|
if (sameName(type, "scroll")) return 6;
|
|
83
|
+
if (sameName(type, "keyup")) return 7;
|
|
82
84
|
return -1;
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -90,6 +92,7 @@ int eventTypeIndex(const char *type)
|
|
|
90
92
|
// never by the tree walk. Reset on app switch via resetDocumentEventListeners().
|
|
91
93
|
gea::framework::events::EventListener g_documentRotaryListener;
|
|
92
94
|
gea::framework::events::EventListener g_documentKeyDownListener;
|
|
95
|
+
gea::framework::events::EventListener g_documentKeyUpListener;
|
|
93
96
|
|
|
94
97
|
void chainDocumentListener(gea::framework::events::EventListener &slot,
|
|
95
98
|
gea::framework::events::EventListener listener)
|
|
@@ -113,6 +116,7 @@ void resetDocumentEventListeners()
|
|
|
113
116
|
{
|
|
114
117
|
g_documentRotaryListener = {};
|
|
115
118
|
g_documentKeyDownListener = {};
|
|
119
|
+
g_documentKeyUpListener = {};
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
// Register a document-level handler. Only "rotary" and "keydown" are
|
|
@@ -128,6 +132,9 @@ void setDocumentEventListener(const char *type, gea::framework::events::EventLis
|
|
|
128
132
|
if (sameName(type, "keydown")) {
|
|
129
133
|
chainDocumentListener(g_documentKeyDownListener, std::move(listener));
|
|
130
134
|
}
|
|
135
|
+
if (sameName(type, "keyup")) {
|
|
136
|
+
chainDocumentListener(g_documentKeyUpListener, std::move(listener));
|
|
137
|
+
}
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
// Fire the document-level rotary handler with a fresh Rotary event carrying the
|
|
@@ -152,6 +159,13 @@ bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event)
|
|
|
152
159
|
return true;
|
|
153
160
|
}
|
|
154
161
|
|
|
162
|
+
bool dispatchDocumentKeyUp(gea::framework::events::PointerEvent &event)
|
|
163
|
+
{
|
|
164
|
+
if (!g_documentKeyUpListener) return false;
|
|
165
|
+
g_documentKeyUpListener(event);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
155
169
|
// ---- NodeRareData pool ------------------------------------------------------
|
|
156
170
|
//
|
|
157
171
|
// Cold/optional per-node state (currently event listeners) lives here instead
|
|
@@ -174,11 +188,12 @@ NodeAuxiliaryStorageUsage nodeAuxiliaryStorageUsage()
|
|
|
174
188
|
result.text = NodeText::storageUsage();
|
|
175
189
|
result.dependencies = styleDependencyStorageUsage();
|
|
176
190
|
auto &usage = result.rare;
|
|
177
|
-
usage.staticBytes = sizeof(g_rareDataPool) + sizeof(g_rareDataFreeList) + sizeof(g_documentKeyDownListener) + sizeof(g_documentRotaryListener);
|
|
191
|
+
usage.staticBytes = sizeof(g_rareDataPool) + sizeof(g_rareDataFreeList) + sizeof(g_documentKeyUpListener) + sizeof(g_documentKeyDownListener) + sizeof(g_documentRotaryListener);
|
|
178
192
|
#if GEA_UI_NODE_LISTENERS
|
|
179
193
|
usage.staticBytes += sizeof(g_listenerTypeCounts) + sizeof(g_nextEventListenerId);
|
|
180
194
|
#endif
|
|
181
195
|
if (g_documentKeyDownListener) ++usage.untrackedOwners;
|
|
196
|
+
if (g_documentKeyUpListener) ++usage.untrackedOwners;
|
|
182
197
|
if (g_documentRotaryListener) ++usage.untrackedOwners;
|
|
183
198
|
usage.addVector(g_rareDataPool);
|
|
184
199
|
usage.addVector(g_rareDataFreeList);
|
|
@@ -389,7 +404,7 @@ void NodeAttributeStore::set(const char *name, const char *)
|
|
|
389
404
|
void NodeEventListeners::clear()
|
|
390
405
|
{
|
|
391
406
|
#if GEA_UI_NODE_LISTENERS
|
|
392
|
-
for (int type = 0; type <
|
|
407
|
+
for (int type = 0; type < kEventTypeCount; ++type)
|
|
393
408
|
if (hasType(type) && g_listenerTypeCounts[type] > 0) --g_listenerTypeCounts[type];
|
|
394
409
|
entries.clear();
|
|
395
410
|
types = 0;
|
|
@@ -600,16 +615,39 @@ void Tree::setAttribute(int node, const char *name, const char *value)
|
|
|
600
615
|
}
|
|
601
616
|
ensureRareData(node).attributes.set(name, value);
|
|
602
617
|
if (state.nodes[node].type == NodeType::Image && sameName(name, "src")) {
|
|
603
|
-
const
|
|
604
|
-
|
|
618
|
+
const auto &style = state.nodes[node].computedStyle();
|
|
619
|
+
const bool fixedBox = (style.width != kUnset || style.width_percent != kUnset) &&
|
|
620
|
+
(style.height != kUnset || style.height_percent != kUnset);
|
|
621
|
+
bool hadBlit = false;
|
|
622
|
+
for (int i = 0; i < DisplayList::instance().nodeCommandCount(node); ++i) {
|
|
623
|
+
const auto *command = DisplayList::instance().nodeCommandAt(node, i);
|
|
624
|
+
if (command && (command->type == DisplayCommandType::BlitImage ||
|
|
625
|
+
command->type == DisplayCommandType::BlitImageScaled ||
|
|
626
|
+
command->type == DisplayCommandType::BlitImageProjected))
|
|
627
|
+
hadBlit = true;
|
|
628
|
+
}
|
|
629
|
+
bool owned = false;
|
|
630
|
+
const int imageId = static_cast<int>(gea_host_image_acquire_asset_path(value ? value : "", &owned));
|
|
631
|
+
{
|
|
605
632
|
setStyleFromClass(node, Property::ImageId, imageId);
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
633
|
+
if (owned) gea::framework::graphics::ImageStore::instance().release(imageId);
|
|
634
|
+
if (fixedBox) {
|
|
635
|
+
// ImageId already owns fixed-box paint invalidation. Replacing
|
|
636
|
+
// an existing blit changes this image, not the scene's structure.
|
|
637
|
+
// A previously empty range needs a fresh recording, but still
|
|
638
|
+
// only damages this fixed box; siblings need no full repaint.
|
|
639
|
+
if (!hadBlit) markDisplayListContentDirty();
|
|
640
|
+
// Mark even if a runtime file reused the same decoded slot id.
|
|
641
|
+
markNodeDisplayCommandsDirty(node);
|
|
642
|
+
state.nodes[node].render.dirty = 1;
|
|
643
|
+
#if GEA_CSS_SCROLLING
|
|
644
|
+
state.nodes[node].render.non_scroll_dirty = 1;
|
|
645
|
+
#endif
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
// An intrinsic-size image can change surrounding layout and may
|
|
649
|
+
// introduce its first blit. Keep the full layout/recording fallback
|
|
650
|
+
// for this case so newly loaded images and displaced siblings paint.
|
|
613
651
|
markDisplayListDirty();
|
|
614
652
|
state.nodes[node].render.dirty = 1;
|
|
615
653
|
#if GEA_CSS_SCROLLING
|
|
@@ -652,6 +690,10 @@ void Tree::removeAttribute(int node, const char *name)
|
|
|
652
690
|
if (!rd) return; // no rare-data block → no attributes to remove
|
|
653
691
|
const bool hadAttribute = rd->attributes.remove(name);
|
|
654
692
|
if (!hadAttribute) return;
|
|
693
|
+
if (state.nodes[node].type == NodeType::Image && sameName(name, "src")) {
|
|
694
|
+
setStyleFromClass(node, Property::ImageId, -1);
|
|
695
|
+
markDisplayListDirty();
|
|
696
|
+
}
|
|
655
697
|
#if GEA_UI_NODE_ATTRIBUTES
|
|
656
698
|
if (sameName(name, "data-press-id")) rd->attributes.pressId = -1;
|
|
657
699
|
if (sameName(name, "data-press-value")) rd->attributes.pressValue = -1;
|
package/ui/tree_internal.h
CHANGED
|
@@ -171,6 +171,7 @@ private:
|
|
|
171
171
|
void setDocumentEventListener(const char *type, gea::framework::events::EventListener listener);
|
|
172
172
|
void dispatchDocumentRotary(int delta);
|
|
173
173
|
bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event);
|
|
174
|
+
bool dispatchDocumentKeyUp(gea::framework::events::PointerEvent &event);
|
|
174
175
|
void resetDocumentEventListeners();
|
|
175
176
|
void resetDocumentDelegatedEventListeners();
|
|
176
177
|
|
|
@@ -215,6 +216,10 @@ void releaseRareData(int node); // frees the block back to the pool
|
|
|
215
216
|
// Caller must hold AppState::lock(). Returns false for canvas/present apps.
|
|
216
217
|
bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height);
|
|
217
218
|
|
|
219
|
+
// Snapshot replay temporarily binds only the primary canvas to an offscreen
|
|
220
|
+
// buffer. A worker canvas still addresses the display framebuffer.
|
|
221
|
+
extern bool gSnapshotRasterActive;
|
|
222
|
+
|
|
218
223
|
#if GEA_EMBEDDED_DISPLAY_BANDED_UI
|
|
219
224
|
// Banded UI mode: the retained tree renders each dirty band straight into the
|
|
220
225
|
// display's DMA staging buffers, so the PSRAM framebuffer does not hold the
|
package/ui/tree_nodes.cpp
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "internal.h"
|
|
3
|
+
#include <image.h>
|
|
4
|
+
#include "canvas_element.h"
|
|
3
5
|
#include "display.h"
|
|
4
6
|
#include "host/display_orientation.h"
|
|
5
7
|
#include "mirror.h"
|
|
@@ -99,6 +101,9 @@ void resetNodeSlot(TreeState &state, int id)
|
|
|
99
101
|
{
|
|
100
102
|
if (id < 0 || id >= kMaxNodes) return;
|
|
101
103
|
forgetNodeCssAnimations(id);
|
|
104
|
+
#if GEA_UI_IMAGE_NODES
|
|
105
|
+
gea::framework::graphics::ImageStore::instance().release(state.nodes[id].image_id);
|
|
106
|
+
#endif
|
|
102
107
|
// The node's text buffer dies with the slot; retained display commands hold
|
|
103
108
|
// a raw pointer into it (see DisplayList::scrubNodeText) — neutralize them
|
|
104
109
|
// before NodeLifecycle::init frees the string, or a stale-list replay in the
|
|
@@ -181,7 +186,12 @@ void Tree::clear()
|
|
|
181
186
|
// and resets to an empty SSO state, while still zeroing all the
|
|
182
187
|
// POD fields. Slightly slower than memset but runs once per app
|
|
183
188
|
// switch and bounded at kMaxNodes (~512).
|
|
184
|
-
for (int i = 0; i < kMaxNodes; i++)
|
|
189
|
+
for (int i = 0; i < kMaxNodes; i++) {
|
|
190
|
+
#if GEA_UI_IMAGE_NODES
|
|
191
|
+
if (i < state.nodeCount) gea::framework::graphics::ImageStore::instance().release(state.nodes[i].image_id);
|
|
192
|
+
#endif
|
|
193
|
+
state.nodes[i] = Node{};
|
|
194
|
+
}
|
|
185
195
|
state.nodeCount = 0;
|
|
186
196
|
state.fixedPositionUsed = false;
|
|
187
197
|
state.mountedRoot = -1;
|
|
@@ -260,6 +270,7 @@ int Tree::cloneNode(int sourceId, bool deep)
|
|
|
260
270
|
clone.text = source.text;
|
|
261
271
|
#if GEA_UI_IMAGE_NODES
|
|
262
272
|
clone.image_id = source.image_id;
|
|
273
|
+
gea::framework::graphics::ImageStore::instance().retain(clone.image_id);
|
|
263
274
|
#endif
|
|
264
275
|
clone.tag_id = source.tag_id; // interned tag id — just copy the handle
|
|
265
276
|
// Copy attributes + custom properties (DOM cloneNode semantics) but NOT
|
|
@@ -327,6 +338,7 @@ int Tree::createVirtualList() { return createNode(NodeType::VirtualList); }
|
|
|
327
338
|
|
|
328
339
|
gea::framework::graphics::Canvas *Tree::ensureCanvas(int id, int width, int height)
|
|
329
340
|
{
|
|
341
|
+
CanvasRenderingContext2D::materializeRetainedCanvas(id);
|
|
330
342
|
auto &state = treeState();
|
|
331
343
|
if (id < 0 || id >= state.nodeCount) return nullptr;
|
|
332
344
|
Node &node = state.nodes[id];
|
|
@@ -445,6 +457,7 @@ gea::framework::graphics::Canvas *Tree::ensureCameraSurface(int id, int width, i
|
|
|
445
457
|
|
|
446
458
|
const gea::framework::graphics::Canvas *Tree::canvas(int id) const
|
|
447
459
|
{
|
|
460
|
+
CanvasRenderingContext2D::materializeRetainedCanvas(id);
|
|
448
461
|
const auto &state = treeState();
|
|
449
462
|
if (id < 0 || id >= state.nodeCount) return nullptr;
|
|
450
463
|
const auto *slot = state.canvases.find(id);
|
|
@@ -484,6 +497,7 @@ void Tree::markCanvasDirty(int id)
|
|
|
484
497
|
// It used to be set here, and a canvas redrawn every frame (Ember's heat
|
|
485
498
|
// arc) then cost a full relayout of the whole screen per frame (~5.5 ms of
|
|
486
499
|
// 163 layout calls on the S31) for a box that never moved.
|
|
500
|
+
const bool pixelsOnly = !state.nodes[id].render.dirty || state.nodes[id].render.canvas_pixels_only_dirty;
|
|
487
501
|
state.nodes[id].render.dirty = 1;
|
|
488
502
|
#if GEA_CSS_SCROLLING
|
|
489
503
|
state.nodes[id].render.non_scroll_dirty = 1;
|
|
@@ -496,6 +510,7 @@ void Tree::markCanvasDirty(int id)
|
|
|
496
510
|
// reach the display (same trap as the per-frame <camera> preview repaint
|
|
497
511
|
// in tree_render.cpp, which uses the content-dirty mark for this reason).
|
|
498
512
|
markNodeDisplayCommandsDirty(id);
|
|
513
|
+
state.nodes[id].render.canvas_pixels_only_dirty = pixelsOnly;
|
|
499
514
|
}
|
|
500
515
|
|
|
501
516
|
// A reparent that puts `parent` under `child` closes a cycle in the parent chain.
|