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

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 (107) hide show
  1. package/README.md +129 -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 +241 -10
  65. package/dist/core/Canvas.js +739 -44
  66. package/dist/core/ControlStyle.d.ts +2 -0
  67. package/dist/core/ControlStyle.js +2 -0
  68. package/dist/core/DesignerActions.d.ts +32 -0
  69. package/dist/core/DesignerActions.js +68 -0
  70. package/dist/core/Easing.d.ts +12 -1
  71. package/dist/core/Easing.js +25 -1
  72. package/dist/core/Gestures.d.ts +81 -2
  73. package/dist/core/Gestures.js +177 -3
  74. package/dist/core/Hover.d.ts +51 -0
  75. package/dist/core/Hover.js +140 -0
  76. package/dist/core/ImageEffects.d.ts +2 -0
  77. package/dist/core/ImageEffects.js +2 -0
  78. package/dist/core/KeyboardManager.d.ts +40 -0
  79. package/dist/core/KeyboardManager.js +98 -8
  80. package/dist/core/PopupWindows.d.ts +94 -0
  81. package/dist/core/PopupWindows.js +205 -0
  82. package/dist/core/ScrollAnimators.js +9 -0
  83. package/dist/core/Shaping.d.ts +40 -0
  84. package/dist/core/Shaping.js +224 -0
  85. package/dist/core/SkiaControl.d.ts +284 -11
  86. package/dist/core/SkiaControl.js +630 -66
  87. package/dist/core/SkiaEffect.d.ts +17 -0
  88. package/dist/core/SkiaEffect.js +43 -8
  89. package/dist/core/SkiaImageManager.js +1 -1
  90. package/dist/core/Super.d.ts +29 -2
  91. package/dist/core/Super.js +54 -3
  92. package/dist/core/Tooltips.d.ts +71 -0
  93. package/dist/core/Tooltips.js +205 -0
  94. package/dist/core/Types.d.ts +11 -1
  95. package/dist/core/Types.js +32 -1
  96. package/dist/core/ViewsAdapter.d.ts +7 -2
  97. package/dist/core/ViewsAdapter.js +10 -3
  98. package/dist/index.d.ts +7 -0
  99. package/dist/index.js +7 -0
  100. package/dist/react/SkiaShell.js +65 -26
  101. package/dist/react/index.d.ts +51 -4
  102. package/dist/react/index.js +180 -18
  103. package/dist/react/reconciler.d.ts +20 -0
  104. package/dist/react/reconciler.js +69 -14
  105. package/dist/vite/index.d.ts +9 -0
  106. package/dist/vite/index.js +36 -3
  107. package/package.json +66 -2
@@ -1,3 +1,4 @@
1
+ import { DefaultAccent } from "../core/ControlStyle";
1
2
  import { Colors, Thickness } from "../core/Types";
2
3
  import { SkiaLayout } from "./SkiaLayout";
3
4
  import { SkiaLabel } from "./SkiaLabel";
@@ -13,7 +14,7 @@ export class SkiaRadioButton extends SkiaToggle {
13
14
  groupKey;
14
15
  ViewOn;
15
16
  ViewText;
16
- static DefaultAccent = "#DC143C";
17
+ static DefaultAccent = DefaultAccent;
17
18
  static DefaultOutline = "#8E959D";
18
19
  constructor(text = "") {
19
20
  super();
@@ -37,8 +38,7 @@ export class SkiaRadioButton extends SkiaToggle {
37
38
  return table[this.UsingControlStyle]?.[name];
38
39
  }
39
40
  CreateDefaultContent() {
40
- if (this.MinimumHeightRequest < 0)
41
- this.MinimumHeightRequest = 24;
41
+ this.SetMinimumContentHeight(24);
42
42
  const s = this.usingStyle;
43
43
  const size = s === "Unset" ? 18 : 20;
44
44
  const box = new SkiaLayout();
@@ -121,6 +121,16 @@ export class SkiaRadioButton extends SkiaToggle {
121
121
  }
122
122
  DefaultAccessibilityLabel() { return this.text || undefined; }
123
123
  // ---- group (C# RadioButtons.All) ----
124
+ /** A disposed radio leaves its group, and an empty group goes: the module-level registry keeps no page alive. */
125
+ OnDisposing() {
126
+ if (this.groupKey) {
127
+ const set = groups.get(this.groupKey);
128
+ set?.delete(this);
129
+ if (set?.size === 0)
130
+ groups.delete(this.groupKey);
131
+ }
132
+ super.OnDisposing();
133
+ }
124
134
  UpdateGroup() {
125
135
  if (this.groupKey)
126
136
  groups.get(this.groupKey)?.delete(this);
@@ -145,8 +155,10 @@ export class SkiaRadioButton extends SkiaToggle {
145
155
  super.OnToggledChanged();
146
156
  }
147
157
  ProcessGestures(args, apply) {
158
+ if (!this.RespondsToGestures)
159
+ return this.BlockedGestureResult(args); // a tap does not select it, nor reach controls under it
148
160
  if (args.Type === "Tapped") {
149
- if (!this.IsToggled && this.RespondsToGestures) {
161
+ if (!this.IsToggled) {
150
162
  this.IsToggled = true;
151
163
  return this;
152
164
  }
@@ -72,6 +72,6 @@ export declare class SkiaRichLabel extends SkiaLabel {
72
72
  private RenderDocument;
73
73
  /** Blocks are separated by one line break once something was emitted (C# hadParagraph). */
74
74
  private BeginBlock;
75
- /** Inline markdown: `code`, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
75
+ /** Inline markdown: `code`, ***bold italic***, ___bold italic___, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
76
76
  private RenderInlines;
77
77
  }
@@ -206,7 +206,7 @@ export class SkiaRichLabel extends SkiaLabel {
206
206
  this.LineBreak();
207
207
  this.hadParagraph = true;
208
208
  }
209
- /** Inline markdown: `code`, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
209
+ /** Inline markdown: `code`, ***bold italic***, ___bold italic___, **bold**, __bold__, *italic*, _italic_, ~~strike~~, [text](url), backslash escapes. */
210
210
  RenderInlines(text, state) {
211
211
  let literal = "";
212
212
  const flush = () => { if (literal) {
@@ -246,6 +246,16 @@ export class SkiaRichLabel extends SkiaLabel {
246
246
  continue;
247
247
  }
248
248
  }
249
+ const three = text.slice(i, i + 3);
250
+ if (three === "***" || three === "___") {
251
+ const end = closes(three, i + 3);
252
+ if (end > i + 3) {
253
+ flush();
254
+ this.RenderInlines(text.slice(i + 3, end), { ...state, bold: true, italic: true });
255
+ i = end + 3;
256
+ continue;
257
+ }
258
+ }
249
259
  const two = text.slice(i, i + 2);
250
260
  if (two === "**" || two === "__" || two === "~~") {
251
261
  const end = closes(two, i + 2);
@@ -12,7 +12,7 @@ export interface ScaledPoint {
12
12
  * Mirrors DrawnUi SkiaScroll (plain content, no header/footer/refresh/virtualization yet).
13
13
  * Offsets are in POINTS and <= 0 while inside bounds (content moves up/left as you scroll).
14
14
  * Physics ported 1:1: deceleration fling (rate = 1 - FrictionScrolled/100) cut at the content edge,
15
- * rubber-band overscroll while dragging, spring bounce back on release, wheel = WheelLineSize per notch.
15
+ * rubber-band overscroll while dragging, spring bounce back on release, wheel = WheelLineSize per notch (an event moves by its share of a notch).
16
16
  */
17
17
  export declare class SkiaScroll extends SkiaControl {
18
18
  static WheelLineSize: number;
@@ -31,7 +31,11 @@ export declare class SkiaScroll extends SkiaControl {
31
31
  AutoScrollingSpeedMs: number;
32
32
  ScrollingSpeedMs: number;
33
33
  IgnoreWrongDirection: boolean;
34
- RespondsToGestures: boolean;
34
+ private respondsToGestures;
35
+ /** False: neither a drag, the wheel nor the keyboard scrolls it (code still can), and it is reported disabled; its content keeps its own taps (drawnui-cross 6w). */
36
+ get RespondsToGestures(): boolean;
37
+ set RespondsToGestures(v: boolean);
38
+ protected AcceptsInput(): boolean;
35
39
  private header?;
36
40
  private footer?;
37
41
  /** A view before the content along the scroll axis; `Tag="Header"` on a JSX child sets it. */
@@ -156,6 +160,10 @@ export declare class SkiaScroll extends SkiaControl {
156
160
  set ViewportOffsetX(value: number);
157
161
  get ViewportOffsetY(): number;
158
162
  set ViewportOffsetY(value: number);
163
+ /** An offset set without a glide or a pan (a jump, a touchpad step): the controls under a still mouse changed. */
164
+ private OffsetJumped;
165
+ /** Hover waits while the content glides, flings, bounces or follows a pan (C# IsScrolling). */
166
+ MovesContent(): boolean;
159
167
  private readonly animatorFlingX;
160
168
  private readonly animatorFlingY;
161
169
  private readonly bounceX;
@@ -214,18 +222,40 @@ export declare class SkiaScroll extends SkiaControl {
214
222
  * templated layout (the recycled list is the scroll's only child; a header goes above the scroll or in Header).
215
223
  */
216
224
  ScrollToIndex(index: number, animate: boolean, option?: RelativePositionType): void;
225
+ /**
226
+ * An open ScrollToIndex (C# OrderedScrollToIndex, DrawnUi.Rust scroll_to_index): a row not measured yet is gone to by
227
+ * the sizes as they are estimated, and the order is aimed again every frame until the row has its real place and the
228
+ * viewport stands on it; an animated move goes on to a moved target in the time it has left, later corrections jump.
229
+ * A press, the wheel or another scroll drops it; while it is open LoadMore waits.
230
+ */
231
+ private indexOrder?;
232
+ private pursuing;
233
+ /** One step of the open order (C# ExecuteScrollToIndexOrder, Rust `pursue`), at the start of every paint. */
234
+ private PursueIndexOrder;
235
+ /** The offset (points) that puts item `index` where `option` says, by the sizes the list knows now; Exact = its place is measured. */
236
+ private AimIndex;
217
237
  private StopAnimators;
218
238
  /** DrawnUi DecelerationRatio: FrictionScrolled / 100, floored at 0.1 friction. */
219
239
  private get DecelerationRatio();
220
240
  private ResetPan;
241
+ private draggedScrollBar?;
242
+ private scrollBarOwnsGesture;
243
+ /**
244
+ * Thumb drag and track press on a ScrollBar / ScrollBarHorizontal with IsDraggable set (C# ProcessScrollBarGestures).
245
+ * A gesture that starts on the bar belongs to it until the next down: the content neither pans nor gets the tap.
246
+ * True when the gesture was handled here.
247
+ */
248
+ protected ProcessScrollBarGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): boolean;
249
+ private ApplyScrollBarDrag;
221
250
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
222
251
  private Bounce;
223
252
  /** DrawnUi StartToFlingFrom + PrepareToFlingAfterInitialized: cut the curve so it stops exactly at the edge. */
224
253
  private StartToFlingFrom;
225
254
  /**
226
- * One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs.
227
- * Notches arriving while the previous one is still animating add onto its target, so a fast wheel
228
- * spin travels N steps instead of restarting from the barely-moved current offset.
255
+ * One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs. An event moves by its share
256
+ * of a notch (Canvas.WheelDeltaPerNotch), so a touchpad's many small events scroll as far as the fingers moved (C#
257
+ * aaa871c3); an event under half a notch moves the content at once (no glide). Events arriving while the previous one is still animating add onto its target, so a fast wheel spin
258
+ * travels N steps instead of restarting from the barely-moved current offset.
229
259
  */
230
260
  private ApplyWheelScroll;
231
261
  }
@@ -9,7 +9,7 @@ import { RubberBandUtils, ScrollFlingAnimator, Spring, SpringWithVelocityAnimato
9
9
  * Mirrors DrawnUi SkiaScroll (plain content, no header/footer/refresh/virtualization yet).
10
10
  * Offsets are in POINTS and <= 0 while inside bounds (content moves up/left as you scroll).
11
11
  * Physics ported 1:1: deceleration fling (rate = 1 - FrictionScrolled/100) cut at the content edge,
12
- * rubber-band overscroll while dragging, spring bounce back on release, wheel = WheelLineSize per notch.
12
+ * rubber-band overscroll while dragging, spring bounce back on release, wheel = WheelLineSize per notch (an event moves by its share of a notch).
13
13
  */
14
14
  export class SkiaScroll extends SkiaControl {
15
15
  static WheelLineSize = 150;
@@ -28,23 +28,34 @@ export class SkiaScroll extends SkiaControl {
28
28
  AutoScrollingSpeedMs = 600;
29
29
  ScrollingSpeedMs = 400;
30
30
  IgnoreWrongDirection = false;
31
- RespondsToGestures = true;
31
+ respondsToGestures = true;
32
+ /** False: neither a drag, the wheel nor the keyboard scrolls it (code still can), and it is reported disabled; its content keeps its own taps (drawnui-cross 6w). */
33
+ get RespondsToGestures() { return this.respondsToGestures; }
34
+ set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
35
+ this.respondsToGestures = v;
36
+ this.NotifyAccessibility();
37
+ } }
38
+ AcceptsInput() { return this.respondsToGestures; }
32
39
  // ---- header / footer (C# SkiaScroll.Header / Footer) ----
33
40
  header;
34
41
  footer;
35
42
  /** A view before the content along the scroll axis; `Tag="Header"` on a JSX child sets it. */
36
43
  get Header() { return this.header; }
37
44
  set Header(v) { if (this.header === v)
38
- return; if (this.header)
39
- this.header.Parent = undefined; this.header = v; if (v) {
45
+ return; if (this.header) {
46
+ this.Superview?.ControlLeft(this.header, false);
47
+ this.header.Parent = undefined;
48
+ } this.header = v; if (v) {
40
49
  v.Parent = this;
41
50
  v.ZIndex = 1;
42
51
  } this.InvalidateMeasure(); }
43
52
  /** A view after the content along the scroll axis; `Tag="Footer"` on a JSX child sets it. */
44
53
  get Footer() { return this.footer; }
45
54
  set Footer(v) { if (this.footer === v)
46
- return; if (this.footer)
47
- this.footer.Parent = undefined; this.footer = v; if (v)
55
+ return; if (this.footer) {
56
+ this.Superview?.ControlLeft(this.footer, false);
57
+ this.footer.Parent = undefined;
58
+ } this.footer = v; if (v)
48
59
  v.Parent = this; this.InvalidateMeasure(); }
49
60
  /** The header stays at the viewport start while the content scrolls under it (drawn over the content unless HeaderBehind). */
50
61
  HeaderSticky = false;
@@ -121,7 +132,7 @@ export class SkiaScroll extends SkiaControl {
121
132
  }
122
133
  /** C# UpdateScrollBarIndicator: pushes progress / thumb ratio / overscroll / scrolling state when any changed. */
123
134
  UpdateScrollBarIndicator() {
124
- const isScrolling = this.IsScrolling || this.IsUserPanning;
135
+ const isScrolling = this.IsScrolling || this.IsUserPanning || !!this.draggedScrollBar;
125
136
  const scale = this.RenderingScale;
126
137
  const viewportH = this.DrawingRect.Height / scale, viewportW = this.DrawingRect.Width / scale;
127
138
  const extentH = this.ContentSize.Units.Height + this.HeaderExtentPts + this.FooterExtentPts, extentW = this.ContentSize.Units.Width + this.HeaderExtentPts + this.FooterExtentPts;
@@ -158,8 +169,10 @@ export class SkiaScroll extends SkiaControl {
158
169
  /** The pull-to-refresh view (IRefreshIndicator control); `Tag="RefreshIndicator"` on a JSX child sets it. */
159
170
  get RefreshIndicator() { return this.refreshIndicator; }
160
171
  set RefreshIndicator(v) { if (this.refreshIndicator === v)
161
- return; if (this.refreshIndicator)
162
- this.refreshIndicator.Parent = undefined; this.refreshIndicator = v; if (v)
172
+ return; if (this.refreshIndicator) {
173
+ this.Superview?.ControlLeft(this.refreshIndicator, false);
174
+ this.refreshIndicator.Parent = undefined;
175
+ } this.refreshIndicator = v; if (v)
163
176
  v.Parent = this; this.InvalidateMeasure(); }
164
177
  isRefreshing = false;
165
178
  wasRefreshing = false;
@@ -333,6 +346,8 @@ export class SkiaScroll extends SkiaControl {
333
346
  loadMoreTopArmed = false;
334
347
  /** C# CheckNeedToLoadMore: fires once per content extent near an edge; re-arms when the content grows or the user moves away (>offset+100pt, >2 s). */
335
348
  CheckLoadMore() {
349
+ if (this.indexOrder)
350
+ return; // an open ScrollToIndex has the viewport on its way: the edges are looked at after it
336
351
  const vertical = this.Orientation !== "Horizontal";
337
352
  const offset = vertical ? this.offsetY : this.offsetX;
338
353
  const min = vertical ? this.ContentOffsetBounds.Top : this.ContentOffsetBounds.Left; // most negative offset
@@ -373,6 +388,7 @@ export class SkiaScroll extends SkiaControl {
373
388
  if (this.content === value)
374
389
  return;
375
390
  if (this.content) {
391
+ this.Superview?.ControlLeft(this.content, false);
376
392
  this.content.Parent = undefined;
377
393
  if (this.content instanceof SkiaLayout)
378
394
  this.content.ItemsInsertedAtStart = undefined;
@@ -399,12 +415,19 @@ export class SkiaScroll extends SkiaControl {
399
415
  set ViewportOffsetX(value) { if (this.offsetX !== value) {
400
416
  this.offsetX = value;
401
417
  this.OnScrolled();
418
+ this.OffsetJumped();
402
419
  } }
403
420
  get ViewportOffsetY() { return this.offsetY; }
404
421
  set ViewportOffsetY(value) { if (this.offsetY !== value) {
405
422
  this.offsetY = value;
406
423
  this.OnScrolled();
424
+ this.OffsetJumped();
407
425
  } }
426
+ /** An offset set without a glide or a pan (a jump, a touchpad step): the controls under a still mouse changed. */
427
+ OffsetJumped() { if (!this.MovesContent())
428
+ this.Superview?.Hover?.RequestCheck(); }
429
+ /** Hover waits while the content glides, flings, bounces or follows a pan (C# IsScrolling). */
430
+ MovesContent() { return this.IsScrolling || this.IsUserPanning || !!this.draggedScrollBar; }
408
431
  animatorFlingX = new ScrollFlingAnimator(this);
409
432
  animatorFlingY = new ScrollFlingAnimator(this);
410
433
  bounceX = new SpringWithVelocityAnimator(this);
@@ -506,6 +529,7 @@ export class SkiaScroll extends SkiaControl {
506
529
  }
507
530
  InsertSubView(_index, control) { this.AddSubView(control); }
508
531
  RemoveSubView(control) {
532
+ this.Superview?.Hover?.RequestCheck();
509
533
  if (this.content === control)
510
534
  this.Content = undefined;
511
535
  else if (this.header === control)
@@ -548,10 +572,12 @@ export class SkiaScroll extends SkiaControl {
548
572
  this.footerSize = this.footer && this.footer.IsVisible ? this.footer.Measure(widthConstraint, heightConstraint, scale) : ScaledSize.Default;
549
573
  if (this.refreshIndicator)
550
574
  this.refreshIndicator.Measure(widthConstraint, heightConstraint, scale);
575
+ // C# SetMeasuredAdaptToContentSize: the scroll's own size is its content's, up to the space it is given; a side with
576
+ // a request or Fill takes its box in Measure (NeedAutoWidth / NeedAutoHeight)
551
577
  const extra = (this.HeaderExtentPts + this.FooterExtentPts) * scale;
552
- const rw = isFinite(widthConstraint) ? widthConstraint : this.ContentSize.Pixels.Width + (this.Orientation === "Horizontal" ? extra : 0);
553
- const rh = isFinite(heightConstraint) ? heightConstraint : this.ContentSize.Pixels.Height + (this.Orientation !== "Horizontal" ? extra : 0);
554
- return ScaledSize.FromPixels(rw, rh, scale);
578
+ const cw = this.ContentSize.Pixels.Width + (this.Orientation === "Horizontal" ? extra : 0);
579
+ const ch = this.ContentSize.Pixels.Height + (this.Orientation !== "Horizontal" ? extra : 0);
580
+ return ScaledSize.FromPixels(Math.min(cw, widthConstraint), Math.min(ch, heightConstraint), scale);
555
581
  }
556
582
  OnLayoutChanged() {
557
583
  const scale = this.RenderingScale;
@@ -560,6 +586,15 @@ export class SkiaScroll extends SkiaControl {
560
586
  const width = Math.max(0, this.ContentSize.Units.Width + (this.Orientation === "Horizontal" ? extra : 0) - viewportW);
561
587
  const height = Math.max(0, this.ContentSize.Units.Height + (this.Orientation !== "Horizontal" ? extra : 0) - viewportH);
562
588
  this.ContentOffsetBounds = new SKRect(-width, -height, 0, 0);
589
+ // C# InitializeViewport: pull an offset the new bounds no longer contain back inside them, here where
590
+ // the bounds change. Shrinking content (fewer items) otherwise leaves the viewport parked past its end
591
+ // with nothing on screen. Skipped under a live pan, a fling / bounce or pull-to-refresh, where being
592
+ // past the edge is intentional (rubber band, refresh indicator).
593
+ if (!this.IsUserPanning && !this.IsScrolling && !this.isRefreshing) {
594
+ const c = this.ClampOffset(this.offsetX, this.offsetY, this.ContentOffsetBounds, true);
595
+ this.ViewportOffsetX = c.X;
596
+ this.ViewportOffsetY = c.Y;
597
+ }
563
598
  this.ArrangeContent();
564
599
  this.CheckLoadMore();
565
600
  }
@@ -617,6 +652,8 @@ export class SkiaScroll extends SkiaControl {
617
652
  }
618
653
  }
619
654
  Paint(ctx) {
655
+ this.Superview?.Hover?.RegisterMover(this);
656
+ this.PursueIndexOrder();
620
657
  const c = this.content;
621
658
  if (!c)
622
659
  return;
@@ -637,9 +674,18 @@ export class SkiaScroll extends SkiaControl {
637
674
  if (this.RefreshEnabled && this.refreshIndicator && this.refreshIndicator.IsVisible && (this.OverScrolled || this.isRefreshing))
638
675
  this.refreshIndicator.Render(ctx);
639
676
  this.UpdateScrollBarIndicator();
640
- for (const bar of [this.scrollBar, this.scrollBarHorizontal])
641
- if (bar && bar.IsVisible && bar.Opacity > 0)
642
- bar.Render(ctx);
677
+ for (const bar of [this.scrollBar, this.scrollBarHorizontal]) {
678
+ if (!bar || !bar.IsVisible || bar.Opacity <= 0)
679
+ continue;
680
+ // the bar is parent-independent: its thumb resizing (squash on a bounce) invalidates the bar alone, so it is
681
+ // re-measured here on draw instead of dragging the scroll and every ancestor through a measure each frame
682
+ if (bar.NeedMeasure) {
683
+ const r = this.DrawingRect;
684
+ bar.Measure(r.Width, r.Height, this.RenderingScale);
685
+ bar.Arrange(r, bar.WidthRequest, bar.HeightRequest, this.RenderingScale);
686
+ }
687
+ bar.Render(ctx);
688
+ }
643
689
  canvas.restoreToCount(saved);
644
690
  }
645
691
  OnScrolled() {
@@ -710,6 +756,8 @@ export class SkiaScroll extends SkiaControl {
710
756
  this.ViewportOffsetY = target;
711
757
  }
712
758
  ScrollTo(x, y, maxSpeedSecs, clamp = true) {
759
+ if (!this.pursuing)
760
+ this.indexOrder = undefined; // another scroll drops an open ScrollToIndex
713
761
  this.StopAnimators(); // also forgets any pending edge bounce: a programmatic scroll never bounces
714
762
  let tx = x, ty = y;
715
763
  if (clamp) {
@@ -742,25 +790,110 @@ export class SkiaScroll extends SkiaControl {
742
790
  else
743
791
  this.ScrollTo(this.offsetX, this.ContentOffsetBounds.Top, maxTimeSecs);
744
792
  }
745
- StopScrolling() { this.StopAnimators(); this.IsUserPanning = false; }
793
+ StopScrolling() { this.indexOrder = undefined; this.StopAnimators(); this.IsUserPanning = false; }
746
794
  /**
747
795
  * Scrolls so that item `index` is at the viewport start (or end). Like DrawnUi, Content must BE the
748
796
  * templated layout (the recycled list is the scroll's only child; a header goes above the scroll or in Header).
749
797
  */
750
798
  ScrollToIndex(index, animate, option = "Start") {
799
+ this.indexOrder = { Index: index, Option: option, Secs: animate ? this.ScrollingSpeedMs / 1000 : 0, Stalled: 0 };
800
+ this.PursueIndexOrder();
801
+ this.Repaint();
802
+ }
803
+ /**
804
+ * An open ScrollToIndex (C# OrderedScrollToIndex, DrawnUi.Rust scroll_to_index): a row not measured yet is gone to by
805
+ * the sizes as they are estimated, and the order is aimed again every frame until the row has its real place and the
806
+ * viewport stands on it; an animated move goes on to a moved target in the time it has left, later corrections jump.
807
+ * A press, the wheel or another scroll drops it; while it is open LoadMore waits.
808
+ */
809
+ indexOrder;
810
+ pursuing = false;
811
+ /** One step of the open order (C# ExecuteScrollToIndexOrder, Rust `pursue`), at the start of every paint. */
812
+ PursueIndexOrder() {
813
+ const order = this.indexOrder;
814
+ if (!order)
815
+ return;
816
+ const horizontal = this.Orientation === "Horizontal";
817
+ const before = horizontal ? this.offsetX : this.offsetY;
818
+ const running = horizontal ? this.animatorFlingX : this.animatorFlingY;
819
+ const aim = this.AimIndex(order.Index, order.Option);
820
+ let done = false;
821
+ if (aim) {
822
+ const c = this.ClampOffset(horizontal ? aim.Offset : this.offsetX, horizontal ? this.offsetY : aim.Offset, this.ContentOffsetBounds, true);
823
+ const target = horizontal ? c.X : c.Y;
824
+ const runningTo = horizontal ? this.scrollToTargetX : this.scrollToTargetY;
825
+ const move = (to, secs) => {
826
+ this.pursuing = true;
827
+ try {
828
+ this.ScrollTo(horizontal ? to : this.offsetX, horizontal ? this.offsetY : to, secs, true);
829
+ }
830
+ finally {
831
+ this.pursuing = false;
832
+ }
833
+ };
834
+ if (running.IsRunning && runningTo !== null) {
835
+ if (Math.abs(runningTo - target) > 0.5) {
836
+ // on the way: the move goes on to the new target in the time it has left
837
+ const now = this.Superview?.FrameTimeNanos || performance.now() * 1_000_000;
838
+ move(target, running.StartFrameTimeNanos ? Math.max(0.016, running.Speed - (now - running.StartFrameTimeNanos) / 1e9) : running.Speed);
839
+ running.StartFrameTimeNanos = running.LastFrameTimeNanos = now;
840
+ }
841
+ }
842
+ else if (Math.abs(before - target) <= 0.5) {
843
+ if (horizontal)
844
+ this.ViewportOffsetX = target;
845
+ else
846
+ this.ViewportOffsetY = target;
847
+ done = aim.Exact;
848
+ }
849
+ else {
850
+ move(target, order.Secs);
851
+ order.Secs = 0;
852
+ }
853
+ }
854
+ // no list yet, or a row that never gets its real place: not forever
855
+ order.Stalled = (horizontal ? this.offsetX : this.offsetY) === before && !running.IsRunning ? order.Stalled + 1 : 0;
856
+ if (done || order.Stalled >= 10) {
857
+ this.indexOrder = undefined;
858
+ this.CheckLoadMore();
859
+ return;
860
+ }
861
+ this.Repaint(); // the next frame aims again
862
+ }
863
+ /** The offset (points) that puts item `index` where `option` says, by the sizes the list knows now; Exact = its place is measured. */
864
+ AimIndex(index, option) {
751
865
  const layout = this.content instanceof SkiaLayout && this.content.IsTemplated ? this.content : undefined;
752
866
  const items = layout?.ItemsSource;
753
867
  if (!layout || !items || items.length === 0 || !this.content)
754
- return;
868
+ return undefined;
755
869
  const i = Math.max(0, Math.min(items.length - 1, index));
756
870
  const scale = this.RenderingScale;
757
- const layoutTopPts = (layout.DrawingRect.Top - this.content.DrawingRect.Top) / scale;
758
- let target = layoutTopPts + layout.GetItemOffsetPixels(i) / scale;
871
+ const horizontal = this.Orientation === "Horizontal";
872
+ const viewport = (horizontal ? this.DrawingRect.Width : this.DrawingRect.Height) / scale;
873
+ // Item start and size in points, relative to the content start along the scroll axis.
874
+ let itemStart, itemSize;
875
+ if (!horizontal && layout.Type === "Column" && layout.Split <= 1) {
876
+ // The virtualized list: cells past the viewport are not realized, the structure knows their offsets.
877
+ itemStart = (layout.DrawingRect.Top - this.content.DrawingRect.Top + layout.GetItemOffsetPixels(i)) / scale;
878
+ itemSize = (layout.GetItemOffsetPixels(i + 1) - layout.GetItemOffsetPixels(i)) / scale;
879
+ }
880
+ else {
881
+ // A templated Row / Wrap / Grid realizes every item (C# non-list layouts are not virtualized): read the cell's
882
+ // arranged rect, like C# reads the structure cell's Destination.
883
+ // recycled slots know every item's place, shown or not
884
+ const r = layout.GetItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
885
+ if (!r)
886
+ return undefined;
887
+ const c = this.content.DrawingRect;
888
+ itemStart = (horizontal ? r.Left - c.Left : r.Top - c.Top) / scale;
889
+ itemSize = (horizontal ? r.Width : r.Height) / scale;
890
+ }
891
+ let target = itemStart;
759
892
  if (option === "End")
760
- target -= this.DrawingRect.Height / scale - layout.GetItemOffsetPixels(i + 1) / scale + layout.GetItemOffsetPixels(i) / scale;
893
+ target -= viewport - itemSize;
761
894
  else if (option === "Center")
762
- target -= this.DrawingRect.Height / scale / 2;
763
- this.ScrollTo(this.offsetX, -target, animate ? this.ScrollingSpeedMs / 1000 : 0, true);
895
+ target -= (viewport - itemSize) / 2;
896
+ return { Offset: -target, Exact: layout.IsItemMeasured(i) };
764
897
  }
765
898
  StopAnimators() {
766
899
  this.flingEdgeX = null;
@@ -783,11 +916,70 @@ export class SkiaScroll extends SkiaControl {
783
916
  this.panningLastDelta = SKPoint.Empty;
784
917
  this.panningCurrentOffsetPts = new SKPoint(this.offsetX, this.offsetY);
785
918
  }
919
+ draggedScrollBar;
920
+ scrollBarOwnsGesture = false;
921
+ /**
922
+ * Thumb drag and track press on a ScrollBar / ScrollBarHorizontal with IsDraggable set (C# ProcessScrollBarGestures).
923
+ * A gesture that starts on the bar belongs to it until the next down: the content neither pans nor gets the tap.
924
+ * True when the gesture was handled here.
925
+ */
926
+ ProcessScrollBarGestures(args, apply) {
927
+ if (args.Type === "Down") {
928
+ this.draggedScrollBar = undefined;
929
+ this.scrollBarOwnsGesture = false;
930
+ const draggable = (b) => b && b.IsDraggable && b.BeginDrag && b.GetDragProgress ? b : undefined;
931
+ const v = draggable(this.scrollBar), h = draggable(this.scrollBarHorizontal);
932
+ if (!v && !h)
933
+ return false;
934
+ const x = apply.MappedLocation.X + apply.ChildOffset.X, y = apply.MappedLocation.Y + apply.ChildOffset.Y;
935
+ if (v && v.BeginDrag(x, y))
936
+ this.draggedScrollBar = v;
937
+ else if (h && h.BeginDrag(x, y))
938
+ this.draggedScrollBar = h;
939
+ if (!this.draggedScrollBar)
940
+ return false;
941
+ this.scrollBarOwnsGesture = true;
942
+ this.StopScrolling();
943
+ this.ApplyScrollBarDrag(x, y);
944
+ args.Event.Handled = true; // used: a touch on the bar is claimed, the page must not take the drag
945
+ return true;
946
+ }
947
+ if (!this.scrollBarOwnsGesture)
948
+ return false;
949
+ if (!this.draggedScrollBar)
950
+ return args.Type === "Tapped" || args.Type === "LongPressing"; // released already: only the tap that follows belongs to the bar
951
+ if (args.Type === "Panning") {
952
+ this.ApplyScrollBarDrag(apply.MappedLocation.X + apply.ChildOffset.X, apply.MappedLocation.Y + apply.ChildOffset.Y);
953
+ args.Event.Handled = true;
954
+ }
955
+ else if (args.Type === "Up") {
956
+ this.draggedScrollBar = undefined;
957
+ this.scrollBarLast = undefined; // push the idle state so an auto-hiding bar fades again
958
+ this.scrollBarHLast = undefined;
959
+ this.Repaint();
960
+ }
961
+ return true;
962
+ }
963
+ ApplyScrollBarDrag(x, y) {
964
+ const bar = this.draggedScrollBar;
965
+ if (!bar)
966
+ return;
967
+ const progress = bar.GetDragProgress(x, y);
968
+ const b = this.ContentOffsetBounds;
969
+ if (bar === this.scrollBarHorizontal)
970
+ this.ViewportOffsetX = this.ClampOffset(-progress * b.Width, this.offsetY, b, true).X;
971
+ else
972
+ this.ViewportOffsetY = this.ClampOffset(this.offsetX, -progress * b.Height, b, true).Y;
973
+ this.Repaint();
974
+ }
786
975
  ProcessGestures(args, apply) {
787
976
  const consumedDefault = this.BlockGesturesBelow ? this : null;
788
977
  const scale = this.RenderingScale;
789
978
  const e = args.Event;
979
+ if (this.ProcessScrollBarGestures(args, apply))
980
+ return this;
790
981
  if (args.Type === "Down") {
982
+ this.indexOrder = undefined; // a press drops an open ScrollToIndex
791
983
  this.hadDown = true;
792
984
  this.snapped = false;
793
985
  if (this.RespondsToGestures) {
@@ -801,15 +993,21 @@ export class SkiaScroll extends SkiaControl {
801
993
  const child = super.ProcessGestures(args, apply);
802
994
  if (child && child !== this)
803
995
  return child;
804
- if (!this.RespondsToGestures)
996
+ if (!this.RespondsToGestures || this.Orientation === "Neither")
997
+ return child ?? consumedDefault; // Neither: not used, a parent scroll may take it
998
+ // a vertical scroll leaves horizontal events (the sideways part of a diagonal swipe) to whatever is around it
999
+ if (e.Wheel.IsHorizontal && this.Orientation === "Vertical")
805
1000
  return child ?? consumedDefault;
806
- return this.ApplyWheelScroll(e.Wheel.Delta) ? this : consumedDefault;
1001
+ if (!this.ApplyWheelScroll(e.Wheel.Delta))
1002
+ return consumedDefault; // at its edge: not used, the page may take it
1003
+ e.Handled = true;
1004
+ return this;
807
1005
  }
808
1006
  this.velocityY = e.Distance.Velocity.Y / scale;
809
1007
  this.velocityX = e.Distance.Velocity.X / scale;
810
1008
  const wrongDirection = (this.Orientation === "Vertical" && Math.abs(e.Distance.Total.X) > Math.abs(e.Distance.Total.Y) && Math.abs(e.Distance.Total.X) > SkiaScroll.ScrollVelocityThreshold * scale) ||
811
1009
  (this.Orientation === "Horizontal" && Math.abs(e.Distance.Total.Y) > Math.abs(e.Distance.Total.X) && Math.abs(e.Distance.Total.Y) > SkiaScroll.ScrollVelocityThreshold * scale);
812
- if (args.Type === "Panning" && this.RespondsToGestures && this.hadDown) {
1010
+ if (args.Type === "Panning" && this.RespondsToGestures && this.hadDown && this.Orientation !== "Neither") {
813
1011
  if (!this.IsUserPanning) {
814
1012
  // A child may own the pan (slider, nested horizontal scroll); ask once before taking over.
815
1013
  const childConsumed = super.ProcessGestures(args, apply);
@@ -860,6 +1058,12 @@ export class SkiaScroll extends SkiaControl {
860
1058
  const swipeThreshold = SkiaScroll.ThesholdSwipeOnUp * scale;
861
1059
  let vx = finalVelocity.X * this.ChangeVelocityScrolled;
862
1060
  let vy = finalVelocity.Y * this.ChangeVelocityScrolled;
1061
+ // a cancelled pointer (the browser took the pan to scroll the page, or a parent intercepted it) settles in place:
1062
+ // flinging from the few moves that arrived before the cancel would scroll the list while the page scrolls
1063
+ if (e.Type === "Cancelled") {
1064
+ vx = 0;
1065
+ vy = 0;
1066
+ }
863
1067
  let fling = false;
864
1068
  if (this.OverScrolled) {
865
1069
  const rest = this.ClampOffset(this.offsetX, this.offsetY, this.ContentOffsetBounds, true);
@@ -934,15 +1138,20 @@ export class SkiaScroll extends SkiaControl {
934
1138
  return true;
935
1139
  }
936
1140
  /**
937
- * One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs.
938
- * Notches arriving while the previous one is still animating add onto its target, so a fast wheel
939
- * spin travels N steps instead of restarting from the barely-moved current offset.
1141
+ * One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs. An event moves by its share
1142
+ * of a notch (Canvas.WheelDeltaPerNotch), so a touchpad's many small events scroll as far as the fingers moved (C#
1143
+ * aaa871c3); an event under half a notch moves the content at once (no glide). Events arriving while the previous one is still animating add onto its target, so a fast wheel spin
1144
+ * travels N steps instead of restarting from the barely-moved current offset.
940
1145
  */
941
1146
  ApplyWheelScroll(delta) {
942
- const step = SkiaScroll.WheelLineSize * -Math.sign(delta); // wheel down = content up = more negative offset
1147
+ const perNotch = this.Superview?.WheelDeltaPerNotch ?? 0;
1148
+ const lines = perNotch > 0 ? delta / perNotch : Math.sign(delta);
1149
+ const step = -SkiaScroll.WheelLineSize * lines; // wheel down = content up = more negative offset
943
1150
  const horizontal = this.Orientation === "Horizontal";
944
- const running = horizontal ? this.animatorFlingX : this.animatorFlingY;
945
- const base = running.IsRunning && running.Parameters ? running.Parameters.Destination : horizontal ? this.offsetX : this.offsetY;
1151
+ // the target the running wheel / ScrollTo move lands on: Parameters.Destination is where its deceleration curve would
1152
+ // end if it ran on, beyond that target, so continuing from it overshot more with every event (a touchpad swipe flew away)
1153
+ const running = horizontal ? this.animatorFlingX : this.animatorFlingY, target = horizontal ? this.scrollToTargetX : this.scrollToTargetY;
1154
+ const base = running.IsRunning && target !== null ? target : horizontal ? this.offsetX : this.offsetY;
946
1155
  const b = this.ContentOffsetBounds;
947
1156
  const min = horizontal ? b.Left : b.Top, max = horizontal ? b.Right : b.Bottom;
948
1157
  if ((step < 0 && base <= min) || (step > 0 && base >= max))
@@ -952,7 +1161,18 @@ export class SkiaScroll extends SkiaControl {
952
1161
  x = base + step;
953
1162
  else
954
1163
  y = base + step;
955
- this.ScrollTo(x, y, this.AutoScrollingSpeedMs / 1000, true);
1164
+ // a notch glides over AutoScrollingSpeedMs; smaller events (a touchpad, a free-spinning or high-resolution wheel) come
1165
+ // as a stream and move the content at once, as the browser scrolls a page: easing each one over 600 ms kept the
1166
+ // content behind the fingers, a visible delay before it started to move
1167
+ const glide = perNotch <= 0 || Math.abs(delta) >= perNotch / 2;
1168
+ this.ScrollTo(x, y, glide ? this.AutoScrollingSpeedMs / 1000 : 0, true);
1169
+ // a restarted glide starts at the event, not at its first frame: a fast trackpad swipe sends a notch-sized event
1170
+ // before every frame, and a glide drawn at progress 0 on each of them left the content standing still until the
1171
+ // events stopped, then it jumped (DrawnUi.Rust dfe36fe). Never before the last frame, at most one frame back.
1172
+ if (glide && running.IsRunning) {
1173
+ const event = performance.now() * 1_000_000;
1174
+ running.StartFrameTimeNanos = running.LastFrameTimeNanos = Math.max(this.Superview?.FrameTimeNanos ?? 0, event - 16_666_667);
1175
+ }
956
1176
  return true;
957
1177
  }
958
1178
  }