drawnui-react 0.1.0-preview.4 → 0.1.0-preview.40

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.
Files changed (105) hide show
  1. package/README.md +119 -14
  2. package/SKIPPED.md +36 -26
  3. package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
  4. package/dist/controls/AnimatedFramesRenderer.js +18 -1
  5. package/dist/controls/DrawnGame.d.ts +44 -0
  6. package/dist/controls/DrawnGame.js +82 -0
  7. package/dist/controls/GridStructure.d.ts +16 -2
  8. package/dist/controls/GridStructure.js +40 -4
  9. package/dist/controls/SkiaBackdrop.d.ts +8 -2
  10. package/dist/controls/SkiaBackdrop.js +42 -14
  11. package/dist/controls/SkiaButton.d.ts +17 -3
  12. package/dist/controls/SkiaButton.js +26 -8
  13. package/dist/controls/SkiaCarousel.d.ts +22 -3
  14. package/dist/controls/SkiaCarousel.js +85 -9
  15. package/dist/controls/SkiaCheckbox.d.ts +0 -1
  16. package/dist/controls/SkiaCheckbox.js +2 -7
  17. package/dist/controls/SkiaDrawer.d.ts +15 -0
  18. package/dist/controls/SkiaDrawer.js +42 -7
  19. package/dist/controls/SkiaEditor.d.ts +48 -2
  20. package/dist/controls/SkiaEditor.js +268 -53
  21. package/dist/controls/SkiaGif.d.ts +7 -0
  22. package/dist/controls/SkiaGif.js +25 -4
  23. package/dist/controls/SkiaImage.d.ts +5 -0
  24. package/dist/controls/SkiaImage.js +48 -14
  25. package/dist/controls/SkiaLabel.d.ts +117 -9
  26. package/dist/controls/SkiaLabel.js +526 -80
  27. package/dist/controls/SkiaLabelFps.d.ts +16 -0
  28. package/dist/controls/SkiaLabelFps.js +41 -0
  29. package/dist/controls/SkiaLayout.d.ts +89 -9
  30. package/dist/controls/SkiaLayout.js +364 -21
  31. package/dist/controls/SkiaLottie.js +5 -3
  32. package/dist/controls/SkiaProgress.d.ts +2 -1
  33. package/dist/controls/SkiaProgress.js +8 -5
  34. package/dist/controls/SkiaRadioButton.d.ts +2 -0
  35. package/dist/controls/SkiaRadioButton.js +16 -4
  36. package/dist/controls/SkiaRichLabel.d.ts +1 -1
  37. package/dist/controls/SkiaRichLabel.js +11 -1
  38. package/dist/controls/SkiaScroll.d.ts +35 -5
  39. package/dist/controls/SkiaScroll.js +252 -32
  40. package/dist/controls/SkiaScrollBar.d.ts +27 -0
  41. package/dist/controls/SkiaScrollBar.js +51 -2
  42. package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
  43. package/dist/controls/SkiaShaderCarousel.js +27 -5
  44. package/dist/controls/SkiaShape.d.ts +13 -2
  45. package/dist/controls/SkiaShape.js +50 -10
  46. package/dist/controls/SkiaSlider.d.ts +20 -2
  47. package/dist/controls/SkiaSlider.js +61 -7
  48. package/dist/controls/SkiaSprite.d.ts +4 -0
  49. package/dist/controls/SkiaSprite.js +22 -10
  50. package/dist/controls/SkiaSvg.d.ts +4 -0
  51. package/dist/controls/SkiaSvg.js +28 -4
  52. package/dist/controls/SkiaSwitch.d.ts +0 -1
  53. package/dist/controls/SkiaSwitch.js +4 -8
  54. package/dist/controls/SkiaToggle.d.ts +25 -5
  55. package/dist/controls/SkiaToggle.js +58 -5
  56. package/dist/controls/SnappingLayout.d.ts +12 -1
  57. package/dist/controls/SnappingLayout.js +21 -2
  58. package/dist/controls/TooltipStyle.d.ts +52 -0
  59. package/dist/controls/TooltipStyle.js +88 -0
  60. package/dist/core/Accessibility.d.ts +134 -0
  61. package/dist/core/Accessibility.js +675 -9
  62. package/dist/core/Animators.d.ts +37 -1
  63. package/dist/core/Animators.js +102 -9
  64. package/dist/core/Canvas.d.ts +222 -10
  65. package/dist/core/Canvas.js +698 -37
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/Easing.d.ts +12 -1
  69. package/dist/core/Easing.js +25 -1
  70. package/dist/core/Gestures.d.ts +81 -2
  71. package/dist/core/Gestures.js +177 -3
  72. package/dist/core/Hover.d.ts +51 -0
  73. package/dist/core/Hover.js +140 -0
  74. package/dist/core/ImageEffects.d.ts +2 -0
  75. package/dist/core/ImageEffects.js +2 -0
  76. package/dist/core/KeyboardManager.d.ts +40 -0
  77. package/dist/core/KeyboardManager.js +98 -8
  78. package/dist/core/PopupWindows.d.ts +94 -0
  79. package/dist/core/PopupWindows.js +205 -0
  80. package/dist/core/ScrollAnimators.js +9 -0
  81. package/dist/core/Shaping.d.ts +40 -0
  82. package/dist/core/Shaping.js +224 -0
  83. package/dist/core/SkiaControl.d.ts +279 -10
  84. package/dist/core/SkiaControl.js +621 -64
  85. package/dist/core/SkiaEffect.d.ts +17 -0
  86. package/dist/core/SkiaEffect.js +43 -8
  87. package/dist/core/SkiaImageManager.js +1 -1
  88. package/dist/core/Super.d.ts +29 -2
  89. package/dist/core/Super.js +54 -3
  90. package/dist/core/Tooltips.d.ts +71 -0
  91. package/dist/core/Tooltips.js +205 -0
  92. package/dist/core/Types.d.ts +11 -1
  93. package/dist/core/Types.js +32 -1
  94. package/dist/core/ViewsAdapter.d.ts +7 -2
  95. package/dist/core/ViewsAdapter.js +10 -3
  96. package/dist/index.d.ts +6 -0
  97. package/dist/index.js +6 -0
  98. package/dist/react/SkiaShell.js +65 -26
  99. package/dist/react/index.d.ts +33 -4
  100. package/dist/react/index.js +157 -18
  101. package/dist/react/reconciler.d.ts +20 -0
  102. package/dist/react/reconciler.js +69 -14
  103. package/dist/vite/index.d.ts +9 -0
  104. package/dist/vite/index.js +36 -3
  105. package/package.json +61 -2
@@ -0,0 +1,82 @@
1
+ import { ActionOnTickAnimator } from "../core/Animators";
2
+ import { KeyboardManager } from "../core/KeyboardManager";
3
+ import { SkiaLayout } from "./SkiaLayout";
4
+ import { CanvasLeaveWatchers } from "../core/SkiaControl";
5
+ /**
6
+ * Mirrors DrawnUi.Gaming DrawnGame (SharedGame/DrawnGame.cs + Game.Input.cs): a layout that runs a game loop.
7
+ * `StartLoop()` / `StopLoop()`, override `GameLoop(deltaSeconds)` for the game and `OnKeyDown` / `OnKeyUp` for keys
8
+ * (DOM `event.code` names, e.g. "ArrowLeft", "Space"). The loop is an `ActionOnTickAnimator`, ticked once per drawn
9
+ * frame; started before the game is attached it waits for the first layout, like C#.
10
+ * Not ported: `FrameTimeInterpolator` (C# disables it on BROWSER too, the raw frame delta is used).
11
+ */
12
+ export class DrawnGame extends SkiaLayout {
13
+ appLoop;
14
+ LastFrameTimeNanos = 0;
15
+ isPaused = false;
16
+ onKeyDown = (key) => this.OnKeyDown(key);
17
+ onKeyChar = () => { };
18
+ onKeyUp = (key) => this.OnKeyUp(key);
19
+ keysOn = false;
20
+ /** The game gets keys while it is on a canvas: from its first layout there until it leaves it. */
21
+ ListenToKeys(on) {
22
+ if (on === this.keysOn)
23
+ return;
24
+ this.keysOn = on;
25
+ if (on) {
26
+ KeyboardManager.Subscribe(this.onKeyDown, this.onKeyChar, this.onKeyUp);
27
+ CanvasLeaveWatchers.add(this);
28
+ }
29
+ else {
30
+ KeyboardManager.Unsubscribe(this.onKeyDown, this.onKeyChar, this.onKeyUp);
31
+ CanvasLeaveWatchers.delete(this);
32
+ }
33
+ }
34
+ OnLayoutChanged() {
35
+ super.OnLayoutChanged();
36
+ if (!this.keysOn && this.Superview)
37
+ this.ListenToKeys(true);
38
+ }
39
+ OnLeftCanvas() { this.ListenToKeys(false); }
40
+ OnDisposing() {
41
+ this.ListenToKeys(false);
42
+ this.appLoop?.Dispose();
43
+ this.appLoop = undefined;
44
+ super.OnDisposing();
45
+ }
46
+ OnResumed() { }
47
+ OnPaused() { }
48
+ /** Override this for your game. `deltaSeconds` is the time elapsed between the previous frame and this one. */
49
+ GameLoop(_deltaSeconds) { }
50
+ /** Stops the game loop. */
51
+ StopLoop() { this.appLoop?.Stop(); }
52
+ /** Starts the game loop. */
53
+ StartLoop(delayMs = 0) {
54
+ this.appLoop ??= new ActionOnTickAnimator(this, (t) => this.GameTick(t));
55
+ this.LastFrameTimeNanos = 0; // the first frame of a (re)started loop has no previous one: its delta is 0
56
+ this.appLoop.Start(delayMs);
57
+ }
58
+ /**
59
+ * Internal, override `GameLoop` for your game. Frame time is in nanoseconds. The first frame after StartLoop or
60
+ * Resume gets a delta of 0, not the time since the clock's origin or since the stop (DrawnUi.Rust game_loop).
61
+ */
62
+ GameTick(frameTimeNanos) {
63
+ const deltaSeconds = this.LastFrameTimeNanos === 0 ? 0 : (frameTimeNanos - this.LastFrameTimeNanos) / 1_000_000_000;
64
+ this.LastFrameTimeNanos = frameTimeNanos;
65
+ this.GameLoop(deltaSeconds);
66
+ }
67
+ get IsPaused() { return this.isPaused; }
68
+ set IsPaused(value) { this.isPaused = value; }
69
+ Pause() {
70
+ this.IsPaused = true;
71
+ this.OnPaused();
72
+ }
73
+ Resume() {
74
+ this.LastFrameTimeNanos = 0; // the frame clock restarts: the next delta is 0
75
+ this.IsPaused = false;
76
+ this.OnResumed();
77
+ }
78
+ /** Override this to process game keys. */
79
+ OnKeyDown(_key) { }
80
+ /** Override this to process game keys. */
81
+ OnKeyUp(_key) { }
82
+ }
@@ -16,6 +16,8 @@ export declare class DefinitionInfo {
16
16
  }
17
17
  /** Parses "*, 2*, Auto, 100" (or an array of the same values) into tracks. */
18
18
  export declare function ParseDefinitions(defs: string | GridLength[] | undefined): DefinitionInfo[];
19
+ /** What the structure reads from a child: a control, or the slot of a recycled templated item (measured on a pooled view). */
20
+ export type GridChild = Pick<SkiaControl, "IsVisible" | "Row" | "Column" | "RowSpan" | "ColumnSpan" | "HorizontalOptions" | "VerticalOptions" | "MinimumWidthRequest" | "MinimumHeightRequest" | "HeightRequest" | "Margin" | "MeasuredSize" | "Measure">;
19
21
  /**
20
22
  * Port of DrawnUi SkiaGridStructure (itself adapted from the MAUI Grid manager). Works in POINTS: constraints come in
21
23
  * already reduced by the grid's padding, cells are returned relative to the padded box. Children are measured in
@@ -35,7 +37,7 @@ export declare class SkiaGridStructure {
35
37
  private readonly spans;
36
38
  private readonly explicitWidth;
37
39
  private readonly explicitHeight;
38
- constructor(grid: SkiaLayout, widthConstraint: number, heightConstraint: number, scale: number);
40
+ constructor(grid: SkiaLayout, widthConstraint: number, heightConstraint: number, scale: number, children?: readonly GridChild[]);
39
41
  private InitializeTracks;
40
42
  private static CreateDefinitionIfMissing;
41
43
  private static ToLengthType;
@@ -46,7 +48,7 @@ export declare class SkiaGridStructure {
46
48
  LeftEdgeOfColumn(column: number): number;
47
49
  TopEdgeOfRow(row: number): number;
48
50
  /** Cell rectangle in points relative to the padded box (+ offsets). */
49
- GetCellBoundsFor(view: SkiaControl, xOffset?: number, yOffset?: number): {
51
+ GetCellBoundsFor(view: GridChild, xOffset?: number, yOffset?: number): {
50
52
  Left: number;
51
53
  Top: number;
52
54
  Width: number;
@@ -63,6 +65,18 @@ export declare class SkiaGridStructure {
63
65
  private ResolveStars;
64
66
  private ResolveStarColumns;
65
67
  private ResolveStarRows;
68
+ /**
69
+ * C# SizesAutoRow: the child decides the height of its single Auto row, so it is measured with the height that row
70
+ * could still grow to, not with the row's current size (drawnui-cross 6p).
71
+ */
72
+ private SizesAutoRow;
73
+ private static NeedFillY;
74
+ /**
75
+ * C# HeightOnAutoRow: the height the single Auto row could still grow to, unbounded for a vertical Fill child (which
76
+ * would take the whole constraint). The row's size so far came from a first pass at the grid's whole width, so a
77
+ * label wrapping in a star column was measured against its one-line height.
78
+ */
79
+ private HeightOnAutoRow;
66
80
  private MeasureKnownCells;
67
81
  private AvailableWidth;
68
82
  private AvailableHeight;
@@ -88,7 +88,7 @@ export class SkiaGridStructure {
88
88
  spans = new Map();
89
89
  explicitWidth;
90
90
  explicitHeight;
91
- constructor(grid, widthConstraint, heightConstraint, scale) {
91
+ constructor(grid, widthConstraint, heightConstraint, scale, children = grid.Views) {
92
92
  this.grid = grid;
93
93
  this.widthConstraint = widthConstraint;
94
94
  this.heightConstraint = heightConstraint;
@@ -99,7 +99,7 @@ export class SkiaGridStructure {
99
99
  this.explicitHeight = grid.HeightRequest;
100
100
  this.Rows = this.InitializeTracks(grid.RowDefinitions, grid.DefaultRowDefinition);
101
101
  this.Columns = this.InitializeTracks(grid.ColumnDefinitions, grid.DefaultColumnDefinition);
102
- this.children = grid.Views.filter((v) => v.IsVisible);
102
+ this.children = children.filter((v) => v.IsVisible);
103
103
  this.InitializeCells();
104
104
  this.MeasureCells();
105
105
  }
@@ -294,7 +294,20 @@ export class SkiaGridStructure {
294
294
  ResolveStarRows(heightConstraint) {
295
295
  this.ResolveStars(this.Rows, heightConstraint - this.GridHeight(), (c) => c.IsRowSpanStar, (v) => v.MeasuredSize.Units.Height);
296
296
  }
297
+ /**
298
+ * C# SizesAutoRow: the child decides the height of its single Auto row, so it is measured with the height that row
299
+ * could still grow to, not with the row's current size (drawnui-cross 6p).
300
+ */
301
+ SizesAutoRow(cell) { return cell.RowSpan === 1 && this.Rows[cell.Row].IsAuto; }
302
+ static NeedFillY(child) { return child.VerticalOptions === "Fill" && child.HeightRequest < 0; }
303
+ /**
304
+ * C# HeightOnAutoRow: the height the single Auto row could still grow to, unbounded for a vertical Fill child (which
305
+ * would take the whole constraint). The row's size so far came from a first pass at the grid's whole width, so a
306
+ * label wrapping in a star column was measured against its one-line height.
307
+ */
308
+ HeightOnAutoRow(cell, child) { return SkiaGridStructure.NeedFillY(child) ? Infinity : this.AvailableHeight(cell); }
297
309
  MeasureKnownCells() {
310
+ let autoRowGrew = false;
298
311
  for (const cell of this.cells) {
299
312
  if (!cell.NeedsKnownMeasurePass)
300
313
  continue;
@@ -307,12 +320,30 @@ export class SkiaGridStructure {
307
320
  continue;
308
321
  const child = this.children[cell.ViewIndex];
309
322
  const rect = this.GetCellBoundsFor(child);
310
- this.MeasurePx(child, rect.Width, rect.Height);
323
+ if (child.IsVisible && this.SizesAutoRow(cell)) {
324
+ // the row grows to the child at its real width, within the room the grid has left
325
+ let grown = this.MeasurePx(child, rect.Width, this.HeightOnAutoRow(cell, child)).Height;
326
+ const available = this.AvailableHeight(cell);
327
+ if (isFinite(available) && grown > available)
328
+ grown = available;
329
+ if (grown > this.Rows[cell.Row].Size) {
330
+ this.Rows[cell.Row].Update(grown);
331
+ autoRowGrew = true;
332
+ }
333
+ }
334
+ else
335
+ this.MeasurePx(child, rect.Width, rect.Height);
311
336
  if (cell.IsColumnSpanStar && cell.ColumnSpan > 1)
312
337
  this.TrackSpan({ Key: `c${cell.Column}:${cell.ColumnSpan}`, Start: cell.Column, Length: cell.ColumnSpan, IsColumn: true, Requested: rect.Width });
313
338
  if (cell.IsRowSpanStar && cell.RowSpan > 1)
314
339
  this.TrackSpan({ Key: `r${cell.Row}:${cell.RowSpan}`, Start: cell.Row, Length: cell.RowSpan, IsColumn: false, Requested: rect.Height });
315
340
  }
341
+ if (autoRowGrew) {
342
+ // star rows were resolved against the smaller Auto rows: they get what is left now, nothing when Auto took it all
343
+ SkiaGridStructure.ZeroOutStars(this.Rows);
344
+ if (this.heightConstraint - this.GridHeight() > 0)
345
+ this.ResolveStarRows(this.heightConstraint);
346
+ }
316
347
  }
317
348
  AvailableWidth(cell) {
318
349
  let w = 0, absolute = true;
@@ -390,10 +421,15 @@ export class SkiaGridStructure {
390
421
  RemeasureChildrenAtFinalCells() {
391
422
  for (const cell of this.cells) {
392
423
  const child = this.children[cell.ViewIndex];
424
+ if (!child.IsVisible)
425
+ continue;
393
426
  const rect = this.GetCellBoundsFor(child);
394
427
  if (rect.Width <= 0 || rect.Height <= 0)
395
428
  continue;
396
- const m = this.MeasurePx(child, rect.Width, rect.Height);
429
+ // on an Auto row a child that is not Fill vertically keeps the height the row can grow to, as in
430
+ // MeasureKnownCells: the same request returns at once, and wrapped text is not cut to the row
431
+ const height = this.SizesAutoRow(cell) && !SkiaGridStructure.NeedFillY(child) ? Math.max(rect.Height, this.AvailableHeight(cell)) : rect.Height;
432
+ const m = this.MeasurePx(child, rect.Width, height);
397
433
  if (cell.ColumnSpan === 1 && this.Columns[cell.Column].IsAuto && m.Width > this.Columns[cell.Column].Size)
398
434
  this.Columns[cell.Column].Update(m.Width);
399
435
  if (cell.RowSpan === 1 && this.Rows[cell.Row].IsAuto && m.Height > this.Rows[cell.Row].Size)
@@ -4,15 +4,21 @@ import { SkiaLayout } from "./SkiaLayout";
4
4
  /**
5
5
  * Mirrors DrawnUi SkiaBackdrop: draws what is already painted beneath its box through `Blur` (points, default 5)
6
6
  * and `Brightness` (gamma, 1 = unchanged), tinted by `BackgroundColor`; children draw first and are blurred too.
7
- * The snapshot comes from the surface being drawn (`UseContext`) or the on-screen surface. Not cached (re-blurs
8
- * on every frame it is drawn in; inside a cached parent it is re-recorded with that parent).
7
+ * The snapshot comes from the surface being drawn (`UseContext`, the area it covers there through every ancestor
8
+ * transform) or the on-screen surface. Not cached (re-blurs on every frame it is drawn in). Its picture-cached parents
9
+ * should use `UseCache = None` (the app sets it, the library never changes a parent's cache; a one-time console warning
10
+ * names the case); inside an Image-cached ancestor it copies that cache's surface
11
+ * (right when what shows through the glass is inside that cache, wrong when it should show content outside it).
9
12
  */
10
13
  export declare class SkiaBackdrop extends SkiaLayout {
14
+ /** Samples what is drawn below: a composite above redraws it whole when something inside changes (drawnui-cross 6m). */
15
+ protected get SamplesContent(): boolean;
11
16
  Blur: number;
12
17
  Brightness: number;
13
18
  /** Snapshot the surface currently drawn into (true) or the on-screen surface (false). */
14
19
  UseContext: boolean;
15
20
  private snapshot?;
21
+ private warnedPicture;
16
22
  constructor();
17
23
  get HasEffects(): boolean;
18
24
  /** The last snapshot taken (C# GetImage hands it over: the caller owns it afterwards). */
@@ -4,15 +4,21 @@ import { SkiaLayout } from "./SkiaLayout";
4
4
  /**
5
5
  * Mirrors DrawnUi SkiaBackdrop: draws what is already painted beneath its box through `Blur` (points, default 5)
6
6
  * and `Brightness` (gamma, 1 = unchanged), tinted by `BackgroundColor`; children draw first and are blurred too.
7
- * The snapshot comes from the surface being drawn (`UseContext`) or the on-screen surface. Not cached (re-blurs
8
- * on every frame it is drawn in; inside a cached parent it is re-recorded with that parent).
7
+ * The snapshot comes from the surface being drawn (`UseContext`, the area it covers there through every ancestor
8
+ * transform) or the on-screen surface. Not cached (re-blurs on every frame it is drawn in). Its picture-cached parents
9
+ * should use `UseCache = None` (the app sets it, the library never changes a parent's cache; a one-time console warning
10
+ * names the case); inside an Image-cached ancestor it copies that cache's surface
11
+ * (right when what shows through the glass is inside that cache, wrong when it should show content outside it).
9
12
  */
10
13
  export class SkiaBackdrop extends SkiaLayout {
14
+ /** Samples what is drawn below: a composite above redraws it whole when something inside changes (drawnui-cross 6m). */
15
+ get SamplesContent() { return true; }
11
16
  Blur = 5;
12
17
  Brightness = 1;
13
18
  /** Snapshot the surface currently drawn into (true) or the on-screen surface (false). */
14
19
  UseContext = true;
15
20
  snapshot;
21
+ warnedPicture = false;
16
22
  constructor() {
17
23
  super();
18
24
  this.HorizontalOptions = "Fill";
@@ -38,16 +44,36 @@ export class SkiaBackdrop extends SkiaLayout {
38
44
  }
39
45
  if (!this.HasEffects)
40
46
  return;
47
+ // recorded into a parent's picture cache: its copy of what is behind goes into the picture. The library never
48
+ // changes a parent's cache (Nick, C# cf18cf29): it says so once, the app sets UseCache = None on those parents
49
+ if (ctx.Context.Recording && !this.warnedPicture) {
50
+ this.warnedPicture = true;
51
+ console.warn(`[SkiaBackdrop]${this.Tag ? ` ${this.Tag}` : ""} is recorded into a parent's picture cache (Operations / OperationsFull, the default of SkiaShape): its copy of what is behind goes into the picture. Set UseCache = None on its picture-cached parents.`);
52
+ }
41
53
  // C# UseContext: snapshot the surface the pixels end up on — the on-screen surface or the nearest Image cache
42
- // surface (Origin = its top-left in canvas pixels). Content beneath is already there because caches are recorded
43
- // inline while the parent paints, so this also works while an Operations picture is being recorded.
54
+ // surface. Copied where the backdrop really is on that surface: its rect through the canvas matrix (ancestor
55
+ // scale, move, rotation, 3D, the cache origin), rounded out, clamped to the surface, and drawn back 1:1 with the
56
+ // matrix undone, clipped to the backdrop's own (maybe turned) rect: the blur stays the same on screen while an
57
+ // ancestor scales (C# 6fd3bae3). The global surface (UseContext false) is copied at the layout rect.
44
58
  const surface = this.UseContext ? ctx.Context.Surface : this.Superview?.Surface;
45
59
  if (!surface)
46
60
  return;
47
61
  surface.flush();
48
- const origin = this.UseContext ? ctx.Context.Origin : undefined;
49
- const ox = origin?.X ?? 0, oy = origin?.Y ?? 0;
50
- const l = Math.floor(d.Left - ox), t = Math.floor(d.Top - oy), r = Math.ceil(d.Right - ox), b = Math.ceil(d.Bottom - oy);
62
+ let l = Math.floor(d.Left), t = Math.floor(d.Top), r = Math.ceil(d.Right), b = Math.ceil(d.Bottom);
63
+ let device = null;
64
+ if (this.UseContext) {
65
+ const m = canvas.getTotalMatrix();
66
+ const p = CK.Matrix.mapPoints(m, [d.Left, d.Top, d.Right, d.Top, d.Right, d.Bottom, d.Left, d.Bottom]);
67
+ l = Math.max(0, Math.floor(Math.min(p[0], p[2], p[4], p[6])));
68
+ t = Math.max(0, Math.floor(Math.min(p[1], p[3], p[5], p[7])));
69
+ r = Math.min(surface.width(), Math.ceil(Math.max(p[0], p[2], p[4], p[6])));
70
+ b = Math.min(surface.height(), Math.ceil(Math.max(p[1], p[3], p[5], p[7])));
71
+ if (r <= l || b <= t)
72
+ return;
73
+ device = CK.Matrix.invert(m);
74
+ if (!device)
75
+ return;
76
+ }
51
77
  // whole-surface snapshot, sub-rect on draw: a bounded snapshot of a GPU surface is not origin-safe in CanvasKit
52
78
  const image = surface.makeImageSnapshot();
53
79
  if (!image)
@@ -61,7 +87,13 @@ export class SkiaBackdrop extends SkiaLayout {
61
87
  paint.setColorFilter(gamma);
62
88
  const saved = canvas.save();
63
89
  canvas.clipRect(CK.LTRBRect(d.Left, d.Top, d.Right, d.Bottom), CK.ClipOp.Intersect, true);
64
- canvas.drawImageRectOptions(image, CK.LTRBRect(l, t, r, b), CK.LTRBRect(d.Left, d.Top, d.Right, d.Bottom), CK.FilterMode.Linear, CK.MipmapMode.None, paint);
90
+ if (device) {
91
+ canvas.concat(device);
92
+ canvas.drawImageRectOptions(image, CK.LTRBRect(l, t, r, b), CK.LTRBRect(l, t, r, b), CK.FilterMode.Nearest, CK.MipmapMode.None, paint);
93
+ }
94
+ else {
95
+ canvas.drawImageRectOptions(image, CK.LTRBRect(l, t, r, b), CK.LTRBRect(d.Left, d.Top, d.Right, d.Bottom), CK.FilterMode.Linear, CK.MipmapMode.None, paint);
96
+ }
65
97
  canvas.restoreToCount(saved);
66
98
  blur?.delete();
67
99
  gamma?.delete();
@@ -69,12 +101,8 @@ export class SkiaBackdrop extends SkiaLayout {
69
101
  const kill = this.snapshot;
70
102
  this.snapshot = image;
71
103
  kill?.delete();
72
- // What is beneath may change without invalidating this branch (an image that loads later, a sibling animating):
73
- // stale the ancestors' caches for the NEXT frame, after the current record has finished, without asking for one.
74
- queueMicrotask(() => { let p = this.Parent; while (p) {
75
- p.InvalidateCache();
76
- p = p.Parent;
77
- } });
104
+ // the library never changes how a parent's cache behaves (Nick, 2026-10-25): a cached parent replays the copy it
105
+ // recorded, as in C#; the app sets UseCache = None on the parents of a backdrop that must follow what is behind
78
106
  }
79
107
  OnDisposing() { this.snapshot?.delete(); this.snapshot = undefined; }
80
108
  }
@@ -1,5 +1,5 @@
1
1
  import type { Path } from "canvaskit-wasm";
2
- import type { SkiaControl } from "../core/SkiaControl";
2
+ import { SkiaControl } from "../core/SkiaControl";
3
3
  import { type Color, type CornerRadius, ScaledSize, type SkiaTouchAnimation } from "../core/Types";
4
4
  import { type GestureEventProcessingInfo, type SkiaGesturesParameters } from "../core/Gestures";
5
5
  import { SkiaLayout } from "./SkiaLayout";
@@ -10,6 +10,8 @@ import { type PrebuiltControlStyle, type ResolvedControlStyle } from "../core/Co
10
10
  * PanThreshold. Press feedback = ApplyEffect (ripple), no darkening.
11
11
  */
12
12
  export declare class SkiaButton extends SkiaLayout {
13
+ /** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault). */
14
+ protected ReceivesHoverByDefault(): boolean;
13
15
  static PanThreshold: number;
14
16
  Text: string;
15
17
  /** Look of the default content (C# SkiaButton.ControlStyle): background, corners, font, minimum size when left unset. */
@@ -24,7 +26,17 @@ export declare class SkiaButton extends SkiaLayout {
24
26
  StrokeColor: Color;
25
27
  StrokeWidth: number;
26
28
  IsPressed: boolean;
27
- IsDisabled: boolean;
29
+ private respondsToGestures;
30
+ /**
31
+ * False switches the button off for the user: taps, presses and keyboard activation do nothing (no Tapped, Down, Up),
32
+ * a tap on it does not reach controls under it, and screen readers report it disabled. Code can still change it.
33
+ * Same property as on toggles, sliders, scrolls and drawers (drawnui-cross 6w). Default true.
34
+ */
35
+ get RespondsToGestures(): boolean;
36
+ set RespondsToGestures(v: boolean);
37
+ /** @deprecated The opposite of RespondsToGestures, which every control uses: set `RespondsToGestures = false`. */
38
+ get IsDisabled(): boolean;
39
+ set IsDisabled(v: boolean);
28
40
  LockPanning: boolean;
29
41
  /** Touch feedback played on Down (DrawnUi SkiaButton.ApplyEffect). */
30
42
  ApplyEffect: SkiaTouchAnimation;
@@ -41,6 +53,8 @@ export declare class SkiaButton extends SkiaLayout {
41
53
  static DefaultAccessibilityRole?: string;
42
54
  protected DefaultAccessibilityLabel(): string | undefined;
43
55
  protected DefaultAccessibilityCanInteract(): boolean;
56
+ /** With RespondsToGestures = false the button ignores taps, keyboard navigation skips it and it is reported disabled. */
57
+ protected AcceptsInput(): boolean;
44
58
  /** The button's own BackgroundColor/CornerRadius/Stroke are the frame's; the button itself paints nothing. */
45
59
  protected PaintBackground(): void;
46
60
  get UsingControlStyle(): ResolvedControlStyle;
@@ -55,7 +69,7 @@ export declare class SkiaButton extends SkiaLayout {
55
69
  /** Ripple clipped to the rounded frame. */
56
70
  CreateClip(): Path;
57
71
  /** DrawnUi SkiaButton.OnDown: press feedback; true = consume Down. */
58
- protected OnDown(_args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): boolean;
72
+ protected OnDown(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): boolean;
59
73
  private SetUp;
60
74
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
61
75
  }
@@ -1,15 +1,18 @@
1
+ import { SkiaControl } from "../core/SkiaControl";
1
2
  import { Colors, SKRect, ScaledSize, SkiaShadow, Thickness } from "../core/Types";
2
3
  import { SKPoint } from "../core/Gestures";
3
4
  import { SkiaLayout } from "./SkiaLayout";
4
5
  import { SkiaLabel } from "./SkiaLabel";
5
6
  import { SkiaShape } from "./SkiaShape";
6
- import { ResolveControlStyle } from "../core/ControlStyle";
7
+ import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
7
8
  /**
8
9
  * Mirrors DrawnUi SkiaButton (default style): a SkiaShape frame tagged "BtnShape" + a centered SkiaLabel
9
10
  * tagged "BtnText". Consumes Down/Up/Tapped inside its rect; releases the pressed state when a pan exceeds
10
11
  * PanThreshold. Press feedback = ApplyEffect (ripple), no darkening.
11
12
  */
12
13
  export class SkiaButton extends SkiaLayout {
14
+ /** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault). */
15
+ ReceivesHoverByDefault() { return true; }
13
16
  static PanThreshold = 5;
14
17
  Text = "";
15
18
  /** Look of the default content (C# SkiaButton.ControlStyle): background, corners, font, minimum size when left unset. */
@@ -24,7 +27,20 @@ export class SkiaButton extends SkiaLayout {
24
27
  StrokeColor = Colors.Transparent;
25
28
  StrokeWidth = 0;
26
29
  IsPressed = false;
27
- IsDisabled = false;
30
+ respondsToGestures = true;
31
+ /**
32
+ * False switches the button off for the user: taps, presses and keyboard activation do nothing (no Tapped, Down, Up),
33
+ * a tap on it does not reach controls under it, and screen readers report it disabled. Code can still change it.
34
+ * Same property as on toggles, sliders, scrolls and drawers (drawnui-cross 6w). Default true.
35
+ */
36
+ get RespondsToGestures() { return this.respondsToGestures; }
37
+ set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
38
+ this.respondsToGestures = v;
39
+ this.NotifyAccessibility();
40
+ } }
41
+ /** @deprecated The opposite of RespondsToGestures, which every control uses: set `RespondsToGestures = false`. */
42
+ get IsDisabled() { return !this.respondsToGestures; }
43
+ set IsDisabled(v) { this.RespondsToGestures = !v; }
28
44
  LockPanning = false;
29
45
  /** Touch feedback played on Down (DrawnUi SkiaButton.ApplyEffect). */
30
46
  ApplyEffect = "Ripple"; // C# default
@@ -58,7 +74,9 @@ export class SkiaButton extends SkiaLayout {
58
74
  /** Set to `Aria.RoleButton` to expose every button (React extension). */
59
75
  static DefaultAccessibilityRole;
60
76
  DefaultAccessibilityLabel() { return this.Text || undefined; }
61
- DefaultAccessibilityCanInteract() { return !this.IsDisabled; }
77
+ DefaultAccessibilityCanInteract() { return this.respondsToGestures; }
78
+ /** With RespondsToGestures = false the button ignores taps, keyboard navigation skips it and it is reported disabled. */
79
+ AcceptsInput() { return this.respondsToGestures; }
62
80
  /** The button's own BackgroundColor/CornerRadius/Stroke are the frame's; the button itself paints nothing. */
63
81
  PaintBackground() { }
64
82
  get UsingControlStyle() { return ResolveControlStyle(this.ControlStyle); }
@@ -72,7 +90,7 @@ export class SkiaButton extends SkiaLayout {
72
90
  case "Material": return { bg: "#2196F3", radius: 4, font: 14, weight: 0, minW: 100, minH: 40, shadow: new SkiaShadow({ X: 0, Y: 2, Blur: 4, Opacity: 0.3, Color: Colors.Black }) };
73
91
  case "Material3": return { bg: "#6750A4", radius: 20, font: 14, weight: 0, minW: 100, minH: 40 };
74
92
  case "Windows": return { bg: "#0078D7", radius: 4, font: 15, weight: 500, minW: 100, minH: 32, shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 1, Opacity: 0.2, Color: Colors.Black }) };
75
- default: return { bg: "#DC143C", radius: 8, font: 15, weight: 0, minW: 100, minH: 41 };
93
+ default: return { bg: DefaultAccent, radius: 8, font: 15, weight: 0, minW: 100, minH: 41 };
76
94
  }
77
95
  }
78
96
  MeasureAbsolute(w, h, scale) {
@@ -112,8 +130,8 @@ export class SkiaButton extends SkiaLayout {
112
130
  /** Ripple clipped to the rounded frame. */
113
131
  CreateClip() { return this.frame.CreateClip(); }
114
132
  /** DrawnUi SkiaButton.OnDown: press feedback; true = consume Down. */
115
- OnDown(_args, apply) {
116
- if (this.ApplyEffect === "Ripple") {
133
+ OnDown(args, apply) {
134
+ if (this.ApplyEffect === "Ripple" && SkiaControl.IsPrimaryPointer(args)) {
117
135
  const pts = this.GetOffsetInsideControlInPoints(apply.MappedLocation, apply.ChildOffset);
118
136
  this.PlayRippleAnimation(this.TouchEffectColor, pts.X, pts.Y);
119
137
  }
@@ -126,8 +144,8 @@ export class SkiaButton extends SkiaLayout {
126
144
  this.Repaint();
127
145
  }
128
146
  ProcessGestures(args, apply) {
129
- if (this.IsDisabled)
130
- return null;
147
+ if (!this.respondsToGestures)
148
+ return this.BlockedGestureResult(args); // no press, no Down / Up / Tapped; a tap on it stops here
131
149
  const point = args.Event.Location;
132
150
  if (args.Type === "Down") {
133
151
  this.IsPressed = true;
@@ -15,6 +15,8 @@ export interface SnapPoint {
15
15
  * `DynamicSize` sizes an auto-sized carousel from the selected slide, `SwipeSpeed` / `LinearSpeedMs` tune the snap.
16
16
  */
17
17
  export declare class SkiaCarousel extends SnappingLayout {
18
+ /** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault). */
19
+ protected ReceivesHoverByDefault(): boolean;
18
20
  IsVertical: boolean;
19
21
  /** Side padding in points so the previous/next slides peek in. */
20
22
  SidesOffset: number;
@@ -99,13 +101,24 @@ export declare class SkiaCarousel extends SnappingLayout {
99
101
  private GetVirtualSnapPoints;
100
102
  protected GetVirtualAnchor(current: SKPoint): SnapPoint;
101
103
  protected FindNearestAnchorInternal(current: SKPoint, velocity: SKPoint): SKPoint;
102
- /** C# SkiaCarousel.ScrollToNearestAnchor: velocity below 100 counts as none; looped snaps around virtual anchors. */
104
+ /** C# SkiaCarousel.ScrollToNearestAnchor: velocity below SnapVelocityThreshold counts as none; looped snaps around virtual anchors. */
103
105
  ScrollToNearestAnchor(location: SKPoint, velocity: SKPoint): void;
104
- /** C# SkiaCarousel.SelectNextAnchor: base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
106
+ /** C# SkiaCarousel.SelectNextAnchor: the choice below, at most one slide from where a finger gesture started. */
105
107
  SelectNextAnchor(origin: SKPoint, velocity: SKPoint): SKPoint;
108
+ /**
109
+ * A finger release moves at most one slide from the slide its gesture started on, as iOS paging and the Android
110
+ * ViewPager do (C# 1070e0db): a drag past the middle makes the next slide the nearest one, and the flick then went one
111
+ * further. Code moves (ScrollTo, SelectedIndex) are not limited: releaseHome is set only while a release snaps.
112
+ */
113
+ private LimitToNeighbours;
114
+ /** The slide a finger gesture started on (the target when it caught a snap in flight), see LimitToNeighbours. */
115
+ private gestureHome?;
116
+ private releaseHome?;
117
+ /** Base choice, plus a wrap to the virtual anchor at the strip borders when looped. */
118
+ private SelectNextAnchorInternal;
106
119
  /** C# FixIndex: a virtual anchor becomes the real one, the position keeps its offset (visually identical, looped drawing wraps). */
107
120
  private FixIndex;
108
- private FixPosition;
121
+ protected FixPosition(): void;
109
122
  protected OnTransitionChanged(): void;
110
123
  protected ScaleSnapVelocity(velocity: SKPoint): SKPoint;
111
124
  protected CreateSnapSpring(): Spring;
@@ -127,6 +140,12 @@ export declare class SkiaCarousel extends SnappingLayout {
127
140
  /** C# RenderViewsList: position every slide, draw the visible ones (+ neighbours when PreloadNeighboors), release the rest. */
128
141
  protected Paint(ctx: DrawingContext): void;
129
142
  private SlideRect;
143
+ /**
144
+ * Whether the slide at `index` takes part in hit-testing for the frame being rendered (C# IsSlideHitTestable).
145
+ * Every slide drawn on screen does by default; a carousel whose slides share one rect (SkiaShaderCarousel) narrows
146
+ * this to the slide the user actually sees.
147
+ */
148
+ protected IsSlideHitTestable(_index: number): boolean;
130
149
  protected GetGestureListeners(): readonly SkiaControl[];
131
150
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
132
151
  protected DefaultAccessibilityLabel(): string | undefined;