drawnui-react 0.1.0-preview.24 → 0.1.0-preview.26

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.
@@ -160,7 +160,20 @@ export declare class SkiaLayout extends SkiaControl {
160
160
  * one measured, and every item is placed again from the sizes known.
161
161
  */
162
162
  private MeasureMasonry;
163
- /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
163
+ /**
164
+ * Where item `index` of a recycled templated Row / Wrap / Grid / split Column / Masonry was arranged (pixels), from
165
+ * its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
166
+ */
167
+ GetItemRect(index: number): SKRect | undefined;
168
+ /**
169
+ * Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
170
+ * columns have uneven heights and the item `Split` places later is rarely under the focused one.
171
+ */
172
+ GetMasonryPlacement(): {
173
+ Index: number;
174
+ Rect: SKRect;
175
+ }[];
176
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
164
177
  GetMasonryItemRect(index: number): SKRect | undefined;
165
178
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
166
179
  private MeasureGrid;
@@ -612,13 +612,31 @@ export class SkiaLayout extends SkiaControl {
612
612
  const used = Math.min(columns, this.wrapSlots.length);
613
613
  return { w: used > 0 ? used * columnWidth + (used - 1) * spacing : 0, h: Math.max(0, ...bottoms) };
614
614
  }
615
- /** Masonry: where the slot of item `index` was arranged (pixels), also while no view shows it; undefined otherwise. */
616
- GetMasonryItemRect(index) {
617
- if (!this.IsMasonry || !this.IsRecycledLayout)
615
+ /**
616
+ * Where item `index` of a recycled templated Row / Wrap / Grid / split Column / Masonry was arranged (pixels), from
617
+ * its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
618
+ */
619
+ GetItemRect(index) {
620
+ if (!this.IsRecycledLayout)
618
621
  return undefined;
619
622
  const d = this.slots?.[index]?.Destination;
620
623
  return d && d.Width > 0 ? d : undefined;
621
624
  }
625
+ /**
626
+ * Masonry: every placed item with its rect (pixels), in item order: what keyboard navigation follows, since the
627
+ * columns have uneven heights and the item `Split` places later is rarely under the focused one.
628
+ */
629
+ GetMasonryPlacement() {
630
+ if (!this.IsMasonry)
631
+ return [];
632
+ const r = this.DrawingRect, p = this.Padding, s = this.RenderingScale, left = r.Left + p.Left * s, top = r.Top + p.Top * s;
633
+ return this.wrapSlots.map((w) => ({
634
+ Index: w.view instanceof TemplatedSlot ? w.view.Index : this.IsTemplated ? w.view.ContextIndex : this.views.indexOf(w.view),
635
+ Rect: SKRect.Create(left + w.x, top + w.y, w.w, w.h),
636
+ }));
637
+ }
638
+ /** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
639
+ GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
622
640
  /** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
623
641
  MeasureGrid(widthPx, heightPx, scale) {
624
642
  const wPts = widthPx / scale, hPts = heightPx / scale;
@@ -781,7 +799,7 @@ export class SkiaLayout extends SkiaControl {
781
799
  * The item's offset and height are real, not estimated (C# LastMeasuredIndexLocal >= index): MeasureVisible knows
782
800
  * them once the measured prefix passed the item; the other strategies always do.
783
801
  */
784
- IsItemMeasured(index) { return this.IsMasonry || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
802
+ IsItemMeasured(index) { return !this.IsTemplatedList || this.MeasureItemsStrategy !== "MeasureVisible" || index < this.mvMeasured; }
785
803
  /** Pixel offset of item index from the top of the layout content (inside padding). */
786
804
  GetItemOffsetPixels(index) {
787
805
  const scale = this.RenderingScale;
@@ -871,8 +871,8 @@ export class SkiaScroll extends SkiaControl {
871
871
  else {
872
872
  // A templated Row / Wrap / Grid realizes every item (C# non-list layouts are not virtualized): read the cell's
873
873
  // arranged rect, like C# reads the structure cell's Destination.
874
- // a masonry's recycled slots know every item's place, shown or not
875
- const r = layout.GetMasonryItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
874
+ // recycled slots know every item's place, shown or not
875
+ const r = layout.GetItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
876
876
  if (!r)
877
877
  return undefined;
878
878
  const c = this.content.DrawingRect;
@@ -167,7 +167,12 @@ export class SkiaAccessibilityManager {
167
167
  const vertical = axis !== "Horizontal";
168
168
  const page = () => PageSize(scroll, item, vertical) * row;
169
169
  let target, step;
170
- if ((key === "ArrowDown" && axis === "Vertical") || (key === "ArrowRight" && axis !== "Vertical")) {
170
+ const layout = asLayout(group), masonry = layout?.Type === "Masonry" ? MasonryTarget(layout, current, key, scroll) : undefined;
171
+ if (masonry !== undefined) {
172
+ target = masonry;
173
+ step = key === "ArrowDown" || key === "ArrowRight" || key === "PageDown" ? 1 : -1;
174
+ }
175
+ else if ((key === "ArrowDown" && axis === "Vertical") || (key === "ArrowRight" && axis !== "Vertical")) {
171
176
  target = current + 1;
172
177
  step = 1;
173
178
  }
@@ -479,6 +484,57 @@ function IsDrawn(control) {
479
484
  return !!control.Superview && r.Width > 0 && r.Height > 0;
480
485
  }
481
486
  /** Items per viewport of the scroll around the group. */
487
+ /**
488
+ * C# MasonryTarget (2ad608d1): the target of an arrow or page key in a Masonry group, from the placed items. Up / Down go
489
+ * to the previous / next item of the same column, Left / Right to the item of the neighbour column nearest in height,
490
+ * PageUp / PageDown up to one viewport along the column (else the next / previous item of the column). `current` when
491
+ * there is no item that way; undefined for other keys or no placement (the generic rules apply).
492
+ */
493
+ function MasonryTarget(layout, current, key, scroll) {
494
+ if (key !== "ArrowDown" && key !== "ArrowUp" && key !== "ArrowLeft" && key !== "ArrowRight" && key !== "PageDown" && key !== "PageUp")
495
+ return undefined;
496
+ const cells = layout.GetMasonryPlacement?.() ?? [];
497
+ const focused = cells.find((c) => c.Index === current);
498
+ if (!focused)
499
+ return undefined;
500
+ const lefts = [...new Set(cells.map((c) => Math.round(c.Rect.Left)))].sort((a, b) => a - b);
501
+ const columnOf = (c) => lefts.indexOf(Math.round(c.Rect.Left));
502
+ const col = columnOf(focused), top = focused.Rect.Top, mid = (focused.Rect.Top + focused.Rect.Bottom) / 2;
503
+ const column = cells.filter((c) => columnOf(c) === col).sort((a, b) => a.Rect.Top - b.Rect.Top);
504
+ const below = column.filter((c) => c.Rect.Top > top), above = column.filter((c) => c.Rect.Top < top);
505
+ const viewport = scroll ? scroll.DrawingRect.Height : 0;
506
+ let found;
507
+ if (key === "ArrowDown")
508
+ found = below[0];
509
+ else if (key === "ArrowUp")
510
+ found = above[above.length - 1];
511
+ else if (key === "ArrowRight" || key === "ArrowLeft") {
512
+ const next = col + (key === "ArrowRight" ? 1 : -1);
513
+ let best = Infinity;
514
+ for (const c of cells) {
515
+ if (columnOf(c) !== next)
516
+ continue;
517
+ const d = Math.abs((c.Rect.Top + c.Rect.Bottom) / 2 - mid);
518
+ if (d < best) {
519
+ best = d;
520
+ found = c;
521
+ }
522
+ }
523
+ }
524
+ else {
525
+ if (!scroll)
526
+ return undefined;
527
+ if (key === "PageDown") {
528
+ const within = below.filter((c) => c.Rect.Top <= top + viewport);
529
+ found = within[within.length - 1] ?? below[0];
530
+ }
531
+ else {
532
+ const within = above.filter((c) => c.Rect.Top >= top - viewport);
533
+ found = within[0] ?? above[above.length - 1];
534
+ }
535
+ }
536
+ return found?.Index ?? current;
537
+ }
482
538
  function PageSize(scroll, item, vertical) {
483
539
  const v = scroll.DrawingRect, size = item.MeasuredSize.Pixels;
484
540
  const viewport = vertical ? v.Height : v.Width, s = vertical ? size.Height : size.Width;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drawnui-react",
3
- "version": "0.1.0-preview.24",
3
+ "version": "0.1.0-preview.26",
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)",
@@ -81,6 +81,8 @@
81
81
  "check:backdrop": "node dev/check.mjs dev/check-backdrop.ts",
82
82
  "check:masonry": "node dev/check.mjs dev/check-masonry.ts",
83
83
  "check:thickness": "node dev/check.mjs dev/check-thickness.ts",
84
+ "check:scroll-recycled": "node dev/check.mjs dev/check-scroll-recycled.ts",
85
+ "check:masonry-keys": "node dev/check.mjs dev/check-masonry-keys.ts",
84
86
  "site:extras": "node dev/site-extras.mjs dist/demo",
85
87
  "build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
86
88
  "prepublishOnly": "npm run build:lib",