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.
- package/README.md +119 -14
- package/SKIPPED.md +36 -26
- 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 +16 -2
- package/dist/controls/GridStructure.js +40 -4
- 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 +48 -2
- package/dist/controls/SkiaEditor.js +268 -53
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +48 -14
- package/dist/controls/SkiaLabel.d.ts +117 -9
- package/dist/controls/SkiaLabel.js +526 -80
- package/dist/controls/SkiaLabelFps.d.ts +16 -0
- package/dist/controls/SkiaLabelFps.js +41 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +364 -21
- 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 +35 -5
- package/dist/controls/SkiaScroll.js +252 -32
- 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 +13 -2
- package/dist/controls/SkiaShape.js +50 -10
- 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 +22 -10
- 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 +134 -0
- package/dist/core/Accessibility.js +675 -9
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +222 -10
- package/dist/core/Canvas.js +698 -37
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +81 -2
- package/dist/core/Gestures.js +177 -3
- 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 +205 -0
- package/dist/core/ScrollAnimators.js +9 -0
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +279 -10
- package/dist/core/SkiaControl.js +621 -64
- package/dist/core/SkiaEffect.d.ts +17 -0
- package/dist/core/SkiaEffect.js +43 -8
- package/dist/core/SkiaImageManager.js +1 -1
- package/dist/core/Super.d.ts +29 -2
- package/dist/core/Super.js +54 -3
- 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 +6 -0
- package/dist/index.js +6 -0
- package/dist/react/SkiaShell.js +65 -26
- package/dist/react/index.d.ts +33 -4
- package/dist/react/index.js +157 -18
- package/dist/react/reconciler.d.ts +20 -0
- package/dist/react/reconciler.js +69 -14
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +61 -2
|
@@ -11,6 +11,12 @@ export type ScrollBarDock = "End" | "Start";
|
|
|
11
11
|
*/
|
|
12
12
|
export interface IScrollBar {
|
|
13
13
|
SetScrollProgress(orientation: ScrollOrientation, progress: number, thumbSizeRatio: number, overscrollPts: number, isScrolling: boolean): void;
|
|
14
|
+
/** Optional desktop behavior: the bar takes the gesture that starts on it (thumb drag, track press). */
|
|
15
|
+
IsDraggable?: boolean;
|
|
16
|
+
/** Canvas pixels; true when the point is on the bar and a drag starts. */
|
|
17
|
+
BeginDrag?(x: number, y: number): boolean;
|
|
18
|
+
/** Scroll progress 0..1 for the pointer during a drag started by BeginDrag. */
|
|
19
|
+
GetDragProgress?(x: number, y: number): number;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Mirrors DrawnUi SkiaScrollBar: thin rounded thumb over an optional track, docked at the right edge for vertical
|
|
@@ -41,6 +47,19 @@ export declare class SkiaScrollBar extends SkiaLayout implements IScrollBar {
|
|
|
41
47
|
/** Fade out after scrolling stops. */
|
|
42
48
|
AutoHide: boolean;
|
|
43
49
|
HideDelaySecs: number;
|
|
50
|
+
/** Duration in seconds of the fade-out once HideDelaySecs has passed. */
|
|
51
|
+
HideDurationSecs: number;
|
|
52
|
+
/**
|
|
53
|
+
* Lets the user drag the thumb and press the track to jump there (desktop scroll bar behavior). The owning
|
|
54
|
+
* SkiaScroll then takes the whole gesture, from down to up, when it starts on the bar. Default false: the bar only
|
|
55
|
+
* indicates and every gesture passes through to the content.
|
|
56
|
+
*/
|
|
57
|
+
IsDraggable: boolean;
|
|
58
|
+
/** Extra grab area in points on both sides of the bar, across the scrolling axis, so a thin bar is easy to hit with a mouse. */
|
|
59
|
+
GrabPadding: number;
|
|
60
|
+
private thumbOffsetPts;
|
|
61
|
+
private dragGrabPx;
|
|
62
|
+
private hasTravel;
|
|
44
63
|
protected readonly thumb: SkiaShape;
|
|
45
64
|
protected readonly track: SkiaShape;
|
|
46
65
|
private hideTimer;
|
|
@@ -52,5 +71,13 @@ export declare class SkiaScrollBar extends SkiaLayout implements IScrollBar {
|
|
|
52
71
|
protected ApplyOrientation(): void;
|
|
53
72
|
SetScrollProgress(orientation: ScrollOrientation, progress: number, thumbSizeRatio: number, overscrollPts: number, isScrolling: boolean): void;
|
|
54
73
|
private CancelHide;
|
|
74
|
+
/**
|
|
75
|
+
* Called by the owning scroll on touch down, coordinates in canvas pixels. True when the point is on the bar (track
|
|
76
|
+
* plus GrabPadding) and a drag starts: on the thumb it keeps the grab point, on the track the thumb jumps to center
|
|
77
|
+
* under the pointer.
|
|
78
|
+
*/
|
|
79
|
+
BeginDrag(x: number, y: number): boolean;
|
|
80
|
+
/** Scroll progress 0..1 for the pointer position during a drag started by BeginDrag, coordinates in canvas pixels. */
|
|
81
|
+
GetDragProgress(x: number, y: number): number;
|
|
55
82
|
protected OnDisposing(): void;
|
|
56
83
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Colors, Thickness } from "../core/Types";
|
|
1
|
+
import { Colors, SKRect, Thickness } from "../core/Types";
|
|
2
2
|
import { SkiaLayout } from "./SkiaLayout";
|
|
3
3
|
import { SkiaShape } from "./SkiaShape";
|
|
4
4
|
/**
|
|
@@ -49,6 +49,19 @@ export class SkiaScrollBar extends SkiaLayout {
|
|
|
49
49
|
/** Fade out after scrolling stops. */
|
|
50
50
|
AutoHide = true;
|
|
51
51
|
HideDelaySecs = 1;
|
|
52
|
+
/** Duration in seconds of the fade-out once HideDelaySecs has passed. */
|
|
53
|
+
HideDurationSecs = 0.25;
|
|
54
|
+
/**
|
|
55
|
+
* Lets the user drag the thumb and press the track to jump there (desktop scroll bar behavior). The owning
|
|
56
|
+
* SkiaScroll then takes the whole gesture, from down to up, when it starts on the bar. Default false: the bar only
|
|
57
|
+
* indicates and every gesture passes through to the content.
|
|
58
|
+
*/
|
|
59
|
+
IsDraggable = false;
|
|
60
|
+
/** Extra grab area in points on both sides of the bar, across the scrolling axis, so a thin bar is easy to hit with a mouse. */
|
|
61
|
+
GrabPadding = 8;
|
|
62
|
+
thumbOffsetPts = 0;
|
|
63
|
+
dragGrabPx = 0;
|
|
64
|
+
hasTravel = false;
|
|
52
65
|
thumb = new SkiaShape();
|
|
53
66
|
track = new SkiaShape();
|
|
54
67
|
hideTimer = 0;
|
|
@@ -62,6 +75,7 @@ export class SkiaScrollBar extends SkiaLayout {
|
|
|
62
75
|
this.HorizontalOptions = "Fill";
|
|
63
76
|
this.VerticalOptions = "Fill";
|
|
64
77
|
this.InputTransparent = true; // display only, gestures pass through
|
|
78
|
+
this.IsParentIndependent = true; // the bar's look (thumb squashed on overscroll) never changes the layout around it
|
|
65
79
|
this.Opacity = 0; // hidden until the first scroll
|
|
66
80
|
this.track.Type = "Rectangle";
|
|
67
81
|
this.track.BackgroundColor = this.trackColor;
|
|
@@ -127,6 +141,8 @@ export class SkiaScrollBar extends SkiaLayout {
|
|
|
127
141
|
thumbLen = Math.max(this.MinThumbSize / 2, thumbLen - Math.abs(overscrollPts)); // squash on bounce
|
|
128
142
|
const travel = track - thumbLen;
|
|
129
143
|
const offset = Math.max(0, Math.min(1, progress)) * travel;
|
|
144
|
+
this.thumbOffsetPts = offset;
|
|
145
|
+
this.hasTravel = travel > 0;
|
|
130
146
|
if (Math.abs(thumbLen - this.lastThumbLen) > 0.5) {
|
|
131
147
|
this.lastThumbLen = thumbLen;
|
|
132
148
|
if (orientation === "Horizontal")
|
|
@@ -142,7 +158,7 @@ export class SkiaScrollBar extends SkiaLayout {
|
|
|
142
158
|
this.CancelHide();
|
|
143
159
|
this.Opacity = 1;
|
|
144
160
|
if (this.AutoHide && !isScrolling) {
|
|
145
|
-
this.hideTimer = window.setTimeout(() => { this.hideTimer = 0; this.hideAbort = new AbortController(); void this.FadeToAsync(0,
|
|
161
|
+
this.hideTimer = window.setTimeout(() => { this.hideTimer = 0; this.hideAbort = new AbortController(); void this.FadeToAsync(0, Math.max(0, this.HideDurationSecs * 1000), undefined, this.hideAbort.signal); }, this.HideDelaySecs * 1000);
|
|
146
162
|
}
|
|
147
163
|
this.RepaintComposition();
|
|
148
164
|
}
|
|
@@ -154,5 +170,38 @@ export class SkiaScrollBar extends SkiaLayout {
|
|
|
154
170
|
this.hideAbort?.abort();
|
|
155
171
|
this.hideAbort = undefined;
|
|
156
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Called by the owning scroll on touch down, coordinates in canvas pixels. True when the point is on the bar (track
|
|
175
|
+
* plus GrabPadding) and a drag starts: on the thumb it keeps the grab point, on the track the thumb jumps to center
|
|
176
|
+
* under the pointer.
|
|
177
|
+
*/
|
|
178
|
+
BeginDrag(x, y) {
|
|
179
|
+
if (!this.IsDraggable || !this.hasTravel)
|
|
180
|
+
return false;
|
|
181
|
+
const scale = this.RenderingScale || 1;
|
|
182
|
+
const track = this.track.DrawingRect;
|
|
183
|
+
const pad = this.GrabPadding * scale;
|
|
184
|
+
const vertical = this.orientation !== "Horizontal";
|
|
185
|
+
const hit = vertical ? new SKRect(track.Left - pad, track.Top, track.Right + pad, track.Bottom) : new SKRect(track.Left, track.Top - pad, track.Right, track.Bottom + pad);
|
|
186
|
+
if (x < hit.Left || x > hit.Right || y < hit.Top || y > hit.Bottom)
|
|
187
|
+
return false;
|
|
188
|
+
// an auto-hidden bar that gets grabbed shows again right away: never drag something invisible
|
|
189
|
+
this.CancelHide();
|
|
190
|
+
this.Opacity = 1;
|
|
191
|
+
const pos = vertical ? y - track.Top : x - track.Left;
|
|
192
|
+
const thumbStart = this.thumbOffsetPts * scale, thumbLen = this.lastThumbLen * scale;
|
|
193
|
+
this.dragGrabPx = pos >= thumbStart && pos <= thumbStart + thumbLen ? pos - thumbStart : thumbLen / 2;
|
|
194
|
+
this.RepaintComposition();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
/** Scroll progress 0..1 for the pointer position during a drag started by BeginDrag, coordinates in canvas pixels. */
|
|
198
|
+
GetDragProgress(x, y) {
|
|
199
|
+
const scale = this.RenderingScale || 1;
|
|
200
|
+
const track = this.track.DrawingRect;
|
|
201
|
+
const vertical = this.orientation !== "Horizontal";
|
|
202
|
+
const pos = (vertical ? y - track.Top : x - track.Left) - this.dragGrabPx;
|
|
203
|
+
const travel = (vertical ? track.Height : track.Width) - this.lastThumbLen * scale;
|
|
204
|
+
return travel > 0 ? Math.max(0, Math.min(1, pos / travel)) : 0;
|
|
205
|
+
}
|
|
157
206
|
OnDisposing() { this.CancelHide(); super.OnDisposing(); }
|
|
158
207
|
}
|
|
@@ -56,6 +56,11 @@ export declare class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
56
56
|
protected OnScrollProgressChanged(): void;
|
|
57
57
|
/** Slides never move: the transition effect renders the change (C# AnimateVisibleChild no-op). */
|
|
58
58
|
protected SlideOffset(_offset: SKPoint): SKPoint;
|
|
59
|
+
/**
|
|
60
|
+
* Slides all sit on the same rect, so only the selected one may take gestures: otherwise the topmost slide in the
|
|
61
|
+
* gesture list (the last on-screen one, a neighbour exactly one width away counts as on screen) caught every tap.
|
|
62
|
+
*/
|
|
63
|
+
protected IsSlideHitTestable(index: number): boolean;
|
|
59
64
|
ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
|
|
60
65
|
/**
|
|
61
66
|
* Gesture targeting (C#): one gesture moves at most one slide from the slide it started on; a flick moves one slide
|
|
@@ -63,5 +68,10 @@ export declare class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
63
68
|
* first wraps that transition up within InterruptedTransitionMs, then the new one plays.
|
|
64
69
|
*/
|
|
65
70
|
protected ScrollToOffset(targetOffset: SKPoint, velocity: SKPoint, animate: boolean): boolean;
|
|
66
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Phase 2 of an interrupted swipe starts here, the moment phase 1 arrives, so the carousel never reports a stop between
|
|
73
|
+
* the two phases: InTransition stays true and Stopped fires once, at real rest (C# f4628b7e, drawnui-cross 6y). A stop in
|
|
74
|
+
* between let an app move its slides there, and the queued raw offset then replayed in the new slides.
|
|
75
|
+
*/
|
|
76
|
+
CheckTransitionEnded(): boolean;
|
|
67
77
|
}
|
|
@@ -83,6 +83,7 @@ export class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
83
83
|
return super.MeasureAbsolute(w, h, scale);
|
|
84
84
|
}
|
|
85
85
|
OnChildrenInitialized() {
|
|
86
|
+
this.pendingTarget = undefined; // new slides: an offset queued for the old ones means nothing here
|
|
86
87
|
this.indexFrom = -1;
|
|
87
88
|
this.indexTo = -1;
|
|
88
89
|
this.indexFromLast = -1;
|
|
@@ -145,6 +146,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
145
146
|
}
|
|
146
147
|
/** Slides never move: the transition effect renders the change (C# AnimateVisibleChild no-op). */
|
|
147
148
|
SlideOffset(_offset) { return SKPoint.Empty; }
|
|
149
|
+
/**
|
|
150
|
+
* Slides all sit on the same rect, so only the selected one may take gestures: otherwise the topmost slide in the
|
|
151
|
+
* gesture list (the last on-screen one, a neighbour exactly one width away counts as on screen) caught every tap.
|
|
152
|
+
*/
|
|
153
|
+
IsSlideHitTestable(index) { return index === this.SelectedIndex; }
|
|
148
154
|
ProcessGestures(args, apply) {
|
|
149
155
|
if (args.Type === "Down") {
|
|
150
156
|
const interrupted = this.InTransition;
|
|
@@ -174,6 +180,10 @@ export class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
174
180
|
* first wraps that transition up within InterruptedTransitionMs, then the new one plays.
|
|
175
181
|
*/
|
|
176
182
|
ScrollToOffset(targetOffset, velocity, animate) {
|
|
183
|
+
// a real move by code (ScrollTo, SelectedIndex, GoNext / GoPrev) drops a queued phase 2: its raw offset would replay
|
|
184
|
+
// over that move; the carousel's own echo of its index (a target already at CurrentSnap) is not a move and keeps it
|
|
185
|
+
if (!this.inGestureRelease && (targetOffset.X !== this.CurrentSnap.X || targetOffset.Y !== this.CurrentSnap.Y))
|
|
186
|
+
this.pendingTarget = undefined;
|
|
177
187
|
if (!this.inGestureRelease || !animate || this.SnapPoints.length < 2)
|
|
178
188
|
return super.ScrollToOffset(targetOffset, velocity, animate);
|
|
179
189
|
const axis = (p) => (this.IsVertical ? p.Y : p.X);
|
|
@@ -198,6 +208,11 @@ export class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
198
208
|
if (!this.wasInTransitionAtDown)
|
|
199
209
|
return super.ScrollToOffset(targetOffset, velocity, animate);
|
|
200
210
|
this.wasInTransitionAtDown = false;
|
|
211
|
+
// a swipe back against the interrupted transition goes straight to its slide: wrapping that transition up first ran
|
|
212
|
+
// it on to its end and then back, a visible jump forward and back (C# b75f233a)
|
|
213
|
+
const heading = axis(this.gestureOrigin) - axis(this.gestureFrom), turn = axis(targetOffset) - axis(this.gestureOrigin);
|
|
214
|
+
if (heading !== 0 && turn !== 0 && Math.sign(heading) !== Math.sign(turn))
|
|
215
|
+
return super.ScrollToOffset(targetOffset, velocity, animate);
|
|
201
216
|
// the pan may already have carried the position PAST the interrupted transition's destination toward the new
|
|
202
217
|
// target: wrapping it up would animate backward first. Only run phase 1 while that destination is still ahead.
|
|
203
218
|
const toOrigin = axis(this.gestureOrigin) - axis(this.CurrentPosition);
|
|
@@ -234,13 +249,20 @@ export class SkiaShaderCarousel extends SkiaCarousel {
|
|
|
234
249
|
}
|
|
235
250
|
return started;
|
|
236
251
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Phase 2 of an interrupted swipe starts here, the moment phase 1 arrives, so the carousel never reports a stop between
|
|
254
|
+
* the two phases: InTransition stays true and Stopped fires once, at real rest (C# f4628b7e, drawnui-cross 6y). A stop in
|
|
255
|
+
* between let an app move its slides there, and the queued raw offset then replayed in the new slides.
|
|
256
|
+
*/
|
|
257
|
+
CheckTransitionEnded() {
|
|
258
|
+
const ended = super.CheckTransitionEnded();
|
|
240
259
|
const next = this.pendingTarget;
|
|
241
|
-
if (
|
|
260
|
+
if (ended && next) {
|
|
242
261
|
this.pendingTarget = undefined;
|
|
243
|
-
this.
|
|
262
|
+
this.FixPosition(); // looped: back from a virtual slot first, as at every stop
|
|
263
|
+
if (this.ScrollToOffset(next, SKPoint.Empty, true))
|
|
264
|
+
return false; // phase 2 runs
|
|
244
265
|
}
|
|
266
|
+
return ended;
|
|
245
267
|
}
|
|
246
268
|
}
|
|
@@ -20,6 +20,10 @@ export declare class SkiaShape extends SkiaLayout {
|
|
|
20
20
|
StrokeCap: StrokeCap;
|
|
21
21
|
/** Gradient painted along the stroke instead of StrokeColor (C# StrokeGradient). */
|
|
22
22
|
StrokeGradient?: SkiaGradient;
|
|
23
|
+
/** Dashes in points: on, off, on, off... (C# StrokePath, each rounded to pixels). Empty = a solid line. */
|
|
24
|
+
StrokePath?: number[];
|
|
25
|
+
/** Blend mode of the stroke, an SKBlendMode name (C# StrokeBlendMode). */
|
|
26
|
+
StrokeBlendMode: string;
|
|
23
27
|
/** Raised (Bevel) or pressed-in (Emboss) edges, drawn with Bevel after the background (C# BevelType). */
|
|
24
28
|
BevelType: BevelType;
|
|
25
29
|
private bevel?;
|
|
@@ -43,11 +47,18 @@ export declare class SkiaShape extends SkiaLayout {
|
|
|
43
47
|
static ShadowFilter(shadow: SkiaShadow, scale: number): import("canvaskit-wasm").ImageFilter;
|
|
44
48
|
constructor();
|
|
45
49
|
private StrokePixels;
|
|
46
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* The outline the stroke runs on (C# CalculateShapeSizeForStroke): the bounds inset by half the stroke rounded up, at
|
|
52
|
+
* least a pixel, then on whole pixels inward, so a 1 px stroke on a plain rectangle sits on the line between two
|
|
53
|
+
* pixels as upstream draws it.
|
|
54
|
+
*/
|
|
47
55
|
private StrokeAwareRect;
|
|
56
|
+
/** The fill (C# MeasuredStrokeAwareClipSize): a third of the stroke inside the outline, so it does not show under the stroke's edge. */
|
|
57
|
+
private BackgroundRect;
|
|
48
58
|
private UsesStroke;
|
|
49
59
|
/** Builds the outline path for rect (canvas pixels). Caller deletes it. */
|
|
50
|
-
|
|
60
|
+
/** `radiusReduce`: pixels taken off every corner radius (the fill inside a thick stroke, C# GetCorrectedBackgroundRadii). */
|
|
61
|
+
protected CreateShapePath(rect: SKRect, scale: number, radiusReduce?: number): Path;
|
|
51
62
|
/** Children live inside the stroke (full width) + Padding. */
|
|
52
63
|
private ChildrenRect;
|
|
53
64
|
/** Clip for overlay effects (ripple) and children: the shape itself, inset by the stroke. */
|
|
@@ -17,6 +17,10 @@ export class SkiaShape extends SkiaLayout {
|
|
|
17
17
|
StrokeCap = "Round";
|
|
18
18
|
/** Gradient painted along the stroke instead of StrokeColor (C# StrokeGradient). */
|
|
19
19
|
StrokeGradient;
|
|
20
|
+
/** Dashes in points: on, off, on, off... (C# StrokePath, each rounded to pixels). Empty = a solid line. */
|
|
21
|
+
StrokePath;
|
|
22
|
+
/** Blend mode of the stroke, an SKBlendMode name (C# StrokeBlendMode). */
|
|
23
|
+
StrokeBlendMode = "SrcOver";
|
|
20
24
|
/** Raised (Bevel) or pressed-in (Emboss) edges, drawn with Bevel after the background (C# BevelType). */
|
|
21
25
|
BevelType = "None";
|
|
22
26
|
bevel;
|
|
@@ -66,14 +70,28 @@ export class SkiaShape extends SkiaLayout {
|
|
|
66
70
|
return 0;
|
|
67
71
|
return this.StrokeWidth > 0 ? this.StrokeWidth * scale : -this.StrokeWidth;
|
|
68
72
|
}
|
|
69
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* The outline the stroke runs on (C# CalculateShapeSizeForStroke): the bounds inset by half the stroke rounded up, at
|
|
75
|
+
* least a pixel, then on whole pixels inward, so a 1 px stroke on a plain rectangle sits on the line between two
|
|
76
|
+
* pixels as upstream draws it.
|
|
77
|
+
*/
|
|
70
78
|
StrokeAwareRect(r, scale) {
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
if (!this.UsesStroke())
|
|
80
|
+
return r;
|
|
81
|
+
const half = this.StrokePixels(scale) / 2, inset = half < 0.5 ? 1 : Math.ceil(half);
|
|
82
|
+
return new SKRect(Math.ceil(r.Left + inset), Math.ceil(r.Top + inset), Math.floor(r.Right - inset), Math.floor(r.Bottom - inset));
|
|
83
|
+
}
|
|
84
|
+
/** The fill (C# MeasuredStrokeAwareClipSize): a third of the stroke inside the outline, so it does not show under the stroke's edge. */
|
|
85
|
+
BackgroundRect(r, scale) {
|
|
86
|
+
if (!this.UsesStroke())
|
|
87
|
+
return r;
|
|
88
|
+
const o = this.StrokeAwareRect(r, scale), k = this.StrokePixels(scale) / 3;
|
|
89
|
+
return new SKRect(o.Left + k, o.Top + k, o.Right - k, o.Bottom - k);
|
|
73
90
|
}
|
|
74
91
|
UsesStroke() { return this.StrokeWidth !== 0 && this.StrokeColor !== Colors.Transparent; }
|
|
75
92
|
/** Builds the outline path for rect (canvas pixels). Caller deletes it. */
|
|
76
|
-
|
|
93
|
+
/** `radiusReduce`: pixels taken off every corner radius (the fill inside a thick stroke, C# GetCorrectedBackgroundRadii). */
|
|
94
|
+
CreateShapePath(rect, scale, radiusReduce = 0) {
|
|
77
95
|
const CK = Super.CK;
|
|
78
96
|
const b = new CK.PathBuilder();
|
|
79
97
|
const type = this.Type;
|
|
@@ -114,7 +132,8 @@ export class SkiaShape extends SkiaLayout {
|
|
|
114
132
|
else {
|
|
115
133
|
const c = this.cornerRadius;
|
|
116
134
|
if (c.TopLeft || c.TopRight || c.BottomLeft || c.BottomRight) {
|
|
117
|
-
const
|
|
135
|
+
const k = (v) => Math.max(0, v * scale - radiusReduce);
|
|
136
|
+
const tl = k(c.TopLeft), tr = k(c.TopRight), br = k(c.BottomRight), bl = k(c.BottomLeft);
|
|
118
137
|
b.addRRect(Float32Array.of(rect.Left, rect.Top, rect.Right, rect.Bottom, tl, tl, tr, tr, br, br, bl, bl));
|
|
119
138
|
}
|
|
120
139
|
else {
|
|
@@ -151,8 +170,11 @@ export class SkiaShape extends SkiaLayout {
|
|
|
151
170
|
return; // open shapes: stroke only
|
|
152
171
|
const CK = Super.CK;
|
|
153
172
|
const canvas = ctx.Context.Canvas;
|
|
154
|
-
const rect = this.
|
|
155
|
-
|
|
173
|
+
const rect = this.BackgroundRect(ctx.Destination, ctx.Scale);
|
|
174
|
+
// inside a stroke wider than a point the corners of the fill are rounded less (C# GetCorrectedBackgroundRadii)
|
|
175
|
+
const outline = this.StrokeAwareRect(ctx.Destination, ctx.Scale);
|
|
176
|
+
const reduce = this.UsesStroke() && this.StrokeWidth > 1 ? Math.min((outline.Width - rect.Width) / 2, (outline.Height - rect.Height) / 2) : 0;
|
|
177
|
+
const path = this.CreateShapePath(rect, ctx.Scale, reduce);
|
|
156
178
|
// C# PaintWithShadowsInternal: the fill is drawn once per shadow with a drop-shadow filter; a hollow shape
|
|
157
179
|
// (ClipBackgroundColor) clips its own outline away so only the shadow outside remains
|
|
158
180
|
for (const shadow of this.shadows) {
|
|
@@ -295,18 +317,36 @@ export class SkiaShape extends SkiaLayout {
|
|
|
295
317
|
clip.delete();
|
|
296
318
|
}
|
|
297
319
|
if (this.UsesStroke()) {
|
|
298
|
-
const
|
|
299
|
-
|
|
320
|
+
const scale = ctx.Scale, px = this.StrokePixels(scale), type = this.Type;
|
|
321
|
+
let rect = this.StrokeAwareRect(ctx.Destination, scale);
|
|
322
|
+
const c = this.cornerRadius;
|
|
323
|
+
const rounded = type === "Rectangle" && !!(c.TopLeft || c.TopRight || c.BottomLeft || c.BottomRight);
|
|
324
|
+
// C# PaintStroke: on curves a stroke of a point or less is thinned (its antialiasing makes it look heavier than
|
|
325
|
+
// the straight parts), a thin rounded rectangle runs through pixel centers, a line is at least a pixel wide
|
|
326
|
+
const curved = rounded || type === "Circle" || type === "Ellipse" || type === "Arc" || type === "Path";
|
|
327
|
+
const width = type === "Line" ? Math.max(1, px) : curved && px <= scale ? px * 0.55 : px;
|
|
328
|
+
if (rounded && px <= 2 * scale) {
|
|
329
|
+
const even = (v) => { const r = Math.round(v); return Math.abs(v % 1) === 0.5 && r % 2 !== 0 ? r - 1 : r; }; // C# Math.Round: ties to even
|
|
330
|
+
rect = new SKRect(even(rect.Left) + 0.5, even(rect.Top) + 0.5, even(rect.Right) - 0.5, even(rect.Bottom) - 0.5);
|
|
331
|
+
}
|
|
332
|
+
const path = this.CreateShapePath(rect, scale);
|
|
300
333
|
const paint = new CK.Paint();
|
|
301
334
|
paint.setAntiAlias(true);
|
|
302
335
|
paint.setStyle(CK.PaintStyle.Stroke);
|
|
303
|
-
paint.setStrokeWidth(
|
|
336
|
+
paint.setStrokeWidth(width);
|
|
304
337
|
paint.setColor(Super.ParseColor(this.StrokeColor));
|
|
305
338
|
if (this.StrokeGradient)
|
|
306
339
|
this.SetupGradient(paint, this.StrokeGradient, rect);
|
|
340
|
+
const blend = CK.BlendMode[this.StrokeBlendMode];
|
|
341
|
+
if (blend && this.StrokeBlendMode !== "SrcOver")
|
|
342
|
+
paint.setBlendMode(blend);
|
|
307
343
|
paint.setStrokeCap(this.StrokeCap === "Butt" ? CK.StrokeCap.Butt : this.StrokeCap === "Square" ? CK.StrokeCap.Square : CK.StrokeCap.Round);
|
|
308
344
|
paint.setStrokeJoin(this.StrokeCap === "Round" ? CK.StrokeJoin.Round : CK.StrokeJoin.Miter);
|
|
345
|
+
const dash = this.StrokePath?.length ? CK.PathEffect.MakeDash(this.StrokePath.map((v) => Math.round(v * scale)), 0) : null;
|
|
346
|
+
if (dash)
|
|
347
|
+
paint.setPathEffect(dash);
|
|
309
348
|
canvas.drawPath(path, paint);
|
|
349
|
+
dash?.delete();
|
|
310
350
|
paint.delete();
|
|
311
351
|
path.delete();
|
|
312
352
|
}
|
|
@@ -8,6 +8,8 @@ import { type Color, ScaledSize, Thickness } from "../core/Types";
|
|
|
8
8
|
* Track, selected trail and thumbs are painted directly; the C# thumb-position math (SliderHeight = thumb box) is kept.
|
|
9
9
|
*/
|
|
10
10
|
export declare class SkiaSlider extends SkiaControl {
|
|
11
|
+
/** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault). */
|
|
12
|
+
protected ReceivesHoverByDefault(): boolean;
|
|
11
13
|
static DefaultAccessibilityRole?: string;
|
|
12
14
|
ControlStyle: PrebuiltControlStyle;
|
|
13
15
|
Min: number;
|
|
@@ -17,7 +19,11 @@ export declare class SkiaSlider extends SkiaControl {
|
|
|
17
19
|
/** Minimum distance between the two thumbs, in value units. */
|
|
18
20
|
RangeMin: number;
|
|
19
21
|
ClickOnTrailEnabled: boolean;
|
|
20
|
-
|
|
22
|
+
private respondsToGestures;
|
|
23
|
+
/** False: neither a drag nor the arrow keys move it (code still can), and it is reported disabled (drawnui-cross 6w). */
|
|
24
|
+
get RespondsToGestures(): boolean;
|
|
25
|
+
set RespondsToGestures(v: boolean);
|
|
26
|
+
protected AcceptsInput(): boolean;
|
|
21
27
|
IsPressed: boolean;
|
|
22
28
|
IsUserPanning: boolean;
|
|
23
29
|
/** Extra points around a thumb that still count as grabbing it (C# moreHotspotSize). */
|
|
@@ -70,5 +76,17 @@ export declare class SkiaSlider extends SkiaControl {
|
|
|
70
76
|
protected Paint(ctx: DrawingContext): void;
|
|
71
77
|
ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
|
|
72
78
|
protected DefaultAccessibilityCanInteract(): boolean;
|
|
73
|
-
|
|
79
|
+
/** Enter / Space do nothing: the base taps the center, which would jump the value to the middle. */
|
|
80
|
+
OnAccessibilityActivated(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Keyboard adjustment while the slider holds keyboard focus (C# SkiaSlider.OnAccessibilityKey): Right / Up increase and
|
|
83
|
+
* Left / Down decrease by Step (a hundredth of the range when Step is 0), PageUp / PageDown move a tenth of the range,
|
|
84
|
+
* Home / End go to Min / Max. A ranged slider moves its End thumb, which stops at Start.
|
|
85
|
+
*/
|
|
86
|
+
OnAccessibilityKey(key: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* End between Min and Max, read as the number, or "20 – 80" in range mode; the step is the arrow key's. The name is
|
|
89
|
+
* the app's AccessibilityLabel only (C# used to make the value the name, drawnui-cross 6c).
|
|
90
|
+
*/
|
|
91
|
+
get AccessibilityValue(): import("../core/Accessibility").AccessibilityValue;
|
|
74
92
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SkiaControl } from "../core/SkiaControl";
|
|
2
2
|
import { Super } from "../core/Super";
|
|
3
|
-
import { ResolveControlStyle } from "../core/ControlStyle";
|
|
3
|
+
import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
|
|
4
4
|
import { Colors, ScaledSize, SkiaShadow, Thickness } from "../core/Types";
|
|
5
5
|
import { SkiaShape } from "./SkiaShape";
|
|
6
6
|
/**
|
|
@@ -9,6 +9,8 @@ import { SkiaShape } from "./SkiaShape";
|
|
|
9
9
|
* Track, selected trail and thumbs are painted directly; the C# thumb-position math (SliderHeight = thumb box) is kept.
|
|
10
10
|
*/
|
|
11
11
|
export class SkiaSlider extends SkiaControl {
|
|
12
|
+
/** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault). */
|
|
13
|
+
ReceivesHoverByDefault() { return true; }
|
|
12
14
|
static DefaultAccessibilityRole = "slider";
|
|
13
15
|
ControlStyle = "Unset";
|
|
14
16
|
Min = 0;
|
|
@@ -18,7 +20,14 @@ export class SkiaSlider extends SkiaControl {
|
|
|
18
20
|
/** Minimum distance between the two thumbs, in value units. */
|
|
19
21
|
RangeMin = 0;
|
|
20
22
|
ClickOnTrailEnabled = true;
|
|
21
|
-
|
|
23
|
+
respondsToGestures = true;
|
|
24
|
+
/** False: neither a drag nor the arrow keys move it (code still can), and it is reported disabled (drawnui-cross 6w). */
|
|
25
|
+
get RespondsToGestures() { return this.respondsToGestures; }
|
|
26
|
+
set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
|
|
27
|
+
this.respondsToGestures = v;
|
|
28
|
+
this.NotifyAccessibility();
|
|
29
|
+
} }
|
|
30
|
+
AcceptsInput() { return this.respondsToGestures; }
|
|
22
31
|
IsPressed = false;
|
|
23
32
|
IsUserPanning = false;
|
|
24
33
|
/** Extra points around a thumb that still count as grabbing it (C# moreHotspotSize). */
|
|
@@ -60,11 +69,11 @@ export class SkiaSlider extends SkiaControl {
|
|
|
60
69
|
get SliderHeight() { return this.sliderHeight ?? this.Look().thumb + (this.EnableRange && this.UsingControlStyle !== "Unset" ? 8 : 0); }
|
|
61
70
|
set SliderHeight(v) { this.sliderHeight = v; this.Update(); }
|
|
62
71
|
get ThumbColor() { return this.thumbColor ?? this.Look().thumbColor; }
|
|
63
|
-
set ThumbColor(v) { this.thumbColor = v; this.
|
|
72
|
+
set ThumbColor(v) { this.thumbColor = v; this.UpdateDraw(); }
|
|
64
73
|
get TrackColor() { return this.trackColor ?? this.Look().track; }
|
|
65
|
-
set TrackColor(v) { this.trackColor = v; this.
|
|
74
|
+
set TrackColor(v) { this.trackColor = v; this.UpdateDraw(); }
|
|
66
75
|
get TrackSelectedColor() { return this.trackSelectedColor ?? this.Look().selected; }
|
|
67
|
-
set TrackSelectedColor(v) { this.trackSelectedColor = v; this.
|
|
76
|
+
set TrackSelectedColor(v) { this.trackSelectedColor = v; this.UpdateDraw(); }
|
|
68
77
|
/** C# style builders: thumb diameter, track height, palette, thumb shadow. */
|
|
69
78
|
Look() {
|
|
70
79
|
switch (this.UsingControlStyle) {
|
|
@@ -72,7 +81,7 @@ export class SkiaSlider extends SkiaControl {
|
|
|
72
81
|
case "Material": return { thumb: 20, trackH: 4, track: "#E8EAED", selected: "#2196F3", thumbColor: "#2196F3", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.3, Color: Colors.Black }) };
|
|
73
82
|
case "Material3": return { thumb: 20, trackH: 4, track: "#E6E0E9", selected: "#6750A4", thumbColor: "#6750A4", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.3, Color: Colors.Black }) };
|
|
74
83
|
case "Windows": return { thumb: 20, trackH: 4, track: "#C6C6C6", selected: "#0078D4", thumbColor: "#0078D4", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.25, Color: Colors.Black }) };
|
|
75
|
-
default: return { thumb: 35, trackH: 6, track: "#D7DBE0", selected:
|
|
84
|
+
default: return { thumb: 35, trackH: 6, track: "#D7DBE0", selected: DefaultAccent, thumbColor: DefaultAccent, shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 3, Opacity: 0.25, Color: Colors.Black }) };
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
/** Thumb shadows paint outside the box: the cache must include them. */
|
|
@@ -239,5 +248,50 @@ export class SkiaSlider extends SkiaControl {
|
|
|
239
248
|
return super.ProcessGestures(args, apply);
|
|
240
249
|
}
|
|
241
250
|
DefaultAccessibilityCanInteract() { return this.RespondsToGestures; }
|
|
242
|
-
|
|
251
|
+
/** Enter / Space do nothing: the base taps the center, which would jump the value to the middle. */
|
|
252
|
+
OnAccessibilityActivated() { }
|
|
253
|
+
/**
|
|
254
|
+
* Keyboard adjustment while the slider holds keyboard focus (C# SkiaSlider.OnAccessibilityKey): Right / Up increase and
|
|
255
|
+
* Left / Down decrease by Step (a hundredth of the range when Step is 0), PageUp / PageDown move a tenth of the range,
|
|
256
|
+
* Home / End go to Min / Max. A ranged slider moves its End thumb, which stops at Start.
|
|
257
|
+
*/
|
|
258
|
+
OnAccessibilityKey(key) {
|
|
259
|
+
if (!this.RespondsToGestures)
|
|
260
|
+
return false;
|
|
261
|
+
const range = this.Max - this.Min, small = this.Step > 0 ? this.Step : range / 100, large = Math.max(small, range / 10);
|
|
262
|
+
const low = this.EnableRange ? this.Start : this.Min;
|
|
263
|
+
let value;
|
|
264
|
+
switch (key) {
|
|
265
|
+
case "ArrowRight":
|
|
266
|
+
case "ArrowUp":
|
|
267
|
+
value = this.End + small;
|
|
268
|
+
break;
|
|
269
|
+
case "ArrowLeft":
|
|
270
|
+
case "ArrowDown":
|
|
271
|
+
value = this.End - small;
|
|
272
|
+
break;
|
|
273
|
+
case "PageUp":
|
|
274
|
+
value = this.End + large;
|
|
275
|
+
break;
|
|
276
|
+
case "PageDown":
|
|
277
|
+
value = this.End - large;
|
|
278
|
+
break;
|
|
279
|
+
case "Home":
|
|
280
|
+
value = low;
|
|
281
|
+
break;
|
|
282
|
+
case "End":
|
|
283
|
+
value = this.Max;
|
|
284
|
+
break;
|
|
285
|
+
default: return false;
|
|
286
|
+
}
|
|
287
|
+
this.End = Math.min(this.Max, Math.max(low, value));
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* End between Min and Max, read as the number, or "20 – 80" in range mode; the step is the arrow key's. The name is
|
|
292
|
+
* the app's AccessibilityLabel only (C# used to make the value the name, drawnui-cross 6c).
|
|
293
|
+
*/
|
|
294
|
+
get AccessibilityValue() {
|
|
295
|
+
return { Now: this.end, Min: this.Min, Max: this.Max, Step: this.Step > 0 ? this.Step : (this.Max - this.Min) / 100, Text: this.EnableRange ? `${this.start} – ${this.end}` : "" };
|
|
296
|
+
}
|
|
243
297
|
}
|
|
@@ -81,15 +81,19 @@ export declare class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
81
81
|
static LoadSourceAsync(source: string): Promise<Image>;
|
|
82
82
|
SetSpriteSheet(image: Image): void;
|
|
83
83
|
protected RecalculateFrames(): void;
|
|
84
|
+
/** The frame index (position in FrameSequence when one is set) at a time in ms; negative counts back from the end. */
|
|
84
85
|
protected GetFrameNumberFromTime(msTime: number): number;
|
|
85
86
|
protected SetCurrentFrame(frameNumber: number): void;
|
|
86
87
|
/** Transparent borders of a frame, scanned once (C# ScanFrameContentBounds over the bitmap alpha). */
|
|
87
88
|
private GetFrameContentBounds;
|
|
88
89
|
protected OnAnimatorUpdated(value: number): void;
|
|
90
|
+
protected NextChangeMs(value: number): number | undefined;
|
|
89
91
|
protected OnAnimatorSeeking(time: number): void;
|
|
90
92
|
protected OnAnimatorInitializing(): void;
|
|
91
93
|
protected ApplySpeed(): void;
|
|
92
94
|
protected CheckCanStartAnimator(): boolean;
|
|
95
|
+
/** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
|
|
96
|
+
protected ApplyDefaultFrame(): void;
|
|
93
97
|
Start(delayMs?: number): void;
|
|
94
98
|
protected MeasureAbsolute(widthConstraint: number, heightConstraint: number, scale: number): ScaledSize;
|
|
95
99
|
/** C# ResolveFrameMetrics: source rect of the trimmed content and its display rect inside dest. */
|
|
@@ -74,9 +74,6 @@ export class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
74
74
|
set FramesPerSecond(v) { if (this.framesPerSecond !== v) {
|
|
75
75
|
this.framesPerSecond = v;
|
|
76
76
|
this.RecalculateFrames();
|
|
77
|
-
if (this.Animator) {
|
|
78
|
-
this.OnAnimatorInitializing();
|
|
79
|
-
}
|
|
80
77
|
} }
|
|
81
78
|
/** Custom order of frames to play instead of 0..TotalFrames-1. */
|
|
82
79
|
get FrameSequence() { return this.frameSequence; }
|
|
@@ -160,22 +157,30 @@ export class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
160
157
|
this.DurationMs = this.TotalFrames * this.FrameDurationMs;
|
|
161
158
|
this.lastColumns = this.columns;
|
|
162
159
|
this.lastRows = this.rows;
|
|
160
|
+
if (this.Animator) {
|
|
161
|
+
// FramesPerSecond, FrameSequence, MaxFrames or the grid changed after loading: the animator range and the shown
|
|
162
|
+
// frame follow the new frames
|
|
163
|
+
this.ApplySpeed();
|
|
164
|
+
this.Animator.mMaxValue = this.DurationMs;
|
|
165
|
+
this.SetCurrentFrame(this.currentFrame);
|
|
166
|
+
}
|
|
163
167
|
}
|
|
168
|
+
/** The frame index (position in FrameSequence when one is set) at a time in ms; negative counts back from the end. */
|
|
164
169
|
GetFrameNumberFromTime(msTime) {
|
|
165
170
|
if (this.DurationMs <= 0)
|
|
166
171
|
return 0;
|
|
167
|
-
if (msTime < 0)
|
|
168
|
-
msTime = this.DurationMs + msTime;
|
|
169
172
|
msTime %= this.DurationMs;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
if (msTime < 0)
|
|
174
|
+
msTime += this.DurationMs;
|
|
175
|
+
// the epsilon keeps the exact start time of a frame on that frame: k * d / d can come out a hair below k
|
|
176
|
+
const frame = Math.floor(msTime / this.FrameDurationMs + 1e-9);
|
|
173
177
|
return Math.min(frame, this.TotalFrames - 1);
|
|
174
178
|
}
|
|
175
179
|
SetCurrentFrame(frameNumber) {
|
|
176
180
|
if (!this.SpriteSheet || this.TotalFrames === 0)
|
|
177
181
|
return;
|
|
178
|
-
frameNumber
|
|
182
|
+
if (frameNumber < 0 || frameNumber >= this.TotalFrames)
|
|
183
|
+
frameNumber = this.TotalFrames - 1; // negative = the last frame
|
|
179
184
|
const actual = this.frameSequence && this.frameSequence.length > 0 ? this.frameSequence[Math.min(frameNumber, this.frameSequence.length - 1)] : frameNumber;
|
|
180
185
|
this.currentFrame = frameNumber;
|
|
181
186
|
const framesX = Math.max(1, this.columns);
|
|
@@ -227,6 +232,10 @@ export class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
227
232
|
}
|
|
228
233
|
// ---- animator ----
|
|
229
234
|
OnAnimatorUpdated(value) { this.Seek(value); }
|
|
235
|
+
NextChangeMs(value) {
|
|
236
|
+
const fd = this.FrameDurationMs;
|
|
237
|
+
return fd > 0 ? (Math.floor(value / fd) + 1) * fd : undefined;
|
|
238
|
+
}
|
|
230
239
|
OnAnimatorSeeking(time) {
|
|
231
240
|
if (!this.SpriteSheet)
|
|
232
241
|
return;
|
|
@@ -245,9 +254,12 @@ export class SkiaSprite extends AnimatedFramesRenderer {
|
|
|
245
254
|
ApplySpeed() {
|
|
246
255
|
if (!this.SpriteSheet || !this.Animator)
|
|
247
256
|
return;
|
|
248
|
-
this.Animator.Speed = this.
|
|
257
|
+
this.Animator.Speed = this.GetPlaybackDurationMs(this.DurationMs);
|
|
249
258
|
}
|
|
250
259
|
CheckCanStartAnimator() { return !!this.SpriteSheet && this.TotalFrames > 0; }
|
|
260
|
+
/** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
|
|
261
|
+
ApplyDefaultFrame() { if (!this.IsPlaying)
|
|
262
|
+
this.SetCurrentFrame(this.DefaultFrame); }
|
|
251
263
|
Start(delayMs = 0) { if (this.SpriteSheet && this.TotalFrames > 0)
|
|
252
264
|
super.Start(delayMs); }
|
|
253
265
|
// ---- measure / draw (C# SpriteFrameImage: AspectFit of the FRAME into the box, then the placement config) ----
|
|
@@ -33,6 +33,10 @@ export declare class SkiaSvg extends SkiaControl {
|
|
|
33
33
|
private Clear;
|
|
34
34
|
protected OnDisposing(): void;
|
|
35
35
|
private DropRaster;
|
|
36
|
+
private tileShader?;
|
|
37
|
+
private tileShaderAt;
|
|
38
|
+
/** Repeat shader of the raster placed at `display`, kept until the raster or its placement changes (C# picture shader). */
|
|
39
|
+
private TileShader;
|
|
36
40
|
private Decode;
|
|
37
41
|
/** Natural size: the decoded image's, else the viewBox (SVGs without width/height decode as 0x0 or 300x150). */
|
|
38
42
|
private static IntrinsicSize;
|