drawnui-react 0.1.0-preview.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +229 -22
- package/SKIPPED.md +38 -29
- package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
- package/dist/controls/AnimatedFramesRenderer.js +18 -1
- package/dist/controls/DrawnGame.d.ts +44 -0
- package/dist/controls/DrawnGame.js +82 -0
- package/dist/controls/GridStructure.d.ts +25 -3
- package/dist/controls/GridStructure.js +81 -5
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +17 -3
- package/dist/controls/SkiaButton.js +26 -8
- package/dist/controls/SkiaCarousel.d.ts +22 -3
- package/dist/controls/SkiaCarousel.js +85 -9
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +2 -7
- package/dist/controls/SkiaDrawer.d.ts +15 -0
- package/dist/controls/SkiaDrawer.js +42 -7
- package/dist/controls/SkiaEditor.d.ts +51 -2
- package/dist/controls/SkiaEditor.js +292 -58
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +10 -0
- package/dist/controls/SkiaImage.js +80 -19
- package/dist/controls/SkiaLabel.d.ts +200 -11
- package/dist/controls/SkiaLabel.js +925 -93
- package/dist/controls/SkiaLabelFps.d.ts +12 -0
- package/dist/controls/SkiaLabelFps.js +35 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +397 -23
- package/dist/controls/SkiaLottie.js +5 -3
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +8 -5
- package/dist/controls/SkiaRadioButton.d.ts +2 -0
- package/dist/controls/SkiaRadioButton.js +16 -4
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +86 -7
- package/dist/controls/SkiaScroll.js +361 -40
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
- package/dist/controls/SkiaShaderCarousel.js +27 -5
- package/dist/controls/SkiaShape.d.ts +15 -2
- package/dist/controls/SkiaShape.js +57 -10
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +61 -7
- package/dist/controls/SkiaSprite.d.ts +4 -0
- package/dist/controls/SkiaSprite.js +27 -11
- package/dist/controls/SkiaSvg.d.ts +4 -0
- package/dist/controls/SkiaSvg.js +28 -4
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +4 -8
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +21 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +162 -11
- package/dist/core/Accessibility.js +882 -22
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +307 -8
- package/dist/core/Canvas.js +1202 -66
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/DesignerActions.d.ts +32 -0
- package/dist/core/DesignerActions.js +68 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +86 -2
- package/dist/core/Gestures.js +184 -4
- package/dist/core/Hover.d.ts +51 -0
- package/dist/core/Hover.js +140 -0
- package/dist/core/ImageEffects.d.ts +2 -0
- package/dist/core/ImageEffects.js +2 -0
- package/dist/core/KeyboardManager.d.ts +40 -0
- package/dist/core/KeyboardManager.js +98 -8
- package/dist/core/PopupWindows.d.ts +94 -0
- package/dist/core/PopupWindows.js +207 -0
- package/dist/core/Props.d.ts +11 -0
- package/dist/core/Props.js +44 -0
- package/dist/core/ScrollAnimators.d.ts +6 -0
- package/dist/core/ScrollAnimators.js +16 -1
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +306 -13
- package/dist/core/SkiaControl.js +681 -75
- package/dist/core/SkiaEffect.d.ts +29 -1
- package/dist/core/SkiaEffect.js +78 -16
- package/dist/core/SkiaImageManager.d.ts +101 -18
- package/dist/core/SkiaImageManager.js +318 -63
- package/dist/core/Styles.js +7 -1
- package/dist/core/Super.d.ts +33 -2
- package/dist/core/Super.js +58 -12
- package/dist/core/TextInputProxy.d.ts +31 -1
- package/dist/core/TextInputProxy.js +97 -15
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -475
- package/dist/react/index.d.ts +48 -4
- package/dist/react/index.js +210 -43
- package/dist/react/reconciler.d.ts +32 -0
- package/dist/react/reconciler.js +71 -40
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +103 -5
|
@@ -9,10 +9,15 @@ 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;
|
|
16
|
+
/**
|
|
17
|
+
* Wheel events closer than this (ms) are one wheel gesture: they keep the scroll they started on, as browsers latch a
|
|
18
|
+
* scroller (C# SkiaScroll.WheelGestureGapMs, drawnui-cross 6bo).
|
|
19
|
+
*/
|
|
20
|
+
static WheelGestureGapMs = 300;
|
|
16
21
|
static ThesholdSwipeOnUp = 20;
|
|
17
22
|
static ScrollVelocityThreshold = 5;
|
|
18
23
|
Orientation = "Vertical";
|
|
@@ -28,23 +33,34 @@ export class SkiaScroll extends SkiaControl {
|
|
|
28
33
|
AutoScrollingSpeedMs = 600;
|
|
29
34
|
ScrollingSpeedMs = 400;
|
|
30
35
|
IgnoreWrongDirection = false;
|
|
31
|
-
|
|
36
|
+
respondsToGestures = true;
|
|
37
|
+
/** 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). */
|
|
38
|
+
get RespondsToGestures() { return this.respondsToGestures; }
|
|
39
|
+
set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
|
|
40
|
+
this.respondsToGestures = v;
|
|
41
|
+
this.NotifyAccessibility();
|
|
42
|
+
} }
|
|
43
|
+
AcceptsInput() { return this.respondsToGestures; }
|
|
32
44
|
// ---- header / footer (C# SkiaScroll.Header / Footer) ----
|
|
33
45
|
header;
|
|
34
46
|
footer;
|
|
35
47
|
/** A view before the content along the scroll axis; `Tag="Header"` on a JSX child sets it. */
|
|
36
48
|
get Header() { return this.header; }
|
|
37
49
|
set Header(v) { if (this.header === v)
|
|
38
|
-
return; if (this.header)
|
|
39
|
-
this.
|
|
50
|
+
return; if (this.header) {
|
|
51
|
+
this.Superview?.ControlLeft(this.header, false);
|
|
52
|
+
this.header.Parent = undefined;
|
|
53
|
+
} this.header = v; if (v) {
|
|
40
54
|
v.Parent = this;
|
|
41
55
|
v.ZIndex = 1;
|
|
42
56
|
} this.InvalidateMeasure(); }
|
|
43
57
|
/** A view after the content along the scroll axis; `Tag="Footer"` on a JSX child sets it. */
|
|
44
58
|
get Footer() { return this.footer; }
|
|
45
59
|
set Footer(v) { if (this.footer === v)
|
|
46
|
-
return; if (this.footer)
|
|
47
|
-
this.
|
|
60
|
+
return; if (this.footer) {
|
|
61
|
+
this.Superview?.ControlLeft(this.footer, false);
|
|
62
|
+
this.footer.Parent = undefined;
|
|
63
|
+
} this.footer = v; if (v)
|
|
48
64
|
v.Parent = this; this.InvalidateMeasure(); }
|
|
49
65
|
/** The header stays at the viewport start while the content scrolls under it (drawn over the content unless HeaderBehind). */
|
|
50
66
|
HeaderSticky = false;
|
|
@@ -121,7 +137,7 @@ export class SkiaScroll extends SkiaControl {
|
|
|
121
137
|
}
|
|
122
138
|
/** C# UpdateScrollBarIndicator: pushes progress / thumb ratio / overscroll / scrolling state when any changed. */
|
|
123
139
|
UpdateScrollBarIndicator() {
|
|
124
|
-
const isScrolling = this.IsScrolling || this.IsUserPanning;
|
|
140
|
+
const isScrolling = this.IsScrolling || this.IsUserPanning || !!this.draggedScrollBar;
|
|
125
141
|
const scale = this.RenderingScale;
|
|
126
142
|
const viewportH = this.DrawingRect.Height / scale, viewportW = this.DrawingRect.Width / scale;
|
|
127
143
|
const extentH = this.ContentSize.Units.Height + this.HeaderExtentPts + this.FooterExtentPts, extentW = this.ContentSize.Units.Width + this.HeaderExtentPts + this.FooterExtentPts;
|
|
@@ -158,8 +174,10 @@ export class SkiaScroll extends SkiaControl {
|
|
|
158
174
|
/** The pull-to-refresh view (IRefreshIndicator control); `Tag="RefreshIndicator"` on a JSX child sets it. */
|
|
159
175
|
get RefreshIndicator() { return this.refreshIndicator; }
|
|
160
176
|
set RefreshIndicator(v) { if (this.refreshIndicator === v)
|
|
161
|
-
return; if (this.refreshIndicator)
|
|
162
|
-
this.
|
|
177
|
+
return; if (this.refreshIndicator) {
|
|
178
|
+
this.Superview?.ControlLeft(this.refreshIndicator, false);
|
|
179
|
+
this.refreshIndicator.Parent = undefined;
|
|
180
|
+
} this.refreshIndicator = v; if (v)
|
|
163
181
|
v.Parent = this; this.InvalidateMeasure(); }
|
|
164
182
|
isRefreshing = false;
|
|
165
183
|
wasRefreshing = false;
|
|
@@ -333,6 +351,8 @@ export class SkiaScroll extends SkiaControl {
|
|
|
333
351
|
loadMoreTopArmed = false;
|
|
334
352
|
/** 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
353
|
CheckLoadMore() {
|
|
354
|
+
if (this.indexOrder)
|
|
355
|
+
return; // an open ScrollToIndex has the viewport on its way: the edges are looked at after it
|
|
336
356
|
const vertical = this.Orientation !== "Horizontal";
|
|
337
357
|
const offset = vertical ? this.offsetY : this.offsetX;
|
|
338
358
|
const min = vertical ? this.ContentOffsetBounds.Top : this.ContentOffsetBounds.Left; // most negative offset
|
|
@@ -373,6 +393,7 @@ export class SkiaScroll extends SkiaControl {
|
|
|
373
393
|
if (this.content === value)
|
|
374
394
|
return;
|
|
375
395
|
if (this.content) {
|
|
396
|
+
this.Superview?.ControlLeft(this.content, false);
|
|
376
397
|
this.content.Parent = undefined;
|
|
377
398
|
if (this.content instanceof SkiaLayout)
|
|
378
399
|
this.content.ItemsInsertedAtStart = undefined;
|
|
@@ -399,12 +420,19 @@ export class SkiaScroll extends SkiaControl {
|
|
|
399
420
|
set ViewportOffsetX(value) { if (this.offsetX !== value) {
|
|
400
421
|
this.offsetX = value;
|
|
401
422
|
this.OnScrolled();
|
|
423
|
+
this.OffsetJumped();
|
|
402
424
|
} }
|
|
403
425
|
get ViewportOffsetY() { return this.offsetY; }
|
|
404
426
|
set ViewportOffsetY(value) { if (this.offsetY !== value) {
|
|
405
427
|
this.offsetY = value;
|
|
406
428
|
this.OnScrolled();
|
|
429
|
+
this.OffsetJumped();
|
|
407
430
|
} }
|
|
431
|
+
/** An offset set without a glide or a pan (a jump, a touchpad step): the controls under a still mouse changed. */
|
|
432
|
+
OffsetJumped() { if (!this.MovesContent())
|
|
433
|
+
this.Superview?.Hover?.RequestCheck(); }
|
|
434
|
+
/** Hover waits while the content glides, flings, bounces or follows a pan (C# IsScrolling). */
|
|
435
|
+
MovesContent() { return this.IsScrolling || this.IsUserPanning || !!this.draggedScrollBar; }
|
|
408
436
|
animatorFlingX = new ScrollFlingAnimator(this);
|
|
409
437
|
animatorFlingY = new ScrollFlingAnimator(this);
|
|
410
438
|
bounceX = new SpringWithVelocityAnimator(this);
|
|
@@ -506,6 +534,7 @@ export class SkiaScroll extends SkiaControl {
|
|
|
506
534
|
}
|
|
507
535
|
InsertSubView(_index, control) { this.AddSubView(control); }
|
|
508
536
|
RemoveSubView(control) {
|
|
537
|
+
this.Superview?.Hover?.RequestCheck();
|
|
509
538
|
if (this.content === control)
|
|
510
539
|
this.Content = undefined;
|
|
511
540
|
else if (this.header === control)
|
|
@@ -548,17 +577,20 @@ export class SkiaScroll extends SkiaControl {
|
|
|
548
577
|
this.footerSize = this.footer && this.footer.IsVisible ? this.footer.Measure(widthConstraint, heightConstraint, scale) : ScaledSize.Default;
|
|
549
578
|
if (this.refreshIndicator)
|
|
550
579
|
this.refreshIndicator.Measure(widthConstraint, heightConstraint, scale);
|
|
580
|
+
// C# SetMeasuredAdaptToContentSize: the scroll's own size is its content's, up to the space it is given; a side with
|
|
581
|
+
// a request or Fill takes its box in Measure (NeedAutoWidth / NeedAutoHeight)
|
|
551
582
|
const extra = (this.HeaderExtentPts + this.FooterExtentPts) * scale;
|
|
552
|
-
const
|
|
553
|
-
const
|
|
554
|
-
return ScaledSize.FromPixels(
|
|
583
|
+
const cw = this.ContentSize.Pixels.Width + (this.Orientation === "Horizontal" ? extra : 0);
|
|
584
|
+
const ch = this.ContentSize.Pixels.Height + (this.Orientation !== "Horizontal" ? extra : 0);
|
|
585
|
+
return ScaledSize.FromPixels(Math.min(cw, widthConstraint), Math.min(ch, heightConstraint), scale);
|
|
555
586
|
}
|
|
556
587
|
OnLayoutChanged() {
|
|
557
588
|
const scale = this.RenderingScale;
|
|
558
589
|
const viewportW = this.DrawingRect.Width / scale, viewportH = this.DrawingRect.Height / scale;
|
|
559
590
|
const extra = this.HeaderExtentPts + this.FooterExtentPts;
|
|
560
591
|
const width = Math.max(0, this.ContentSize.Units.Width + (this.Orientation === "Horizontal" ? extra : 0) - viewportW);
|
|
561
|
-
|
|
592
|
+
// with the keyboard up (AdaptToKeyboardAuto), its cover of the viewport is room at the content end
|
|
593
|
+
const height = Math.max(0, this.ContentSize.Units.Height + (this.Orientation !== "Horizontal" ? extra + this.keyboardInset : 0) - viewportH);
|
|
562
594
|
this.ContentOffsetBounds = new SKRect(-width, -height, 0, 0);
|
|
563
595
|
// C# InitializeViewport: pull an offset the new bounds no longer contain back inside them, here where
|
|
564
596
|
// the bounds change. Shrinking content (fewer items) otherwise leaves the viewport parked past its end
|
|
@@ -572,6 +604,94 @@ export class SkiaScroll extends SkiaControl {
|
|
|
572
604
|
this.ArrangeContent();
|
|
573
605
|
this.CheckLoadMore();
|
|
574
606
|
}
|
|
607
|
+
// ---- the on-screen keyboard (C# SkiaScroll ScrollViewKeyboardAwareBehavior, drawnui-cross 6cj) ----
|
|
608
|
+
/**
|
|
609
|
+
* When true, the canvas keeps the focused text field of this scroll above the on-screen keyboard by itself (it sets
|
|
610
|
+
* AdaptToKeyboardFor and AdaptToKeyboardSize), and while the keyboard is up the part of the viewport it covers is room at
|
|
611
|
+
* the content end, so the last fields rise above it too. Off by default: an app that wires those two itself keeps doing so.
|
|
612
|
+
*/
|
|
613
|
+
AdaptToKeyboardAuto = false;
|
|
614
|
+
/** Points kept between the bottom of AdaptToKeyboardFor and the keyboard's top (8 by default). */
|
|
615
|
+
AdaptToKeyboardGap = 8;
|
|
616
|
+
adaptFor;
|
|
617
|
+
adaptSize = 0;
|
|
618
|
+
keyboardInset = 0;
|
|
619
|
+
adaptPending = false;
|
|
620
|
+
/** The field to keep above the keyboard (set by the app, or by the canvas with AdaptToKeyboardAuto). */
|
|
621
|
+
get AdaptToKeyboardFor() { return this.adaptFor; }
|
|
622
|
+
set AdaptToKeyboardFor(v) { if (this.adaptFor !== v) {
|
|
623
|
+
this.adaptFor = v;
|
|
624
|
+
this.AdaptToKeyboard();
|
|
625
|
+
} }
|
|
626
|
+
/** Points of the canvas, from its bottom, the keyboard covers (0 = no keyboard). */
|
|
627
|
+
get AdaptToKeyboardSize() { return this.adaptSize; }
|
|
628
|
+
set AdaptToKeyboardSize(v) { if (this.adaptSize !== v) {
|
|
629
|
+
this.adaptSize = v;
|
|
630
|
+
this.AdaptToKeyboard();
|
|
631
|
+
} }
|
|
632
|
+
/**
|
|
633
|
+
* After the keyboard or the focused field changed: scrolls so the field shows above the keyboard. A field already
|
|
634
|
+
* visible, or the keyboard closing, leaves the page where it is (the keyboard closing settles a page scrolled into the
|
|
635
|
+
* keyboard's room at the content end). One adaptation for the field and the size set together.
|
|
636
|
+
*/
|
|
637
|
+
AdaptToKeyboard() {
|
|
638
|
+
if (this.adaptPending)
|
|
639
|
+
return;
|
|
640
|
+
this.adaptPending = true;
|
|
641
|
+
setTimeout(() => {
|
|
642
|
+
this.adaptPending = false;
|
|
643
|
+
if (this.IsDisposed)
|
|
644
|
+
return;
|
|
645
|
+
this.UpdateKeyboardInset();
|
|
646
|
+
const to = this.CalculateNeededScrollForKeyboard();
|
|
647
|
+
if (!Number.isNaN(to)) {
|
|
648
|
+
this.ViewportOffsetY = to;
|
|
649
|
+
this.Repaint();
|
|
650
|
+
}
|
|
651
|
+
}, 150);
|
|
652
|
+
}
|
|
653
|
+
/** The keyboard's top in canvas points, from AdaptToKeyboardSize; NaN without one. */
|
|
654
|
+
KeyboardTopPts() {
|
|
655
|
+
const canvas = this.Superview;
|
|
656
|
+
if (!canvas || this.adaptSize <= 0)
|
|
657
|
+
return Number.NaN;
|
|
658
|
+
return canvas.Element.height / (this.RenderingScale || 1) - this.adaptSize;
|
|
659
|
+
}
|
|
660
|
+
UpdateKeyboardInset() {
|
|
661
|
+
let inset = 0;
|
|
662
|
+
const top = this.KeyboardTopPts();
|
|
663
|
+
if (this.AdaptToKeyboardAuto && !Number.isNaN(top) && this.Orientation === "Vertical") {
|
|
664
|
+
const covered = this.GetAccessibilityPixelRect().Bottom / (this.RenderingScale || 1) - top;
|
|
665
|
+
// the gap too: the last field rests that far above the keyboard
|
|
666
|
+
if (covered > 0)
|
|
667
|
+
inset = covered + Math.max(0, this.AdaptToKeyboardGap);
|
|
668
|
+
}
|
|
669
|
+
if (Math.abs(inset - this.keyboardInset) < 0.5)
|
|
670
|
+
return;
|
|
671
|
+
const shrinking = inset < this.keyboardInset;
|
|
672
|
+
this.keyboardInset = inset;
|
|
673
|
+
const viewportH = this.DrawingRect.Height / (this.RenderingScale || 1);
|
|
674
|
+
const height = Math.max(0, this.ContentSize.Units.Height + this.HeaderExtentPts + this.FooterExtentPts + inset - viewportH);
|
|
675
|
+
this.ContentOffsetBounds = new SKRect(this.ContentOffsetBounds.Left, -height, this.ContentOffsetBounds.Right, 0);
|
|
676
|
+
// the keyboard closed: content past the new end settles at the end, animated, as native scroll views do
|
|
677
|
+
if (shrinking && this.offsetY < -height && !this.IsUserPanning)
|
|
678
|
+
this.ScrollTo(this.offsetX, -height, this.AutoScrollingSpeedMs / 1000, true);
|
|
679
|
+
this.Repaint();
|
|
680
|
+
}
|
|
681
|
+
/** Where the scroll must go so the field's bottom sits AdaptToKeyboardGap above the keyboard; NaN = nothing to move. */
|
|
682
|
+
CalculateNeededScrollForKeyboard() {
|
|
683
|
+
const field = this.adaptFor, top = this.KeyboardTopPts();
|
|
684
|
+
if (!field || Number.isNaN(top) || !this.Superview)
|
|
685
|
+
return Number.NaN;
|
|
686
|
+
this.StopScrolling();
|
|
687
|
+
const k = this.RenderingScale || 1;
|
|
688
|
+
const f = field.GetAccessibilityPixelRect(), viewport = this.GetAccessibilityPixelRect();
|
|
689
|
+
if (f.Width <= 0 || f.Height <= 0)
|
|
690
|
+
return Number.NaN;
|
|
691
|
+
const visibleBottom = Math.min(viewport.Bottom, top * k);
|
|
692
|
+
const need = (f.Bottom - visibleBottom) / k + this.AdaptToKeyboardGap;
|
|
693
|
+
return need > 0 ? this.offsetY - need : Number.NaN;
|
|
694
|
+
}
|
|
575
695
|
/** Places Content at the current offset; called on layout and every frame while the offset moves. */
|
|
576
696
|
ArrangeContent() {
|
|
577
697
|
const c = this.content;
|
|
@@ -626,6 +746,8 @@ export class SkiaScroll extends SkiaControl {
|
|
|
626
746
|
}
|
|
627
747
|
}
|
|
628
748
|
Paint(ctx) {
|
|
749
|
+
this.Superview?.Hover?.RegisterMover(this);
|
|
750
|
+
this.PursueIndexOrder();
|
|
629
751
|
const c = this.content;
|
|
630
752
|
if (!c)
|
|
631
753
|
return;
|
|
@@ -646,9 +768,18 @@ export class SkiaScroll extends SkiaControl {
|
|
|
646
768
|
if (this.RefreshEnabled && this.refreshIndicator && this.refreshIndicator.IsVisible && (this.OverScrolled || this.isRefreshing))
|
|
647
769
|
this.refreshIndicator.Render(ctx);
|
|
648
770
|
this.UpdateScrollBarIndicator();
|
|
649
|
-
for (const bar of [this.scrollBar, this.scrollBarHorizontal])
|
|
650
|
-
if (bar
|
|
651
|
-
|
|
771
|
+
for (const bar of [this.scrollBar, this.scrollBarHorizontal]) {
|
|
772
|
+
if (!bar || !bar.IsVisible || bar.Opacity <= 0)
|
|
773
|
+
continue;
|
|
774
|
+
// the bar is parent-independent: its thumb resizing (squash on a bounce) invalidates the bar alone, so it is
|
|
775
|
+
// re-measured here on draw instead of dragging the scroll and every ancestor through a measure each frame
|
|
776
|
+
if (bar.NeedMeasure) {
|
|
777
|
+
const r = this.DrawingRect;
|
|
778
|
+
bar.Measure(r.Width, r.Height, this.RenderingScale);
|
|
779
|
+
bar.Arrange(r, bar.WidthRequest, bar.HeightRequest, this.RenderingScale);
|
|
780
|
+
}
|
|
781
|
+
bar.Render(ctx);
|
|
782
|
+
}
|
|
652
783
|
canvas.restoreToCount(saved);
|
|
653
784
|
}
|
|
654
785
|
OnScrolled() {
|
|
@@ -677,9 +808,11 @@ export class SkiaScroll extends SkiaControl {
|
|
|
677
808
|
/** Scroll to an offset in points; maxSpeedSecs > 0 animates along the deceleration curve. */
|
|
678
809
|
/**
|
|
679
810
|
* Scrolls every SkiaScroll ancestor of `control` so its DrawingRect lies inside the viewport (React extension,
|
|
680
|
-
* used by the accessibility overlay when keyboard focus lands on an off-screen node). Offsets are points.
|
|
811
|
+
* used by the accessibility overlay when keyboard focus lands on an off-screen node). Offsets are points. Returns the
|
|
812
|
+
* scrolls that move.
|
|
681
813
|
*/
|
|
682
814
|
static EnsureVisible(control, maxTimeSecs = 0.25, paddingPts = 8) {
|
|
815
|
+
const moved = [];
|
|
683
816
|
let p = control.Parent;
|
|
684
817
|
while (p) {
|
|
685
818
|
if (p instanceof SkiaScroll) {
|
|
@@ -694,11 +827,14 @@ export class SkiaScroll extends SkiaControl {
|
|
|
694
827
|
dx = (v.Left - r.Left) / scale + paddingPts;
|
|
695
828
|
else if (r.Right > v.Right)
|
|
696
829
|
dx = -((r.Right - v.Right) / scale + paddingPts);
|
|
697
|
-
if (dx !== 0 || dy !== 0)
|
|
830
|
+
if (dx !== 0 || dy !== 0) {
|
|
698
831
|
p.ScrollTo(p.offsetX + dx, p.offsetY + dy, maxTimeSecs);
|
|
832
|
+
moved.push(p);
|
|
833
|
+
}
|
|
699
834
|
}
|
|
700
835
|
p = p.Parent;
|
|
701
836
|
}
|
|
837
|
+
return moved;
|
|
702
838
|
}
|
|
703
839
|
/** Destination of the running ScrollTo per axis: the deceleration curve stops within its threshold, the exact value is applied when it finishes. */
|
|
704
840
|
scrollToTargetX = null;
|
|
@@ -719,6 +855,8 @@ export class SkiaScroll extends SkiaControl {
|
|
|
719
855
|
this.ViewportOffsetY = target;
|
|
720
856
|
}
|
|
721
857
|
ScrollTo(x, y, maxSpeedSecs, clamp = true) {
|
|
858
|
+
if (!this.pursuing)
|
|
859
|
+
this.indexOrder = undefined; // another scroll drops an open ScrollToIndex
|
|
722
860
|
this.StopAnimators(); // also forgets any pending edge bounce: a programmatic scroll never bounces
|
|
723
861
|
let tx = x, ty = y;
|
|
724
862
|
if (clamp) {
|
|
@@ -751,16 +889,82 @@ export class SkiaScroll extends SkiaControl {
|
|
|
751
889
|
else
|
|
752
890
|
this.ScrollTo(this.offsetX, this.ContentOffsetBounds.Top, maxTimeSecs);
|
|
753
891
|
}
|
|
754
|
-
StopScrolling() { this.StopAnimators(); this.IsUserPanning = false; }
|
|
892
|
+
StopScrolling() { this.indexOrder = undefined; this.StopAnimators(); this.IsUserPanning = false; }
|
|
755
893
|
/**
|
|
756
894
|
* Scrolls so that item `index` is at the viewport start (or end). Like DrawnUi, Content must BE the
|
|
757
895
|
* templated layout (the recycled list is the scroll's only child; a header goes above the scroll or in Header).
|
|
758
896
|
*/
|
|
759
897
|
ScrollToIndex(index, animate, option = "Start") {
|
|
898
|
+
this.indexOrder = { Index: index, Option: option, Secs: animate ? this.ScrollingSpeedMs / 1000 : 0, Stalled: 0 };
|
|
899
|
+
this.PursueIndexOrder();
|
|
900
|
+
this.Repaint();
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* An open ScrollToIndex (C# OrderedScrollToIndex, DrawnUi.Rust scroll_to_index): a row not measured yet is gone to by
|
|
904
|
+
* the sizes as they are estimated, and the order is aimed again every frame until the row has its real place and the
|
|
905
|
+
* viewport stands on it; an animated move goes on to a moved target in the time it has left, later corrections jump.
|
|
906
|
+
* A press, the wheel or another scroll drops it; while it is open LoadMore waits.
|
|
907
|
+
*/
|
|
908
|
+
indexOrder;
|
|
909
|
+
pursuing = false;
|
|
910
|
+
/** One step of the open order (C# ExecuteScrollToIndexOrder, Rust `pursue`), at the start of every paint. */
|
|
911
|
+
PursueIndexOrder() {
|
|
912
|
+
const order = this.indexOrder;
|
|
913
|
+
if (!order)
|
|
914
|
+
return;
|
|
915
|
+
const horizontal = this.Orientation === "Horizontal";
|
|
916
|
+
const before = horizontal ? this.offsetX : this.offsetY;
|
|
917
|
+
const running = horizontal ? this.animatorFlingX : this.animatorFlingY;
|
|
918
|
+
const aim = this.AimIndex(order.Index, order.Option);
|
|
919
|
+
let done = false;
|
|
920
|
+
if (aim) {
|
|
921
|
+
const c = this.ClampOffset(horizontal ? aim.Offset : this.offsetX, horizontal ? this.offsetY : aim.Offset, this.ContentOffsetBounds, true);
|
|
922
|
+
const target = horizontal ? c.X : c.Y;
|
|
923
|
+
const runningTo = horizontal ? this.scrollToTargetX : this.scrollToTargetY;
|
|
924
|
+
const move = (to, secs) => {
|
|
925
|
+
this.pursuing = true;
|
|
926
|
+
try {
|
|
927
|
+
this.ScrollTo(horizontal ? to : this.offsetX, horizontal ? this.offsetY : to, secs, true);
|
|
928
|
+
}
|
|
929
|
+
finally {
|
|
930
|
+
this.pursuing = false;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
if (running.IsRunning && runningTo !== null) {
|
|
934
|
+
if (Math.abs(runningTo - target) > 0.5) {
|
|
935
|
+
// on the way: the move goes on to the new target in the time it has left
|
|
936
|
+
const now = this.Superview?.FrameTimeNanos || performance.now() * 1_000_000;
|
|
937
|
+
move(target, running.StartFrameTimeNanos ? Math.max(0.016, running.Speed - (now - running.StartFrameTimeNanos) / 1e9) : running.Speed);
|
|
938
|
+
running.StartFrameTimeNanos = running.LastFrameTimeNanos = now;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
else if (Math.abs(before - target) <= 0.5) {
|
|
942
|
+
if (horizontal)
|
|
943
|
+
this.ViewportOffsetX = target;
|
|
944
|
+
else
|
|
945
|
+
this.ViewportOffsetY = target;
|
|
946
|
+
done = aim.Exact;
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
move(target, order.Secs);
|
|
950
|
+
order.Secs = 0;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
// no list yet, or a row that never gets its real place: not forever
|
|
954
|
+
order.Stalled = (horizontal ? this.offsetX : this.offsetY) === before && !running.IsRunning ? order.Stalled + 1 : 0;
|
|
955
|
+
if (done || order.Stalled >= 10) {
|
|
956
|
+
this.indexOrder = undefined;
|
|
957
|
+
this.CheckLoadMore();
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
this.Repaint(); // the next frame aims again
|
|
961
|
+
}
|
|
962
|
+
/** The offset (points) that puts item `index` where `option` says, by the sizes the list knows now; Exact = its place is measured. */
|
|
963
|
+
AimIndex(index, option) {
|
|
760
964
|
const layout = this.content instanceof SkiaLayout && this.content.IsTemplated ? this.content : undefined;
|
|
761
965
|
const items = layout?.ItemsSource;
|
|
762
966
|
if (!layout || !items || items.length === 0 || !this.content)
|
|
763
|
-
return;
|
|
967
|
+
return undefined;
|
|
764
968
|
const i = Math.max(0, Math.min(items.length - 1, index));
|
|
765
969
|
const scale = this.RenderingScale;
|
|
766
970
|
const horizontal = this.Orientation === "Horizontal";
|
|
@@ -775,10 +979,11 @@ export class SkiaScroll extends SkiaControl {
|
|
|
775
979
|
else {
|
|
776
980
|
// A templated Row / Wrap / Grid realizes every item (C# non-list layouts are not virtualized): read the cell's
|
|
777
981
|
// arranged rect, like C# reads the structure cell's Destination.
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
982
|
+
// recycled slots know every item's place, shown or not
|
|
983
|
+
const r = layout.GetItemRect(i) ?? layout.ChildrenFactory.GetViewForIndex(i)?.DrawingRect;
|
|
984
|
+
if (!r)
|
|
985
|
+
return undefined;
|
|
986
|
+
const c = this.content.DrawingRect;
|
|
782
987
|
itemStart = (horizontal ? r.Left - c.Left : r.Top - c.Top) / scale;
|
|
783
988
|
itemSize = (horizontal ? r.Width : r.Height) / scale;
|
|
784
989
|
}
|
|
@@ -787,11 +992,7 @@ export class SkiaScroll extends SkiaControl {
|
|
|
787
992
|
target -= viewport - itemSize;
|
|
788
993
|
else if (option === "Center")
|
|
789
994
|
target -= (viewport - itemSize) / 2;
|
|
790
|
-
|
|
791
|
-
if (horizontal)
|
|
792
|
-
this.ScrollTo(-target, this.offsetY, time, true);
|
|
793
|
-
else
|
|
794
|
-
this.ScrollTo(this.offsetX, -target, time, true);
|
|
995
|
+
return { Offset: -target, Exact: layout.IsItemMeasured(i) };
|
|
795
996
|
}
|
|
796
997
|
StopAnimators() {
|
|
797
998
|
this.flingEdgeX = null;
|
|
@@ -814,11 +1015,72 @@ export class SkiaScroll extends SkiaControl {
|
|
|
814
1015
|
this.panningLastDelta = SKPoint.Empty;
|
|
815
1016
|
this.panningCurrentOffsetPts = new SKPoint(this.offsetX, this.offsetY);
|
|
816
1017
|
}
|
|
1018
|
+
draggedScrollBar;
|
|
1019
|
+
scrollBarOwnsGesture = false;
|
|
1020
|
+
/** The gesture going on started on a draggable scroll bar: it is the bar's (a page text selection does not start there). */
|
|
1021
|
+
get ScrollBarOwnsGesture() { return this.scrollBarOwnsGesture; }
|
|
1022
|
+
/**
|
|
1023
|
+
* Thumb drag and track press on a ScrollBar / ScrollBarHorizontal with IsDraggable set (C# ProcessScrollBarGestures).
|
|
1024
|
+
* A gesture that starts on the bar belongs to it until the next down: the content neither pans nor gets the tap.
|
|
1025
|
+
* True when the gesture was handled here.
|
|
1026
|
+
*/
|
|
1027
|
+
ProcessScrollBarGestures(args, apply) {
|
|
1028
|
+
if (args.Type === "Down") {
|
|
1029
|
+
this.draggedScrollBar = undefined;
|
|
1030
|
+
this.scrollBarOwnsGesture = false;
|
|
1031
|
+
const draggable = (b) => b && b.IsDraggable && b.BeginDrag && b.GetDragProgress ? b : undefined;
|
|
1032
|
+
const v = draggable(this.scrollBar), h = draggable(this.scrollBarHorizontal);
|
|
1033
|
+
if (!v && !h)
|
|
1034
|
+
return false;
|
|
1035
|
+
const x = apply.MappedLocation.X + apply.ChildOffset.X, y = apply.MappedLocation.Y + apply.ChildOffset.Y;
|
|
1036
|
+
if (v && v.BeginDrag(x, y))
|
|
1037
|
+
this.draggedScrollBar = v;
|
|
1038
|
+
else if (h && h.BeginDrag(x, y))
|
|
1039
|
+
this.draggedScrollBar = h;
|
|
1040
|
+
if (!this.draggedScrollBar)
|
|
1041
|
+
return false;
|
|
1042
|
+
this.scrollBarOwnsGesture = true;
|
|
1043
|
+
this.StopScrolling();
|
|
1044
|
+
this.ApplyScrollBarDrag(x, y);
|
|
1045
|
+
args.Event.Handled = true; // used: a touch on the bar is claimed, the page must not take the drag
|
|
1046
|
+
return true;
|
|
1047
|
+
}
|
|
1048
|
+
if (!this.scrollBarOwnsGesture)
|
|
1049
|
+
return false;
|
|
1050
|
+
if (!this.draggedScrollBar)
|
|
1051
|
+
return args.Type === "Tapped" || args.Type === "LongPressing"; // released already: only the tap that follows belongs to the bar
|
|
1052
|
+
if (args.Type === "Panning") {
|
|
1053
|
+
this.ApplyScrollBarDrag(apply.MappedLocation.X + apply.ChildOffset.X, apply.MappedLocation.Y + apply.ChildOffset.Y);
|
|
1054
|
+
args.Event.Handled = true;
|
|
1055
|
+
}
|
|
1056
|
+
else if (args.Type === "Up") {
|
|
1057
|
+
this.draggedScrollBar = undefined;
|
|
1058
|
+
this.scrollBarLast = undefined; // push the idle state so an auto-hiding bar fades again
|
|
1059
|
+
this.scrollBarHLast = undefined;
|
|
1060
|
+
this.Repaint();
|
|
1061
|
+
}
|
|
1062
|
+
return true;
|
|
1063
|
+
}
|
|
1064
|
+
ApplyScrollBarDrag(x, y) {
|
|
1065
|
+
const bar = this.draggedScrollBar;
|
|
1066
|
+
if (!bar)
|
|
1067
|
+
return;
|
|
1068
|
+
const progress = bar.GetDragProgress(x, y);
|
|
1069
|
+
const b = this.ContentOffsetBounds;
|
|
1070
|
+
if (bar === this.scrollBarHorizontal)
|
|
1071
|
+
this.ViewportOffsetX = this.ClampOffset(-progress * b.Width, this.offsetY, b, true).X;
|
|
1072
|
+
else
|
|
1073
|
+
this.ViewportOffsetY = this.ClampOffset(this.offsetX, -progress * b.Height, b, true).Y;
|
|
1074
|
+
this.Repaint();
|
|
1075
|
+
}
|
|
817
1076
|
ProcessGestures(args, apply) {
|
|
818
1077
|
const consumedDefault = this.BlockGesturesBelow ? this : null;
|
|
819
1078
|
const scale = this.RenderingScale;
|
|
820
1079
|
const e = args.Event;
|
|
1080
|
+
if (this.ProcessScrollBarGestures(args, apply))
|
|
1081
|
+
return this;
|
|
821
1082
|
if (args.Type === "Down") {
|
|
1083
|
+
this.indexOrder = undefined; // a press drops an open ScrollToIndex
|
|
822
1084
|
this.hadDown = true;
|
|
823
1085
|
this.snapped = false;
|
|
824
1086
|
if (this.RespondsToGestures) {
|
|
@@ -828,14 +1090,26 @@ export class SkiaScroll extends SkiaControl {
|
|
|
828
1090
|
return super.ProcessGestures(args, apply) ?? consumedDefault; // children see Down (buttons press)
|
|
829
1091
|
}
|
|
830
1092
|
if (args.Type === "Wheel") {
|
|
1093
|
+
// one wheel gesture keeps the scroll it started on (6bo): a scroll inside this one that took it keeps it, also at
|
|
1094
|
+
// its end (the page waits for the next gesture); one this scroll took is not given to a list that comes under the pointer
|
|
1095
|
+
const now = performance.now(), latch = SkiaScroll.wheelLatch;
|
|
1096
|
+
const latched = latch && now - latch.At < SkiaScroll.WheelGestureGapMs && !latch.Scroll.IsDisposed && latch.Scroll.Superview ? latch.Scroll : undefined;
|
|
1097
|
+
if (latched && latched !== this && SkiaScroll.Contains(this, latched)) {
|
|
1098
|
+
latch.At = now;
|
|
1099
|
+
if (latched.WheelUsable(e.Wheel.IsHorizontal))
|
|
1100
|
+
latched.ApplyWheelScroll(e.Wheel.Delta);
|
|
1101
|
+
e.Handled = true;
|
|
1102
|
+
return latched;
|
|
1103
|
+
}
|
|
831
1104
|
// a nested scroll under the pointer takes the wheel first; the outer one scrolls when the inner is at its edge
|
|
832
|
-
const child = super.ProcessGestures(args, apply);
|
|
1105
|
+
const child = latched === this ? null : super.ProcessGestures(args, apply);
|
|
833
1106
|
if (child && child !== this)
|
|
834
1107
|
return child;
|
|
835
|
-
if (!this.
|
|
836
|
-
return child ?? consumedDefault;
|
|
1108
|
+
if (!this.WheelUsable(e.Wheel.IsHorizontal))
|
|
1109
|
+
return child ?? consumedDefault; // not used, a parent scroll may take it
|
|
837
1110
|
if (!this.ApplyWheelScroll(e.Wheel.Delta))
|
|
838
1111
|
return consumedDefault; // at its edge: not used, the page may take it
|
|
1112
|
+
SkiaScroll.wheelLatch = { Scroll: this, At: now };
|
|
839
1113
|
e.Handled = true;
|
|
840
1114
|
return this;
|
|
841
1115
|
}
|
|
@@ -843,7 +1117,7 @@ export class SkiaScroll extends SkiaControl {
|
|
|
843
1117
|
this.velocityX = e.Distance.Velocity.X / scale;
|
|
844
1118
|
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) ||
|
|
845
1119
|
(this.Orientation === "Horizontal" && Math.abs(e.Distance.Total.Y) > Math.abs(e.Distance.Total.X) && Math.abs(e.Distance.Total.Y) > SkiaScroll.ScrollVelocityThreshold * scale);
|
|
846
|
-
if (args.Type === "Panning" && this.RespondsToGestures && this.hadDown) {
|
|
1120
|
+
if (args.Type === "Panning" && this.RespondsToGestures && this.hadDown && this.Orientation !== "Neither") {
|
|
847
1121
|
if (!this.IsUserPanning) {
|
|
848
1122
|
// A child may own the pan (slider, nested horizontal scroll); ask once before taking over.
|
|
849
1123
|
const childConsumed = super.ProcessGestures(args, apply);
|
|
@@ -860,6 +1134,8 @@ export class SkiaScroll extends SkiaControl {
|
|
|
860
1134
|
const v = this.Orientation === "Vertical" ? this.velocityY : this.Orientation === "Horizontal" ? this.velocityX : Math.max(Math.abs(this.velocityX), Math.abs(this.velocityY));
|
|
861
1135
|
if (Math.abs(v) <= SkiaScroll.ScrollVelocityThreshold)
|
|
862
1136
|
return consumedDefault;
|
|
1137
|
+
if (this.LeavesDragToOuter(e.Distance.Total))
|
|
1138
|
+
return null; // not used: the scroll around it takes the whole drag
|
|
863
1139
|
}
|
|
864
1140
|
if (!this.IsUserFocused)
|
|
865
1141
|
this.ResetPan();
|
|
@@ -974,15 +1250,49 @@ export class SkiaScroll extends SkiaControl {
|
|
|
974
1250
|
return true;
|
|
975
1251
|
}
|
|
976
1252
|
/**
|
|
977
|
-
* One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs.
|
|
978
|
-
*
|
|
979
|
-
*
|
|
1253
|
+
* One wheel notch = WheelLineSize points, hard-clamped, animated over AutoScrollingSpeedMs. An event moves by its share
|
|
1254
|
+
* of a notch (Canvas.WheelDeltaPerNotch), so a touchpad's many small events scroll as far as the fingers moved (C#
|
|
1255
|
+
* 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
|
|
1256
|
+
* travels N steps instead of restarting from the barely-moved current offset.
|
|
1257
|
+
*/
|
|
1258
|
+
/**
|
|
1259
|
+
* drawnui-cross 6bo (DrawnUi.Rust leaves_drag_to_outer), asked once, when this scroll would take a drag: already at its
|
|
1260
|
+
* end in the drag's direction (at its start dragged back, at its end dragged on) with a scroll around it moving on the
|
|
1261
|
+
* same axis, the outer scroll takes the whole drag. Never toward the start with pull to refresh on; a scroll with nothing
|
|
1262
|
+
* around it keeps its edge bounce. Otherwise this scroll keeps the drag to its end.
|
|
980
1263
|
*/
|
|
1264
|
+
LeavesDragToOuter(total) {
|
|
1265
|
+
const vertical = this.Orientation === "Vertical" || (this.Orientation === "Both" && Math.abs(total.Y) >= Math.abs(total.X));
|
|
1266
|
+
const d = vertical ? total.Y : total.X; // finger down / right = toward the start (offset grows to 0)
|
|
1267
|
+
if (d === 0 || (d > 0 && this.RefreshEnabled))
|
|
1268
|
+
return false;
|
|
1269
|
+
const b = this.ContentOffsetBounds;
|
|
1270
|
+
const offset = vertical ? this.offsetY : this.offsetX;
|
|
1271
|
+
if (d > 0 ? offset < (vertical ? b.Bottom : b.Right) : offset > (vertical ? b.Top : b.Left))
|
|
1272
|
+
return false;
|
|
1273
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1274
|
+
if (p instanceof SkiaScroll && p.RespondsToGestures && p.Orientation !== "Neither" && p.Orientation !== (vertical ? "Horizontal" : "Vertical"))
|
|
1275
|
+
return true;
|
|
1276
|
+
return false;
|
|
1277
|
+
}
|
|
1278
|
+
static Contains(root, c) { for (let p = c.Parent; p; p = p.Parent)
|
|
1279
|
+
if (p === root)
|
|
1280
|
+
return true; return false; }
|
|
1281
|
+
/** The scroll the current wheel gesture belongs to, and its last event time. */
|
|
1282
|
+
static wheelLatch;
|
|
1283
|
+
/** It scrolls with the wheel on this axis (a vertical scroll leaves the sideways part of a diagonal swipe to what is around it). */
|
|
1284
|
+
WheelUsable(horizontal) {
|
|
1285
|
+
return this.RespondsToGestures && this.Orientation !== "Neither" && !(horizontal && this.Orientation === "Vertical");
|
|
1286
|
+
}
|
|
981
1287
|
ApplyWheelScroll(delta) {
|
|
982
|
-
const
|
|
1288
|
+
const perNotch = this.Superview?.WheelDeltaPerNotch ?? 0;
|
|
1289
|
+
const lines = perNotch > 0 ? delta / perNotch : Math.sign(delta);
|
|
1290
|
+
const step = -SkiaScroll.WheelLineSize * lines; // wheel down = content up = more negative offset
|
|
983
1291
|
const horizontal = this.Orientation === "Horizontal";
|
|
984
|
-
|
|
985
|
-
|
|
1292
|
+
// the target the running wheel / ScrollTo move lands on: Parameters.Destination is where its deceleration curve would
|
|
1293
|
+
// end if it ran on, beyond that target, so continuing from it overshot more with every event (a touchpad swipe flew away)
|
|
1294
|
+
const running = horizontal ? this.animatorFlingX : this.animatorFlingY, target = horizontal ? this.scrollToTargetX : this.scrollToTargetY;
|
|
1295
|
+
const base = running.IsRunning && target !== null ? target : horizontal ? this.offsetX : this.offsetY;
|
|
986
1296
|
const b = this.ContentOffsetBounds;
|
|
987
1297
|
const min = horizontal ? b.Left : b.Top, max = horizontal ? b.Right : b.Bottom;
|
|
988
1298
|
if ((step < 0 && base <= min) || (step > 0 && base >= max))
|
|
@@ -992,7 +1302,18 @@ export class SkiaScroll extends SkiaControl {
|
|
|
992
1302
|
x = base + step;
|
|
993
1303
|
else
|
|
994
1304
|
y = base + step;
|
|
995
|
-
|
|
1305
|
+
// a notch glides over AutoScrollingSpeedMs; smaller events (a touchpad, a free-spinning or high-resolution wheel) come
|
|
1306
|
+
// as a stream and move the content at once, as the browser scrolls a page: easing each one over 600 ms kept the
|
|
1307
|
+
// content behind the fingers, a visible delay before it started to move
|
|
1308
|
+
const glide = perNotch <= 0 || Math.abs(delta) >= perNotch / 2;
|
|
1309
|
+
this.ScrollTo(x, y, glide ? this.AutoScrollingSpeedMs / 1000 : 0, true);
|
|
1310
|
+
// a restarted glide starts at the event, not at its first frame: a fast trackpad swipe sends a notch-sized event
|
|
1311
|
+
// before every frame, and a glide drawn at progress 0 on each of them left the content standing still until the
|
|
1312
|
+
// events stopped, then it jumped (DrawnUi.Rust dfe36fe). Never before the last frame, at most one frame back.
|
|
1313
|
+
if (glide && running.IsRunning) {
|
|
1314
|
+
const event = performance.now() * 1_000_000;
|
|
1315
|
+
running.StartFrameTimeNanos = running.LastFrameTimeNanos = Math.max(this.Superview?.FrameTimeNanos ?? 0, event - 16_666_667);
|
|
1316
|
+
}
|
|
996
1317
|
return true;
|
|
997
1318
|
}
|
|
998
1319
|
}
|