drawnui-react 0.1.0-preview.33 → 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`. |
@@ -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;
@@ -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) {
@@ -672,21 +687,33 @@ export class SkiaLabel extends SkiaControl {
672
687
  }
673
688
  const px = this.padding.HorizontalThickness * scale, py = this.padding.VerticalThickness * scale;
674
689
  const extraH = this.EffectsExtra(scale).H;
675
- this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(widthConstraint - px, scale, heightConstraint - py - extraH) : [];
676
- this.ShapeLines(this.lines);
677
- // ink past the lines' ends (a "j" hook, an italic slant) is drawing room for caches; widths unchanged
678
- const [inkLeft, inkRight] = this.MeasureInkOverhang();
679
- if (inkLeft !== this.inkLeft || inkRight !== this.inkRight) {
680
- this.inkLeft = inkLeft;
681
- this.inkRight = inkRight;
682
- 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() };
683
706
  }
684
707
  let width = 0;
685
708
  for (const l of this.lines)
686
709
  width = Math.max(width, l.Width);
687
710
  const extra = this.EffectsExtra(scale);
688
711
  this.LayoutVersion++;
689
- 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;
690
717
  }
691
718
  /** C# GradientByLines: FillGradient spans each line's bounds (default) instead of the whole text block. */
692
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.33",
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",