drawnui-react 0.1.0-preview.32 → 0.1.0-preview.34

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/SKIPPED.md CHANGED
@@ -62,7 +62,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
62
62
 
63
63
  | Control | Status | Notes |
64
64
  |---|---|---|
65
- | `SkiaLayout` Absolute / Column / Row (+ `SkiaStack`, `SkiaRow`, `SkiaLayer`) | ported | `Spacing`, `Padding`, `Children`/`Views`, `AddSubView`/`RemoveSubView`/`InsertSubView`, `ClearChildren`, `IsChildrenItem`. Children changes follow C# `ChildrenCollectionSync` (insert / move / reset in collection order inside the slots app children occupy); React has no `ObservableCollection`: JSX children diffs and a new `Children` list are the collection actions. |
65
+ | `SkiaLayout` Absolute / Column / Row (+ `SkiaStack`, `SkiaRow`, `SkiaLayer`) | ported | A Column / Row that sizes itself on its cross axis takes its widest / tallest child's fit-content size, Fill children included, and lays those Fill children out at that size (drawnui-cross 6an). `Spacing`, `Padding`, `Children`/`Views`, `AddSubView`/`RemoveSubView`/`InsertSubView`, `ClearChildren`, `IsChildrenItem`. Children changes follow C# `ChildrenCollectionSync` (insert / move / reset in collection order inside the slots app children occupy); React has no `ObservableCollection`: JSX children diffs and a new `Children` list are the collection actions. |
66
66
  | `SkiaLayout` templated (Column only): `ItemsSource` (array), `ItemTemplate` (factory `() => SkiaControl`), `RecyclingTemplate` Enabled/Disabled, `MeasureItemsStrategy` `MeasureAll` (default, per-item size) / `MeasureFirst` (explicit uniform, O(1) for 100k items), `ChildrenFactory` (ViewsAdapter pool: `GetOrCreateViewForIndex`, `ReleaseViewAt`), `FirstVisibleIndex`/`LastVisibleIndex`, `DebugString`, `ApplyItemsSource`, `VirtualisationInflated`, `BindingContext`/`ContextIndex` on every control, `SkiaDynamicDrawnCell.SetContent` | ported | Cells realized/bound/arranged/drawn only for the visible viewport (+inflation) each frame. |
67
67
  | `LoadMoreCommand` / `LoadMoreTopCommand` / `LoadMoreOffset` / `LoadMoreTopOffset` | ported | Callbacks instead of ICommand. Bottom fires once per content extent when within the offset of the end (or when the content underfills the viewport), re-arms when the content grows or the user moves away (>offset+100 pt, >2 s) — C# CheckNeedToLoadMore. Top arms only after the offset left the top edge, fires when it comes back. Not ported: opposite-direction cooldown (`IsOppositeLoadMoreBlocked`), `IInsideViewport.ShouldTriggerLoadMore`. |
68
68
  | Structure-preserving `ItemsSource` updates | ported (array diff) | C# listens to `ObservableCollection` Add/Insert; React apps replace the array, so the setter detects **append** (old is a prefix: measured heights kept, tail measured lazily) and **prepend** (old is a suffix: view indices shifted without rebinding, new head measured synchronously up to 200 items, `ItemsInsertedAtStart(px)` lets the `SkiaScroll` move its offset so visible rows stay put — C# head-insert rebase). and **reorder** (same items permuted, the C# `ObservableCollection.Move` case: contexts rebound, the index-keyed measured heights permuted with their items, nothing re-measured, extent and scroll offset unchanged). Any other change rebuilds the structure (heights re-measured, offset kept). Not ported: removals in place, `Replace`. |
@@ -72,7 +72,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
72
72
  | `SkiaLayout` Wrap (static children) + `SkiaWrap` alias | ported | Left-to-right flow, `Spacing` between items and rows, row height = tallest item. Not ported: `Split`, main-axis `Fill` children sharing a row (1.9.7.4 flex-fill), `UseDynamicColumns`, RTL. |
73
73
  | `SkiaLayout` Masonry + `SkiaMasonry` alias (Split 2, horizontal fill) | ported | C# `MeasureMasonry` / `BuildMasonryLayout`: `Split` columns of width round((width - (Split - 1) * Spacing) / Split), every visible item measured unbounded at that width and placed at the bottom of the shortest column (the first on a tie), `Spacing` between columns and items. Children or `ItemsSource` + `ItemTemplate` (recycled slots, taps, `ScrollToIndex` from the slot rect, `LoadMore`); a templated slot keeps its item's size, so an appended page or a changed item is the only one measured and every item is placed again. No items window. Content = used columns wide, tallest column high. `npm run check:masonry` (C# MasonryLayoutTests) |
74
74
  | `SkiaLayout` Grid (static children) + `SkiaGrid` alias | ported | Port of `SkiaGridStructure` (MAUI grid manager): `ColumnDefinitions`/`RowDefinitions` as `"*, 2*, Auto, 100"` or arrays, `DefaultColumnDefinition`/`DefaultRowDefinition` (Auto, like C#), `ColumnSpacing`/`RowSpacing`, child `Column`/`Row`/`ColumnSpan`/`RowSpan` (plain props instead of attached properties), implicit tracks, unknown/known measure passes, span resolution, star compression, Fill-child minimums, last-track stretch when the grid fills, remeasure at final cells. Not ported: `Split`/`Invert` (templated grids), `UseDynamicColumns`, `SkiaDecoratedGrid`, `GetOrderedSubviews` ZIndex ordering. |
75
- | `SkiaLabel` | partial | Word wrap (+ character break for long words), `MaxLines` with tail ellipsis, `LineBreakMode` (NoWrap / wraps / Tail; Head/Middle behave as Tail), `HorizontalTextAlignment` Start/Center/End, Start and End following each paragraph's direction (a right-to-left paragraph starts at the right; Fill* accepted, not stretched, placed at the paragraph's start), `VerticalTextAlignment`, `LineSpacing`, `LineHeight`, `FontWeight` + `FontAttributes` via faces registered per weight (`AddFont(src, alias, weight)`, nearest weight wins, synthetic bold (`setEmbolden`) when the nearest face is lighter than 600 — C# `Font.Embolden`; italic = synthetic skew when no italic face; empty `FontFamily` = the first registered family, weights included), `TextTransform`, `Padding`, `LinesCount`; text measured with unhinted (linear) advances, the same widths as DrawnUi.Rust on every platform; synthetic italic keeps its slant in every cache type (drawing room only, widths unchanged); defaults as C# (`FontSize` 12, `TextColor` GreenYellow). `FontFamilyFallback` ported and extended: comma-separated chain (`"FontSymbols,FontSymbols2"`), per-codepoint run segmentation, spaces always stay on the main font; `fonts.AddSymbols()` (`FontSymbols` = Noto Sans Math subset, `FontSymbols2` = Noto Sans Symbols 2 subset) and `fonts.AddEmojis()` (`FontEmoji` = Noto Color Emoji subset: faces, hands, skin tones and the demo emoji) ship the same subsets as DrawnUi.Blazor. A joiner, variation selector, skin tone, keycap or tag keeps the font of the glyph before it (C# JoinsPreviousGlyph). Text shaping where the text needs it (C# `UnicodeNeedsShaping` ranges plus Hebrew, Arabic supplements and emoji sequence characters): Arabic joins, Indic conjuncts and marks, emoji sequences as one glyph, through the CanvasKit paragraph module already in the build (HarfBuzz + ICU, no extra wasm); other text keeps the plain glyph-by-glyph path. Right-to-left lines: runs cut where the bidirectional level changes (ICU levels; the paragraph direction from its first strong letter, explicit embeddings reported as their direction only) and placed in visual order (rule L2). A space keeps the style of the span it was written in; where two spans meet with a space each, both stay (C#). `Spans` ported as `<TextSpan>` children: `Text`, `TextColor`/`FontSize`/`FontFamily` (unset = inherit from the label, like C# HasSetColor/HasSetSize/HasSetFont), `FontWeight`, `IsBold`, `IsItalic`, `Underline`/`UnderlineWidth`, `Strikeout`/`StrikeoutWidth`/`StrikeoutColor` (Red default), `BackgroundColor`, `Tapped` + `ForceCaptureInput` (hit-tested through per-fragment `Rects`, ripple on the label, `OnSpanTapped` overridable), mixed sizes on one line share a baseline. TextSpan not ported: `ParagraphColor`, `CommandTapped`, per-span `LineSpacing`/`LineHeight`, `AutoFindFont`, `DrawingOffset`. `CharacterSpacing` (C#: (value - 1) points after every glyph, measured, wrapped and cut at the drawn width), Chinese / Japanese line breaks between characters with kinsoku (C# FitAtBreak, `CanBreakInsideWord`). Text `StrokeColor`/`StrokeWidth`/`StrokeGradient`, `DropShadow*` and `GradientByLines` ported (C# DrawText order). Not ported: `AutoFont`, `AutoSize`/`AutoSizeText`, `MonoForDigits`, `KeepSpacesOnLineBreaks` (accepted, no effect), `Format`, hyphenation, |
75
+ | `SkiaLabel` | partial | Word wrap (+ character break for long words), `MaxLines` with tail ellipsis, `LineBreakMode` (NoWrap / wraps / Tail; Head/Middle behave as Tail), `HorizontalTextAlignment` Start/Center/End, Start and End following each paragraph's direction (a right-to-left paragraph starts at the right; Fill* accepted, not stretched, placed at the paragraph's start), `VerticalTextAlignment`, `LineSpacing`, `LineHeight`, `FontWeight` + `FontAttributes` via faces registered per weight (`AddFont(src, alias, weight)`, nearest weight wins, synthetic bold (`setEmbolden`) when the nearest face is lighter than 600 — C# `Font.Embolden`; italic = synthetic skew when no italic face; empty `FontFamily` = the first registered family, weights included), `TextTransform`, `Padding`, `LinesCount`; text measured with unhinted (linear) advances, the same widths as DrawnUi.Rust on every platform; ink past a line's ends (italic slant, a glyph's negative side bearing such as the hook of "j") is kept by every cache type (drawing room only, widths unchanged); defaults as C# (`FontSize` 12, `TextColor` GreenYellow). `FontFamilyFallback` ported and extended: comma-separated chain (`"FontSymbols,FontSymbols2"`), per-codepoint run segmentation, spaces always stay on the main font; `fonts.AddSymbols()` (`FontSymbols` = Noto Sans Math subset, `FontSymbols2` = Noto Sans Symbols 2 subset) and `fonts.AddEmojis()` (`FontEmoji` = Noto Color Emoji subset: faces, hands, skin tones and the demo emoji) ship the same subsets as DrawnUi.Blazor. A joiner, variation selector, skin tone, keycap or tag keeps the font of the glyph before it (C# JoinsPreviousGlyph). Text shaping where the text needs it (C# `UnicodeNeedsShaping` ranges plus Hebrew, Arabic supplements and emoji sequence characters): Arabic joins, Indic conjuncts and marks, emoji sequences as one glyph, through the CanvasKit paragraph module already in the build (HarfBuzz + ICU, no extra wasm); other text keeps the plain glyph-by-glyph path. Right-to-left lines: runs cut where the bidirectional level changes (ICU levels; the paragraph direction from its first strong letter, explicit embeddings reported as their direction only) and placed in visual order (rule L2). A space keeps the style of the span it was written in; where two spans meet with a space each, both stay (C#). `Spans` ported as `<TextSpan>` children: `Text`, `TextColor`/`FontSize`/`FontFamily` (unset = inherit from the label, like C# HasSetColor/HasSetSize/HasSetFont), `FontWeight`, `IsBold`, `IsItalic`, `Underline`/`UnderlineWidth`, `Strikeout`/`StrikeoutWidth`/`StrikeoutColor` (Red default), `BackgroundColor`, `Tapped` + `ForceCaptureInput` (hit-tested through per-fragment `Rects`, ripple on the label, `OnSpanTapped` overridable), mixed sizes on one line share a baseline. TextSpan not ported: `ParagraphColor`, `CommandTapped`, per-span `LineSpacing`/`LineHeight`, `AutoFindFont`, `DrawingOffset`. `CharacterSpacing` (C#: (value - 1) points after every glyph, measured, wrapped and cut at the drawn width), Chinese / Japanese line breaks between characters with kinsoku (C# FitAtBreak, `CanBreakInsideWord`). Text `StrokeColor`/`StrokeWidth`/`StrokeGradient`, `DropShadow*` and `GradientByLines` ported (C# DrawText order). Not ported: `AutoFont`, `AutoSize`/`AutoSizeText`, `MonoForDigits`, `KeepSpacesOnLineBreaks` (accepted, no effect), `Format`, hyphenation, |
76
76
  | `SkiaHotspot` | ported | Fill/Fill, `Tapped`, `Down`, `Up`, `LockPanning`, `TouchDown`; consumes only Tapped like the C# one. No `AnimationTapped`/ripple/shimmer. |
77
77
  | `SkiaButton` | partial | Default look only: rounded frame radius 8 (hardcoded like the C# default content), centered label, `Text`/`TextColor`/`FontSize`/`FontFamily`/`BackgroundColor`/`IsPressed`/`RespondsToGestures` (`IsDisabled` = its obsolete opposite)/`LockPanning`, `Tapped`/`Down`/`Up`. `RespondsToGestures = false`: no press, no `Tapped`/`Down`/`Up`, a press or tap on it stops there, keyboard skips it, reported disabled (drawnui-cross 6w). `IsPressed` is tracked but has no visual; press feedback = `ApplyEffect="Ripple"`. No `ButtonStyle` platform looks, icons, `TextCase`, elevation, shimmer, `BtnText`/`BtnShape` templating. |
78
78
  | `SkiaImage` | partial | Effects ported: `AddEffect` (BlackAndWhite/Grayscale, Pastel, Sepia, InvertColors, Tint + `ColorTint`/`EffectBlendMode`, Darken, Lighten, Contrast, Saturation, Brightness, TSL, Gamma ≈ linear fit — CanvasKit has no table color filter), `Blur` (image filter, mirror tile), `ZoomX/ZoomY`, `HorizontalOffset/VerticalOffset`; C# color matrices use 0..255 translations, CanvasKit 0..1 — converted. `HSL` (hue from `Gamma`, `Saturation`, `Brightness`, tint blend), `Custom` = your own `PaintColorFilter` (C# public fields `PaintColorFilter` / `PaintImageFilter`, the latter replaces `Blur`), `ImageBitmap` (decoded image shared, not owned), `LoadPriority` of the queued `Source` load. Not ported: `UseGradient`/`StartColor`/`EndColor`, sprites, `InflateAmount`, `EraseChangedContent`, `RescaleSource`/`RescalingQuality`. `Source` (URL), `Aspect` (all `TransformAspect` values; `Tile` is a no-op like C#, tiling is `SkiaImageTiles`, same `RescaleAspect` math), `HorizontalAlignment`/`VerticalAlignment`, `Success`/`Error`, `IsLoading`, `LoadedSource`, `DisplayRect`, `AspectScale`; overflow clipped to the box. Not ported: `LoadSourceOnFirstDraw`, `PreviewBase64`, `ImageBitmap`/`LoadedImageSource`, `RescaleSource`/`CacheRescaledSource`/`RescalingQuality`, all adjustments (`Brightness`…`Blur`, `ColorTint`, gradient, `Zoom*`, offsets), sprites, `DrawWhenEmpty`, `EraseChangedContent`, `UseAssembly`. Measure: bounded box taken as is, unbounded axis from source aspect; no `NeedAutoWidth/Height` from Start alignment. |
@@ -170,6 +170,15 @@ export declare class SkiaLabel extends SkiaControl {
170
170
  * and MaxLines, the last kept one ending with a tail ellipsis (C# / DrawnUi.Rust: a label in a box too short for its
171
171
  * text cuts it, not only MaxLines).
172
172
  */
173
+ /** The last layout broke a line because the text did not fit: its max-content is wider than the constraint. */
174
+ private wrapped;
175
+ /** The last layout cut lines (MaxLines, height, an ellipsis): its lines depend on the room it had. */
176
+ private truncated;
177
+ /**
178
+ * Lines laid out without wrapping or cutting stay the same for any room that holds them: reused, while nothing in the
179
+ * label changed (NeedMeasure), for a later measure with at least that width and height (C# 5f24f577 label line reuse).
180
+ */
181
+ private reusable?;
173
182
  private LayoutLines;
174
183
  /** A paragraph is right to left when its first strong letter is (DrawnUi.Rust split_bidi). */
175
184
  static FirstStrongIsRtl(text: string): boolean;
@@ -191,13 +200,16 @@ export declare class SkiaLabel extends SkiaControl {
191
200
  /** ParagraphSpacing above a line that starts a paragraph (after the first): that many of its lines, with their spacing. */
192
201
  private ParagraphSpace;
193
202
  private BlockHeight;
194
- /** Skew of synthetic italic (Super.GetFont setSkewX -0.25): x moves by 0.25 per pixel above the baseline. */
195
- private static readonly ItalicSkew;
196
- /** Pixels synthetic italic glyphs reach past the line box: right at the ascent, left at the descent. */
197
- private slantRight;
198
- private slantLeft;
199
- /** The slant of synthetic italic is drawn outside the label's box: caches record that room too (C# / DrawnUi.Rust draw it whole). */
203
+ /** Pixels of ink outside the lines' advance boxes, at their left and right ends (side bearings, italic slant). */
204
+ private inkLeft;
205
+ private inkRight;
206
+ /** Ink drawn outside the label's box (a "j" hook, an italic slant) is recorded by caches too, as C# draws it whole. */
200
207
  ComputeEffectsMargin(scale: number): Thickness;
208
+ /**
209
+ * C# (after 106e768a): the ink bounds of the first glyph of each line's leftmost run and the last glyph of its
210
+ * rightmost run, beyond the advance box of that run. Two glyph bounds per line, at measure.
211
+ */
212
+ private MeasureInkOverhang;
201
213
  /**
202
214
  * Where a line starts inside [left, right] (drawnui-cross 6am): Start and End follow the paragraph's direction (in a
203
215
  * right-to-left paragraph Start is the right edge); Center is centered; Fill* lines are not stretched here and sit
@@ -138,7 +138,7 @@ export class SkiaLabel extends SkiaControl {
138
138
  const main = Super.GetFont(family, weight, italic, sizePx);
139
139
  const m = main.getMetrics();
140
140
  f = {
141
- Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent, Italic: italic,
141
+ Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent,
142
142
  Fallbacks: this.fontFamilyFallback
143
143
  ? this.fontFamilyFallback.split(",").map((a) => a.trim()).filter(Boolean).map((a) => Super.GetFont(a, weight, italic, sizePx))
144
144
  : [],
@@ -382,7 +382,18 @@ export class SkiaLabel extends SkiaControl {
382
382
  * and MaxLines, the last kept one ending with a tail ellipsis (C# / DrawnUi.Rust: a label in a box too short for its
383
383
  * text cuts it, not only MaxLines).
384
384
  */
385
+ /** The last layout broke a line because the text did not fit: its max-content is wider than the constraint. */
386
+ wrapped = false;
387
+ /** The last layout cut lines (MaxLines, height, an ellipsis): its lines depend on the room it had. */
388
+ truncated = false;
389
+ /**
390
+ * Lines laid out without wrapping or cutting stay the same for any room that holds them: reused, while nothing in the
391
+ * label changed (NeedMeasure), for a later measure with at least that width and height (C# 5f24f577 label line reuse).
392
+ */
393
+ reusable;
385
394
  LayoutLines(maxWidth, scale, maxHeight = Infinity) {
395
+ this.wrapped = false;
396
+ this.truncated = false;
386
397
  const wrap = this.lineBreakMode !== "NoWrap" && isFinite(maxWidth);
387
398
  // run widths carry the gap after every glyph; the one after a line's last glyph is not drawn
388
399
  const sp = this.glyphSpacing;
@@ -423,11 +434,13 @@ export class SkiaLabel extends SkiaControl {
423
434
  out.push(line);
424
435
  line = this.NewLine();
425
436
  word = rest;
437
+ this.wrapped = true;
426
438
  continue;
427
439
  }
428
440
  if (line.Runs.length > 0) {
429
441
  out.push(line);
430
442
  line = this.NewLine();
443
+ this.wrapped = true;
431
444
  continue;
432
445
  }
433
446
  // word longer than the line: break by code points
@@ -438,6 +451,7 @@ export class SkiaLabel extends SkiaControl {
438
451
  if (line.Runs.length > 0 && line.Width + chW - sp > maxWidth) {
439
452
  out.push(line);
440
453
  line = this.NewLine();
454
+ this.wrapped = true;
441
455
  }
442
456
  this.Append(line, run);
443
457
  }
@@ -462,6 +476,7 @@ export class SkiaLabel extends SkiaControl {
462
476
  kept = Math.min(kept, fit);
463
477
  }
464
478
  if (kept < out.length) {
479
+ this.truncated = true;
465
480
  out.length = kept;
466
481
  const truncates = this.lineBreakMode === "TailTruncation" || this.lineBreakMode === "HeadTruncation" || this.lineBreakMode === "MiddleTruncation";
467
482
  if (truncates) {
@@ -606,17 +621,50 @@ export class SkiaLabel extends SkiaControl {
606
621
  }
607
622
  return h;
608
623
  }
609
- /** Skew of synthetic italic (Super.GetFont setSkewX -0.25): x moves by 0.25 per pixel above the baseline. */
610
- static ItalicSkew = 0.25;
611
- /** Pixels synthetic italic glyphs reach past the line box: right at the ascent, left at the descent. */
612
- slantRight = 0;
613
- slantLeft = 0;
614
- /** The slant of synthetic italic is drawn outside the label's box: caches record that room too (C# / DrawnUi.Rust draw it whole). */
624
+ /** Pixels of ink outside the lines' advance boxes, at their left and right ends (side bearings, italic slant). */
625
+ inkLeft = 0;
626
+ inkRight = 0;
627
+ /** Ink drawn outside the label's box (a "j" hook, an italic slant) is recorded by caches too, as C# draws it whole. */
615
628
  ComputeEffectsMargin(scale) {
616
629
  const m = super.ComputeEffectsMargin(scale);
617
- if (this.slantRight === 0 && this.slantLeft === 0)
630
+ if (this.inkRight === 0 && this.inkLeft === 0)
618
631
  return m;
619
- return new Thickness(m.Left + this.slantLeft, m.Top, m.Right + this.slantRight, m.Bottom);
632
+ return new Thickness(m.Left + this.inkLeft, m.Top, m.Right + this.inkRight, m.Bottom);
633
+ }
634
+ /**
635
+ * C# (after 106e768a): the ink bounds of the first glyph of each line's leftmost run and the last glyph of its
636
+ * rightmost run, beyond the advance box of that run. Two glyph bounds per line, at measure.
637
+ */
638
+ MeasureInkOverhang() {
639
+ const sp = this.glyphSpacing;
640
+ let left = 0, right = 0;
641
+ for (const line of this.lines) {
642
+ const runs = line.Runs.filter((r) => r.Text.trim().length > 0);
643
+ if (runs.length === 0)
644
+ continue;
645
+ const first = runs.reduce((a, b) => ((b.X ?? 0) < (a.X ?? 0) ? b : a)), last = runs.reduce((a, b) => ((b.X ?? 0) >= (a.X ?? 0) ? b : a));
646
+ const firstX = first.X ?? 0, lastEnd = (last.X ?? line.Width) + (last.X === undefined ? 0 : last.Width - sp);
647
+ // ink x of a run's visually first / last glyph, from the line start
648
+ const ends = (r, x0) => {
649
+ if (r.Shaped) {
650
+ const g = r.Shaped.Glyphs, n = g.length;
651
+ if (n === 0)
652
+ return [x0, x0];
653
+ const b = r.Font.getGlyphBounds([g[0], g[n - 1]]);
654
+ return [x0 + r.Shaped.Positions[0] + b[0], x0 + r.Shaped.Positions[(n - 1) * 2] + b[6]];
655
+ }
656
+ const ids = r.Font.getGlyphIDs(r.Text);
657
+ const n = ids.length;
658
+ const b = r.Font.getGlyphBounds([ids[0], ids[n - 1]]);
659
+ const lastAdvance = r.Font.getGlyphWidths([ids[n - 1]])[0];
660
+ return [x0 + b[0], x0 + r.Width - sp - lastAdvance + b[6]];
661
+ };
662
+ // a line without placed runs (no bidi): its runs follow each other from x 0, the last ends at the line width
663
+ const lastX0 = last.X ?? (line.Width - (last.Width - sp));
664
+ left = Math.max(left, firstX - ends(first, firstX)[0]);
665
+ right = Math.max(right, ends(last, lastX0)[1] - (last.X === undefined ? line.Width : lastEnd));
666
+ }
667
+ return [Math.max(0, left), Math.max(0, right)];
620
668
  }
621
669
  /**
622
670
  * Where a line starts inside [left, right] (drawnui-cross 6am): Start and End follow the paragraph's direction (in a
@@ -639,27 +687,33 @@ export class SkiaLabel extends SkiaControl {
639
687
  }
640
688
  const px = this.padding.HorizontalThickness * scale, py = this.padding.VerticalThickness * scale;
641
689
  const extraH = this.EffectsExtra(scale).H;
642
- this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(widthConstraint - px, scale, heightConstraint - py - extraH) : [];
643
- this.ShapeLines(this.lines);
644
- // synthetic italic leans its glyphs past their advances: drawing room for caches, widths unchanged (DrawnUi.Rust label.rs)
645
- let slantRight = 0, slantLeft = 0;
646
- for (const l of this.lines)
647
- for (const r of l.Runs)
648
- if (r.Fonts.Italic && r.Text.trim()) {
649
- slantRight = Math.max(slantRight, SkiaLabel.ItalicSkew * r.Fonts.Ascent);
650
- slantLeft = Math.max(slantLeft, SkiaLabel.ItalicSkew * r.Fonts.Descent);
651
- }
652
- if (slantRight !== this.slantRight || slantLeft !== this.slantLeft) {
653
- this.slantRight = slantRight;
654
- this.slantLeft = slantLeft;
655
- this.InvalidateEffectsMargin();
690
+ const roomW = widthConstraint - px, roomH = heightConstraint - py - extraH;
691
+ const r = this.reusable;
692
+ if (this.NeedMeasure || !r || r.Scale !== scale || r.Spacing !== glyphSpacing || roomW < r.Width - 0.01 || roomH < r.Height - 0.01) {
693
+ this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(roomW, scale, roomH) : [];
694
+ this.ShapeLines(this.lines);
695
+ // ink past the lines' ends (a "j" hook, an italic slant) is drawing room for caches; widths unchanged
696
+ const [inkLeft, inkRight] = this.MeasureInkOverhang();
697
+ if (inkLeft !== this.inkLeft || inkRight !== this.inkRight) {
698
+ this.inkLeft = inkLeft;
699
+ this.inkRight = inkRight;
700
+ this.InvalidateEffectsMargin();
701
+ }
702
+ let widest = 0;
703
+ for (const l of this.lines)
704
+ widest = Math.max(widest, l.Width);
705
+ this.reusable = this.wrapped || this.truncated ? undefined : { Scale: scale, Spacing: glyphSpacing, Width: widest, Height: this.BlockHeight() };
656
706
  }
657
707
  let width = 0;
658
708
  for (const l of this.lines)
659
709
  width = Math.max(width, l.Width);
660
710
  const extra = this.EffectsExtra(scale);
661
711
  this.LayoutVersion++;
662
- return ScaledSize.FromPixels(Math.ceil(width + extra.W) + px, Math.ceil(this.BlockHeight() + extra.H) + py, scale);
712
+ const size = ScaledSize.FromPixels(Math.ceil(width + extra.W) + px, Math.ceil(this.BlockHeight() + extra.H) + py, scale);
713
+ // fit-content (drawnui-cross 6an): text that had to wrap needs the whole width it was given (min of max-content and it)
714
+ if (this.wrapped && isFinite(widthConstraint))
715
+ this.fitContentPixels = { Width: widthConstraint, Height: size.Pixels.Height };
716
+ return size;
663
717
  }
664
718
  /** C# GradientByLines: FillGradient spans each line's bounds (default) instead of the whole text block. */
665
719
  GradientByLines = true;
@@ -26,6 +26,8 @@ class TemplatedSlot {
26
26
  MinimumWidthRequest = -1;
27
27
  MinimumHeightRequest = -1;
28
28
  MeasuredSize = ScaledSize.Default;
29
+ /** The view's fit-content size from the same measure (SkiaControl.FitPixels). */
30
+ FitPixels = { Width: 0, Height: 0 };
29
31
  WidthConstraint = Infinity;
30
32
  HeightConstraint = Infinity;
31
33
  /** The rect the layout arranged this slot in (pixels). */
@@ -45,9 +47,12 @@ class TemplatedSlot {
45
47
  && Object.is(widthConstraint, this.WidthConstraint) && Object.is(heightConstraint, this.HeightConstraint))
46
48
  return this.MeasuredSize;
47
49
  const view = shown ?? this.factory.GetOrCreateViewForIndex(this.Index, true);
48
- if (!view)
50
+ if (!view) {
51
+ this.FitPixels = { Width: 0, Height: 0 };
49
52
  return (this.MeasuredSize = ScaledSize.Default);
53
+ }
50
54
  this.MeasuredSize = view.Measure(widthConstraint, heightConstraint, scale);
55
+ this.FitPixels = view.FitPixels;
51
56
  this.measuredItem = item;
52
57
  this.measuredScale = scale;
53
58
  this.WidthConstraint = widthConstraint;
@@ -497,6 +502,9 @@ export class SkiaLayout extends SkiaControl {
497
502
  const s = this.MeasureGrid(w, h, scale);
498
503
  return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
499
504
  }
505
+ // fit-content of the children on the cross axis (Fill children included, drawnui-cross 6an)
506
+ let fitW = 0, fitH = 0;
507
+ const visible = [];
500
508
  for (const v of this.LayoutViews()) {
501
509
  if (!v.IsVisible)
502
510
  continue;
@@ -516,13 +524,42 @@ export class SkiaLayout extends SkiaControl {
516
524
  cw = Math.max(cw, s.Pixels.Width);
517
525
  ch = Math.max(ch, s.Pixels.Height);
518
526
  }
527
+ fitW = Math.max(fitW, v.FitPixels.Width);
528
+ fitH = Math.max(fitH, v.FitPixels.Height);
529
+ visible.push(v);
519
530
  n++;
520
531
  }
532
+ // a stack that sizes itself on its cross axis (no request, not Fill, or Fill on an unbounded axis) is as wide / tall
533
+ // as its widest / tallest child needs; its Fill children are measured again at that size, so their wrapped heights /
534
+ // widths are the drawn ones
535
+ if (this.Type === "Column" && (this.HorizontalOptions !== "Fill" || !isFinite(w)) && this.WidthRequest < 0 && this.LockRatio === 0) {
536
+ const size = isFinite(w) ? Math.min(fitW, w) : fitW;
537
+ if (size !== cw) {
538
+ cw = size;
539
+ ch = 0;
540
+ for (const v of visible)
541
+ ch += (v.HorizontalOptions === "Fill" && v.WidthRequest < 0 ? v.Measure(size, Infinity, scale) : v.MeasuredSize).Pixels.Height;
542
+ }
543
+ }
544
+ else if (this.Type === "Row" && (this.VerticalOptions !== "Fill" || !isFinite(h)) && this.HeightRequest < 0 && this.LockRatio === 0) {
545
+ const size = isFinite(h) ? Math.min(fitH, h) : fitH;
546
+ if (size !== ch) {
547
+ ch = size;
548
+ cw = 0;
549
+ for (const v of visible)
550
+ cw += (v.VerticalOptions === "Fill" && v.HeightRequest < 0 ? v.Measure(Infinity, size, scale) : v.MeasuredSize).Pixels.Width;
551
+ }
552
+ }
521
553
  const gaps = Math.max(0, n - 1) * gap;
522
554
  if (this.Type === "Column")
523
555
  ch += gaps;
524
556
  if (this.Type === "Row")
525
557
  cw += gaps;
558
+ // what this layout's own content needs, for a stack around it (a Fill layout still returns the whole constraint)
559
+ this.fitContentPixels = {
560
+ Width: (this.Type === "Row" ? cw : Math.min(cw, fitW)) + px,
561
+ Height: (this.Type === "Column" ? ch : Math.min(ch, fitH)) + py,
562
+ };
526
563
  return ScaledSize.FromPixels(cw + px, ch + py, scale);
527
564
  }
528
565
  /** Wrap rows computed by the last measure: [childIndex, x, y, w, h] in pixels relative to the padded box. */
@@ -311,6 +311,20 @@ export declare class SkiaControl {
311
311
  _superview?: Canvas;
312
312
  get Superview(): Canvas | undefined;
313
313
  MeasuredSize: ScaledSize;
314
+ /**
315
+ * The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
316
+ * axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
317
+ * stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
318
+ */
319
+ FitPixels: {
320
+ Width: number;
321
+ Height: number;
322
+ };
323
+ /** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
324
+ protected fitContentPixels?: {
325
+ Width: number;
326
+ Height: number;
327
+ };
314
328
  DrawingRect: SKRect;
315
329
  RenderingScale: number;
316
330
  NeedMeasure: boolean;
@@ -444,6 +444,14 @@ export class SkiaControl {
444
444
  }
445
445
  // ---- state (pixels) ----
446
446
  MeasuredSize = ScaledSize.Default;
447
+ /**
448
+ * The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
449
+ * axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
450
+ * stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
451
+ */
452
+ FitPixels = { Width: 0, Height: 0 };
453
+ /** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
454
+ fitContentPixels;
447
455
  DrawingRect = SKRect.Empty;
448
456
  RenderingScale = 1;
449
457
  NeedMeasure = true;
@@ -492,6 +500,7 @@ export class SkiaControl {
492
500
  locked = true;
493
501
  }
494
502
  }
503
+ this.fitContentPixels = undefined;
495
504
  const content = this.MeasureAbsolute(w, h, scale);
496
505
  let rw = locked || reqW >= 0 ? w : this.HorizontalOptions === "Fill" && isFinite(w) ? w : content.Pixels.Width;
497
506
  let rh = locked || reqH >= 0 ? h : this.VerticalOptions === "Fill" && isFinite(h) ? h : content.Pixels.Height;
@@ -504,6 +513,19 @@ export class SkiaControl {
504
513
  if (this.MaximumHeightRequest >= 0 && reqH < 0)
505
514
  rh = Math.min(rh, this.MaximumHeightRequest * scale);
506
515
  this.MeasuredSize = ScaledSize.FromPixels(rw + mx, rh + my, scale);
516
+ // fit-content: what the content needs (never more than the constraint), with the requests and min / max
517
+ const fit = this.fitContentPixels ?? { Width: content.Pixels.Width, Height: content.Pixels.Height };
518
+ let fw = locked || reqW >= 0 ? w : Math.min(fit.Width, isFinite(w) ? w : fit.Width);
519
+ let fh = locked || reqH >= 0 ? h : Math.min(fit.Height, isFinite(h) ? h : fit.Height);
520
+ if (this.MinimumWidthRequest >= 0)
521
+ fw = Math.max(fw, this.MinimumWidthRequest * scale);
522
+ if (this.MinimumHeightRequest >= 0)
523
+ fh = Math.max(fh, this.MinimumHeightRequest * scale);
524
+ if (this.MaximumWidthRequest >= 0 && reqW < 0)
525
+ fw = Math.min(fw, this.MaximumWidthRequest * scale);
526
+ if (this.MaximumHeightRequest >= 0 && reqH < 0)
527
+ fh = Math.min(fh, this.MaximumHeightRequest * scale);
528
+ this.FitPixels = { Width: fw + mx, Height: fh + my };
507
529
  this.NeedMeasure = false;
508
530
  return this.MeasuredSize;
509
531
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.32",
3
+ "version": "0.1.0-preview.34",
4
4
  "description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Kovalsky (AppoMobi)",
@@ -88,6 +88,9 @@
88
88
  "check:shaping": "node dev/check.mjs dev/check-shaping.ts",
89
89
  "check:editor-rtl": "node dev/check.mjs dev/check-editor-rtl.ts",
90
90
  "check:label-direction": "node dev/check.mjs dev/check-label-direction.ts",
91
+ "check:stack-fit": "node dev/check.mjs dev/check-stack-fit.ts",
92
+ "check:label-reuse": "node dev/check.mjs dev/check-label-reuse.ts",
93
+ "bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
91
94
  "site:extras": "node dev/site-extras.mjs dist/demo",
92
95
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
93
96
  "prepublishOnly": "npm run build:lib",