drawnui-react 0.1.0-preview.25 → 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.
|
@@ -165,6 +165,14 @@ export declare class SkiaLayout extends SkiaControl {
|
|
|
165
165
|
* its slot, also while no view shows it (ScrollToIndex to an item off screen); undefined otherwise.
|
|
166
166
|
*/
|
|
167
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
|
+
}[];
|
|
168
176
|
/** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
|
|
169
177
|
GetMasonryItemRect(index: number): SKRect | undefined;
|
|
170
178
|
/** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
|
|
@@ -622,6 +622,19 @@ export class SkiaLayout extends SkiaControl {
|
|
|
622
622
|
const d = this.slots?.[index]?.Destination;
|
|
623
623
|
return d && d.Width > 0 ? d : undefined;
|
|
624
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
|
+
}
|
|
625
638
|
/** Masonry: where the slot of item `index` was arranged (pixels); see GetItemRect. */
|
|
626
639
|
GetMasonryItemRect(index) { return this.IsMasonry ? this.GetItemRect(index) : undefined; }
|
|
627
640
|
/** Port of C# MeasureGrid: build the structure in points, stretch the last track when the grid fills, remeasure at final cells. */
|
|
@@ -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
|
-
|
|
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.
|
|
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)",
|
|
@@ -82,6 +82,7 @@
|
|
|
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
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",
|
|
85
86
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|
|
86
87
|
"build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
87
88
|
"prepublishOnly": "npm run build:lib",
|