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
package/dist/controls/SkiaSvg.js
CHANGED
|
@@ -42,7 +42,7 @@ export class SkiaSvg extends SkiaControl {
|
|
|
42
42
|
}
|
|
43
43
|
const generation = ++this.loadGeneration;
|
|
44
44
|
this.IsLoading = true;
|
|
45
|
-
fetch(value)
|
|
45
|
+
fetch(Super.ResolveAssetUrl(value))
|
|
46
46
|
.then((r) => { if (!r.ok)
|
|
47
47
|
throw new Error(`DrawnUi: ${r.status} loading svg '${value}'`); return r.text(); })
|
|
48
48
|
.then((text) => { if (generation === this.loadGeneration)
|
|
@@ -74,10 +74,26 @@ export class SkiaSvg extends SkiaControl {
|
|
|
74
74
|
}
|
|
75
75
|
OnDisposing() { this.loadGeneration++; this.DropRaster(); }
|
|
76
76
|
DropRaster() {
|
|
77
|
+
this.tileShader?.delete();
|
|
78
|
+
this.tileShader = undefined;
|
|
77
79
|
this.raster?.delete();
|
|
78
80
|
this.raster = undefined;
|
|
79
81
|
this.rasterKey = "";
|
|
80
82
|
}
|
|
83
|
+
tileShader;
|
|
84
|
+
tileShaderAt = "";
|
|
85
|
+
/** Repeat shader of the raster placed at `display`, kept until the raster or its placement changes (C# picture shader). */
|
|
86
|
+
TileShader(raster, display) {
|
|
87
|
+
const at = `${display.Left},${display.Top},${display.Width},${display.Height}`;
|
|
88
|
+
if (this.tileShader && this.tileShaderAt === at)
|
|
89
|
+
return this.tileShader;
|
|
90
|
+
this.tileShader?.delete();
|
|
91
|
+
const CK = Super.CK, M = CK.Matrix;
|
|
92
|
+
const local = M.multiply(M.translated(display.Left, display.Top), M.scaled(display.Width / raster.width(), display.Height / raster.height()));
|
|
93
|
+
this.tileShader = raster.makeShaderOptions(CK.TileMode.Repeat, CK.TileMode.Repeat, CK.FilterMode.Linear, CK.MipmapMode.None, local);
|
|
94
|
+
this.tileShaderAt = at;
|
|
95
|
+
return this.tileShader;
|
|
96
|
+
}
|
|
81
97
|
async Decode(svg, sourceName, generation) {
|
|
82
98
|
this.IsLoading = true;
|
|
83
99
|
// browsers refuse to rasterize an <img> SVG whose root has no xmlns (SkiaSharp's parser does not care)
|
|
@@ -154,7 +170,9 @@ export class SkiaSvg extends SkiaControl {
|
|
|
154
170
|
if (!this.element || Width <= 0 || Height <= 0)
|
|
155
171
|
return;
|
|
156
172
|
const dest = ctx.Destination;
|
|
157
|
-
|
|
173
|
+
// Tile: the picture at its natural size (one SVG unit per point), repeated from the aligned copy (C# de5ba4bb)
|
|
174
|
+
const tile = this.Aspect === "Tile";
|
|
175
|
+
const scaled = tile ? { X: ctx.Scale, Y: ctx.Scale } : SkiaImage.RescaleAspect(Width, Height, dest, this.Aspect);
|
|
158
176
|
const display = SkiaImage.CalculateDisplayRect(dest, Width * scaled.X, Height * scaled.Y, this.HorizontalAlignment, this.VerticalAlignment);
|
|
159
177
|
this.DisplayRect = display;
|
|
160
178
|
const raster = this.GetRaster(Math.round(display.Width), Math.round(display.Height));
|
|
@@ -164,7 +182,7 @@ export class SkiaSvg extends SkiaControl {
|
|
|
164
182
|
const canvas = ctx.Context.Canvas;
|
|
165
183
|
const overflows = display.Left < dest.Left || display.Top < dest.Top || display.Right > dest.Right || display.Bottom > dest.Bottom;
|
|
166
184
|
const saved = canvas.save();
|
|
167
|
-
if (overflows)
|
|
185
|
+
if (overflows || tile)
|
|
168
186
|
canvas.clipRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), CK.ClipOp.Intersect, true);
|
|
169
187
|
const paint = new CK.Paint();
|
|
170
188
|
paint.setAntiAlias(true);
|
|
@@ -174,7 +192,13 @@ export class SkiaSvg extends SkiaControl {
|
|
|
174
192
|
paint.setColorFilter(filter);
|
|
175
193
|
filter.delete();
|
|
176
194
|
}
|
|
177
|
-
|
|
195
|
+
if (tile) {
|
|
196
|
+
paint.setShader(this.TileShader(raster, display));
|
|
197
|
+
canvas.drawRect(CK.LTRBRect(dest.Left, dest.Top, dest.Right, dest.Bottom), paint);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
canvas.drawImageRectOptions(raster, CK.LTRBRect(0, 0, raster.width(), raster.height()), CK.LTRBRect(display.Left, display.Top, display.Right, display.Bottom), CK.FilterMode.Linear, CK.MipmapMode.None, paint);
|
|
201
|
+
}
|
|
178
202
|
paint.delete();
|
|
179
203
|
canvas.restoreToCount(saved);
|
|
180
204
|
}
|
|
@@ -14,7 +14,6 @@ export declare class SkiaSwitch extends SkiaToggle {
|
|
|
14
14
|
private static readonly DefaultTrack;
|
|
15
15
|
private static readonly MaterialOutline;
|
|
16
16
|
protected StyleDefault(name: "ColorThumbOn" | "ColorFrameOn" | "ColorThumbOff" | "ColorFrameOff"): Color | undefined;
|
|
17
|
-
private SetContentSize;
|
|
18
17
|
protected CreateDefaultContent(): void;
|
|
19
18
|
/** C# GetThumbPosForOn: track width minus thumb width and margins, in points. */
|
|
20
19
|
private ThumbPosForOn;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultAccent } from "../core/ControlStyle";
|
|
1
2
|
import { Colors, SkiaShadow, Thickness } from "../core/Types";
|
|
2
3
|
import { Easing } from "../core/Easing";
|
|
3
4
|
import { SkiaShape } from "./SkiaShape";
|
|
@@ -11,7 +12,7 @@ export class SkiaSwitch extends SkiaToggle {
|
|
|
11
12
|
static DefaultAccessibilityRole = "switch";
|
|
12
13
|
Track;
|
|
13
14
|
Thumb;
|
|
14
|
-
static DefaultAccent =
|
|
15
|
+
static DefaultAccent = DefaultAccent;
|
|
15
16
|
static DefaultTrack = "#D7DBE0";
|
|
16
17
|
static MaterialOutline = "#79747E";
|
|
17
18
|
StyleDefault(name) {
|
|
@@ -25,12 +26,6 @@ export class SkiaSwitch extends SkiaToggle {
|
|
|
25
26
|
};
|
|
26
27
|
return table[s]?.[name];
|
|
27
28
|
}
|
|
28
|
-
SetContentSize(w, h) {
|
|
29
|
-
if (this.WidthRequest < 0)
|
|
30
|
-
this.WidthRequest = w;
|
|
31
|
-
if (this.HeightRequest < 0)
|
|
32
|
-
this.HeightRequest = h;
|
|
33
|
-
}
|
|
34
29
|
CreateDefaultContent() {
|
|
35
30
|
const frame = new SkiaShape();
|
|
36
31
|
frame.Tag = "Frame";
|
|
@@ -77,8 +72,9 @@ export class SkiaSwitch extends SkiaToggle {
|
|
|
77
72
|
frame.StrokeColor = "#767676";
|
|
78
73
|
thumb.Margin = new Thickness(5.5);
|
|
79
74
|
break;
|
|
75
|
+
// the Agent Signals switch size (C# 5c1288f7, drawnui-cross 6as): 46 x 22, the thumb inside its 2 pt margin
|
|
80
76
|
default:
|
|
81
|
-
this.SetContentSize(46,
|
|
77
|
+
this.SetContentSize(46, 22);
|
|
82
78
|
frame.CornerRadius = 20;
|
|
83
79
|
thumb.Margin = new Thickness(2);
|
|
84
80
|
break;
|
|
@@ -5,16 +5,25 @@ import { type Color, type ScaledSize } from "../core/Types";
|
|
|
5
5
|
import { SkiaLayout } from "./SkiaLayout";
|
|
6
6
|
/**
|
|
7
7
|
* Mirrors DrawnUi SkiaToggle: base of SkiaSwitch / SkiaCheckbox / SkiaRadioButton. Tapped flips IsToggled,
|
|
8
|
-
* `Toggled` reports user changes, `ControlStyle` selects the look the default content is built with (
|
|
9
|
-
* measure, like C# CreateDefaultContent
|
|
8
|
+
* `Toggled` reports user changes, `ControlStyle` selects the look the default content is built with (at first
|
|
9
|
+
* measure, like C# CreateDefaultContent; a later change rebuilds it, C# RebuildDefaultContent). Colors left unset
|
|
10
|
+
* take the style defaults (C# SetStyleDefault).
|
|
10
11
|
*/
|
|
11
12
|
export declare abstract class SkiaToggle extends SkiaLayout {
|
|
12
|
-
|
|
13
|
+
/** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault): switch, checkbox, radio button. */
|
|
14
|
+
protected ReceivesHoverByDefault(): boolean;
|
|
15
|
+
private controlStyle;
|
|
16
|
+
get ControlStyle(): PrebuiltControlStyle;
|
|
17
|
+
set ControlStyle(v: PrebuiltControlStyle);
|
|
13
18
|
/** Fires on every IsToggled change; C# fires only on user/external changes, not on DefaultValue application. */
|
|
14
19
|
Toggled?: (sender: SkiaToggle, value: boolean) => void;
|
|
15
20
|
DefaultValue: boolean;
|
|
16
21
|
IsAnimated: boolean;
|
|
17
|
-
|
|
22
|
+
private respondsToGestures;
|
|
23
|
+
/** False: a tap or the keyboard does not toggle it (code still can), a tap on it stops there, and it is reported disabled (drawnui-cross 6w). */
|
|
24
|
+
get RespondsToGestures(): boolean;
|
|
25
|
+
set RespondsToGestures(v: boolean);
|
|
26
|
+
protected AcceptsInput(): boolean;
|
|
18
27
|
private isToggled;
|
|
19
28
|
private colorThumbOn?;
|
|
20
29
|
private colorFrameOn?;
|
|
@@ -37,10 +46,21 @@ export declare abstract class SkiaToggle extends SkiaLayout {
|
|
|
37
46
|
/** Per-style color defaults (C# SetStyleDefault); undefined = the SkiaToggle default. */
|
|
38
47
|
protected StyleDefault(_name: "ColorThumbOn" | "ColorFrameOn" | "ColorThumbOff" | "ColorFrameOff"): Color | undefined;
|
|
39
48
|
protected OnToggledChanged(): void;
|
|
40
|
-
/** Builds the look
|
|
49
|
+
/** Builds the look (C# CreateDefaultContent) — subclasses add their views here; called again after a rebuild. */
|
|
41
50
|
protected abstract CreateDefaultContent(): void;
|
|
42
51
|
/** Pushes IsToggled + colors into the views (C# ApplyProperties). */
|
|
43
52
|
abstract ApplyProperties(): void;
|
|
53
|
+
/** Size requests the style pinned (C# SetDefaultContentSize / SetDefaultMinimumContentSize); a rebuild releases only these. */
|
|
54
|
+
private stylePinned;
|
|
55
|
+
/** C# SetDefaultContentSize: the style's size, only where the app left the request unset. */
|
|
56
|
+
protected SetContentSize(w: number, h: number): void;
|
|
57
|
+
/** C# SetDefaultMinimumContentSize (height only): the style's minimum, only where the app left it unset. */
|
|
58
|
+
protected SetMinimumContentHeight(h: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* C# RebuildDefaultContent: drops the content built for the previous style and the sizes it pinned (the app's own
|
|
61
|
+
* requests stay), so the next Measure builds the current style. No-op before the first build.
|
|
62
|
+
*/
|
|
63
|
+
RebuildDefaultContent(): void;
|
|
44
64
|
/** Content (and the size requests the style sets) must exist before Measure reads WidthRequest/HeightRequest. */
|
|
45
65
|
Measure(widthConstraint: number, heightConstraint: number, scale: number): ScaledSize;
|
|
46
66
|
protected DefaultAccessibilityCanInteract(): boolean;
|
|
@@ -3,16 +3,33 @@ import { Colors } from "../core/Types";
|
|
|
3
3
|
import { SkiaLayout } from "./SkiaLayout";
|
|
4
4
|
/**
|
|
5
5
|
* Mirrors DrawnUi SkiaToggle: base of SkiaSwitch / SkiaCheckbox / SkiaRadioButton. Tapped flips IsToggled,
|
|
6
|
-
* `Toggled` reports user changes, `ControlStyle` selects the look the default content is built with (
|
|
7
|
-
* measure, like C# CreateDefaultContent
|
|
6
|
+
* `Toggled` reports user changes, `ControlStyle` selects the look the default content is built with (at first
|
|
7
|
+
* measure, like C# CreateDefaultContent; a later change rebuilds it, C# RebuildDefaultContent). Colors left unset
|
|
8
|
+
* take the style defaults (C# SetStyleDefault).
|
|
8
9
|
*/
|
|
9
10
|
export class SkiaToggle extends SkiaLayout {
|
|
10
|
-
|
|
11
|
+
/** Takes mouse hover unless ReceivesHover is set false (C# ReceivesHoverByDefault): switch, checkbox, radio button. */
|
|
12
|
+
ReceivesHoverByDefault() { return true; }
|
|
13
|
+
controlStyle = "Unset";
|
|
14
|
+
get ControlStyle() { return this.controlStyle; }
|
|
15
|
+
set ControlStyle(v) {
|
|
16
|
+
if (this.controlStyle === v)
|
|
17
|
+
return;
|
|
18
|
+
this.controlStyle = v;
|
|
19
|
+
this.RebuildDefaultContent();
|
|
20
|
+
}
|
|
11
21
|
/** Fires on every IsToggled change; C# fires only on user/external changes, not on DefaultValue application. */
|
|
12
22
|
Toggled;
|
|
13
23
|
DefaultValue = false;
|
|
14
24
|
IsAnimated = true;
|
|
15
|
-
|
|
25
|
+
respondsToGestures = true;
|
|
26
|
+
/** False: a tap or the keyboard does not toggle it (code still can), a tap on it stops there, and it is reported disabled (drawnui-cross 6w). */
|
|
27
|
+
get RespondsToGestures() { return this.respondsToGestures; }
|
|
28
|
+
set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
|
|
29
|
+
this.respondsToGestures = v;
|
|
30
|
+
this.NotifyAccessibility();
|
|
31
|
+
} }
|
|
32
|
+
AcceptsInput() { return this.respondsToGestures; }
|
|
16
33
|
isToggled = false;
|
|
17
34
|
colorThumbOn;
|
|
18
35
|
colorFrameOn;
|
|
@@ -48,6 +65,40 @@ export class SkiaToggle extends SkiaLayout {
|
|
|
48
65
|
this.Toggled?.(this, this.isToggled);
|
|
49
66
|
this.NotifyAccessibility();
|
|
50
67
|
}
|
|
68
|
+
/** Size requests the style pinned (C# SetDefaultContentSize / SetDefaultMinimumContentSize); a rebuild releases only these. */
|
|
69
|
+
stylePinned = [];
|
|
70
|
+
/** C# SetDefaultContentSize: the style's size, only where the app left the request unset. */
|
|
71
|
+
SetContentSize(w, h) {
|
|
72
|
+
if (this.WidthRequest < 0) {
|
|
73
|
+
this.WidthRequest = w;
|
|
74
|
+
this.stylePinned.push("WidthRequest");
|
|
75
|
+
}
|
|
76
|
+
if (this.HeightRequest < 0) {
|
|
77
|
+
this.HeightRequest = h;
|
|
78
|
+
this.stylePinned.push("HeightRequest");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** C# SetDefaultMinimumContentSize (height only): the style's minimum, only where the app left it unset. */
|
|
82
|
+
SetMinimumContentHeight(h) {
|
|
83
|
+
if (this.MinimumHeightRequest < 0) {
|
|
84
|
+
this.MinimumHeightRequest = h;
|
|
85
|
+
this.stylePinned.push("MinimumHeightRequest");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* C# RebuildDefaultContent: drops the content built for the previous style and the sizes it pinned (the app's own
|
|
90
|
+
* requests stay), so the next Measure builds the current style. No-op before the first build.
|
|
91
|
+
*/
|
|
92
|
+
RebuildDefaultContent() {
|
|
93
|
+
if (!this.contentCreated)
|
|
94
|
+
return;
|
|
95
|
+
this.ClearChildren();
|
|
96
|
+
for (const p of this.stylePinned)
|
|
97
|
+
this[p] = -1;
|
|
98
|
+
this.stylePinned = [];
|
|
99
|
+
this.contentCreated = false;
|
|
100
|
+
this.Update();
|
|
101
|
+
}
|
|
51
102
|
/** Content (and the size requests the style sets) must exist before Measure reads WidthRequest/HeightRequest. */
|
|
52
103
|
Measure(widthConstraint, heightConstraint, scale) {
|
|
53
104
|
if (!this.contentCreated) {
|
|
@@ -62,7 +113,9 @@ export class SkiaToggle extends SkiaLayout {
|
|
|
62
113
|
get AccessibilityIsPressed() { return this.isToggled; }
|
|
63
114
|
set AccessibilityIsPressed(_v) { }
|
|
64
115
|
ProcessGestures(args, apply) {
|
|
65
|
-
if (
|
|
116
|
+
if (!this.respondsToGestures)
|
|
117
|
+
return this.BlockedGestureResult(args); // a tap does not toggle it, nor reach controls under it
|
|
118
|
+
if (args.Type === "Tapped") {
|
|
66
119
|
this.IsToggled = !this.IsToggled;
|
|
67
120
|
return this;
|
|
68
121
|
}
|
|
@@ -11,7 +11,11 @@ import { SkiaLayout } from "./SkiaLayout";
|
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class SnappingLayout extends SkiaLayout {
|
|
13
13
|
Animated: boolean;
|
|
14
|
-
|
|
14
|
+
private respondsToGestures;
|
|
15
|
+
/** False: neither a swipe nor the keyboard moves it (code still can), and it is reported disabled; its content keeps its own taps (drawnui-cross 6w). */
|
|
16
|
+
get RespondsToGestures(): boolean;
|
|
17
|
+
set RespondsToGestures(v: boolean);
|
|
18
|
+
protected AcceptsInput(): boolean;
|
|
15
19
|
IgnoreWrongDirection: boolean;
|
|
16
20
|
Bounces: boolean;
|
|
17
21
|
RubberDamping: number;
|
|
@@ -50,6 +54,8 @@ export declare abstract class SnappingLayout extends SkiaLayout {
|
|
|
50
54
|
protected StopSnapAnimators(): void;
|
|
51
55
|
/** C# SnappingLayout.Render: the transition state follows the position every frame. */
|
|
52
56
|
Render(ctx: DrawingContext): void;
|
|
57
|
+
/** Hover waits while the content slides (C# InTransition) or follows a pan. */
|
|
58
|
+
MovesContent(): boolean;
|
|
53
59
|
ClampOffset(x: number, y: number, rubber: boolean): SKPoint;
|
|
54
60
|
/** C# GetContentOffsetBounds: the extent covered by the snap points. */
|
|
55
61
|
protected BoundsFromSnapPoints(): SKRect;
|
|
@@ -59,6 +65,11 @@ export declare abstract class SnappingLayout extends SkiaLayout {
|
|
|
59
65
|
protected FindNearestAnchorInternal(current: SKPoint, _velocity: SKPoint): SKPoint;
|
|
60
66
|
/** The closest anchor lying in the direction of the velocity (dot product), else the origin. */
|
|
61
67
|
SelectNextAnchor(origin: SKPoint, velocity: SKPoint): SKPoint;
|
|
68
|
+
/**
|
|
69
|
+
* Release speed, points per second along an axis, under which the snap ignores the velocity and goes to the nearest
|
|
70
|
+
* anchor by distance (C# SnapVelocityThreshold, drawnui-cross 6o): a finger held still before lifting is not a flick.
|
|
71
|
+
*/
|
|
72
|
+
SnapVelocityThreshold: number;
|
|
62
73
|
ScrollToNearestAnchor(location: SKPoint, velocity: SKPoint): void;
|
|
63
74
|
get CanAnimate(): boolean;
|
|
64
75
|
protected GetAutoVelocity(displacement: SKPoint): SKPoint;
|
|
@@ -11,7 +11,14 @@ import { SkiaLayout } from "./SkiaLayout";
|
|
|
11
11
|
*/
|
|
12
12
|
export class SnappingLayout extends SkiaLayout {
|
|
13
13
|
Animated = true;
|
|
14
|
-
|
|
14
|
+
respondsToGestures = true;
|
|
15
|
+
/** False: neither a swipe nor the keyboard moves it (code still can), and it is reported disabled; its content keeps its own taps (drawnui-cross 6w). */
|
|
16
|
+
get RespondsToGestures() { return this.respondsToGestures; }
|
|
17
|
+
set RespondsToGestures(v) { if (this.respondsToGestures !== v) {
|
|
18
|
+
this.respondsToGestures = v;
|
|
19
|
+
this.NotifyAccessibility();
|
|
20
|
+
} }
|
|
21
|
+
AcceptsInput() { return this.respondsToGestures; }
|
|
15
22
|
IgnoreWrongDirection = false;
|
|
16
23
|
Bounces = false;
|
|
17
24
|
RubberDamping = 0.7;
|
|
@@ -63,7 +70,8 @@ export class SnappingLayout extends SkiaLayout {
|
|
|
63
70
|
return; // interrupted / restarted: not a finished transition
|
|
64
71
|
this.InTransition = !this.CheckTransitionEnded();
|
|
65
72
|
this.UpdateReportedPosition(); // subclasses gate reporting on InTransition: report the settled state now
|
|
66
|
-
|
|
73
|
+
if (!this.InTransition)
|
|
74
|
+
this.Stopped?.(this, this.CurrentPosition); // at real rest only (a queued next move keeps it in transition)
|
|
67
75
|
}
|
|
68
76
|
OnDisposing() { this.StopSnapAnimators(); }
|
|
69
77
|
get IsSnapAnimating() { return this.springX.IsRunning || this.springY.IsRunning || this.range.IsRunning; }
|
|
@@ -80,9 +88,12 @@ export class SnappingLayout extends SkiaLayout {
|
|
|
80
88
|
}
|
|
81
89
|
/** C# SnappingLayout.Render: the transition state follows the position every frame. */
|
|
82
90
|
Render(ctx) {
|
|
91
|
+
this.Superview?.Hover?.RegisterMover(this);
|
|
83
92
|
super.Render(ctx);
|
|
84
93
|
this.InTransition = !this.CheckTransitionEnded();
|
|
85
94
|
}
|
|
95
|
+
/** Hover waits while the content slides (C# InTransition) or follows a pan. */
|
|
96
|
+
MovesContent() { return this.InTransition || this.IsUserPanning; }
|
|
86
97
|
// ---- clamping ----
|
|
87
98
|
ClampOffset(x, y, rubber) {
|
|
88
99
|
const b = this.ContentOffsetBounds;
|
|
@@ -135,9 +146,17 @@ export class SnappingLayout extends SkiaLayout {
|
|
|
135
146
|
}
|
|
136
147
|
return origin;
|
|
137
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Release speed, points per second along an axis, under which the snap ignores the velocity and goes to the nearest
|
|
151
|
+
* anchor by distance (C# SnapVelocityThreshold, drawnui-cross 6o): a finger held still before lifting is not a flick.
|
|
152
|
+
*/
|
|
153
|
+
SnapVelocityThreshold = 100;
|
|
138
154
|
ScrollToNearestAnchor(location, velocity) {
|
|
139
155
|
if (this.SnapPoints.length === 0)
|
|
140
156
|
return;
|
|
157
|
+
if (Math.abs(velocity.X) < this.SnapVelocityThreshold || Math.abs(velocity.Y) < this.SnapVelocityThreshold) {
|
|
158
|
+
velocity = new SKPoint(Math.abs(velocity.X) < this.SnapVelocityThreshold ? 0 : velocity.X, Math.abs(velocity.Y) < this.SnapVelocityThreshold ? 0 : velocity.Y);
|
|
159
|
+
}
|
|
141
160
|
const origin = this.FindNearestAnchorInternal(location, velocity);
|
|
142
161
|
const target = this.SelectNextAnchor(origin, velocity);
|
|
143
162
|
if (SnappingLayout.Dist(location, target) >= 0.5)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SkiaControl } from "../core/SkiaControl";
|
|
2
|
+
import { type Color, Thickness } from "../core/Types";
|
|
3
|
+
/**
|
|
4
|
+
* Look and timing of the tooltips a canvas shows for controls with a `Tooltip` (drawnui-cross 6ar, C# TooltipStyle).
|
|
5
|
+
* Set app-wide with `Super.TooltipStyle`, or per canvas with `Canvas.TooltipStyle`. Read when a tooltip is built, so a
|
|
6
|
+
* change applies from the next tooltip shown.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TooltipStyle {
|
|
9
|
+
/** Background of the tooltip: dark, a step lighter than dark app surfaces. */
|
|
10
|
+
BackgroundColor: Color;
|
|
11
|
+
/** Color of the tooltip text. */
|
|
12
|
+
TextColor: Color;
|
|
13
|
+
/** Color of the 1 pt border, lifts the tooltip off dark surfaces. Undefined or transparent for none. */
|
|
14
|
+
BorderColor?: Color;
|
|
15
|
+
/** Color of the soft shadow under the tooltip. Undefined or transparent for none. */
|
|
16
|
+
ShadowColor?: Color;
|
|
17
|
+
/** Font family of the tooltip text, undefined for the default font. */
|
|
18
|
+
FontFamily?: string;
|
|
19
|
+
/** Font size of the tooltip text, in points. */
|
|
20
|
+
FontSize: number;
|
|
21
|
+
/** Corner radius of the tooltip, in points. */
|
|
22
|
+
CornerRadius: number;
|
|
23
|
+
/** Space around the text, in points. */
|
|
24
|
+
Padding: Thickness;
|
|
25
|
+
/** Longer text wraps at this width, in points. */
|
|
26
|
+
MaxWidth: number;
|
|
27
|
+
/** How long the mouse rests on a control before its tooltip shows, in milliseconds. */
|
|
28
|
+
ShowDelayMs: number;
|
|
29
|
+
/** A tooltip that closed less than this many milliseconds ago lets the next one show at once (moving along a toolbar). */
|
|
30
|
+
FollowWindowMs: number;
|
|
31
|
+
/**
|
|
32
|
+
* False (default): attached to its control, centered 6 pt above it (below it where there is no room). True: below and
|
|
33
|
+
* to the right of the pointer where it rested (above it where there is no room). Either way it stays put while the
|
|
34
|
+
* mouse moves over the control.
|
|
35
|
+
*/
|
|
36
|
+
AtCursor: boolean;
|
|
37
|
+
/** Moves the tooltip right (negative: left) from where it would go, in points. */
|
|
38
|
+
OffsetX: number;
|
|
39
|
+
/** Moves the tooltip down (negative: up), in points; on the flipped side it moves the other way, keeping its distance. */
|
|
40
|
+
OffsetY: number;
|
|
41
|
+
/**
|
|
42
|
+
* Builds the tooltip content for a text instead of the default rounded label. The control is measured and drawn on its
|
|
43
|
+
* own, outside the tree: it takes no input and screen readers do not see it.
|
|
44
|
+
*/
|
|
45
|
+
CreateTooltip?: (text: string) => SkiaControl;
|
|
46
|
+
constructor(init?: Partial<TooltipStyle>);
|
|
47
|
+
/** Room left around the default tooltip for its shadow, in points. */
|
|
48
|
+
static readonly ShadowRoom = 8;
|
|
49
|
+
private static Visible;
|
|
50
|
+
/** The default tooltip content: the text on a rounded background. */
|
|
51
|
+
CreateDefault(text: string): SkiaControl;
|
|
52
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Aria } from "../core/Accessibility";
|
|
2
|
+
import { Super } from "../core/Super";
|
|
3
|
+
import { SkiaShadow, Thickness } from "../core/Types";
|
|
4
|
+
import { SkiaLabel } from "./SkiaLabel";
|
|
5
|
+
import { SkiaShape } from "./SkiaShape";
|
|
6
|
+
/**
|
|
7
|
+
* Look and timing of the tooltips a canvas shows for controls with a `Tooltip` (drawnui-cross 6ar, C# TooltipStyle).
|
|
8
|
+
* Set app-wide with `Super.TooltipStyle`, or per canvas with `Canvas.TooltipStyle`. Read when a tooltip is built, so a
|
|
9
|
+
* change applies from the next tooltip shown.
|
|
10
|
+
*/
|
|
11
|
+
export class TooltipStyle {
|
|
12
|
+
/** Background of the tooltip: dark, a step lighter than dark app surfaces. */
|
|
13
|
+
BackgroundColor = "#2B2D31";
|
|
14
|
+
/** Color of the tooltip text. */
|
|
15
|
+
TextColor = "#F2F3F5";
|
|
16
|
+
/** Color of the 1 pt border, lifts the tooltip off dark surfaces. Undefined or transparent for none. */
|
|
17
|
+
BorderColor = "#24FFFFFF";
|
|
18
|
+
/** Color of the soft shadow under the tooltip. Undefined or transparent for none. */
|
|
19
|
+
ShadowColor = "#59000000";
|
|
20
|
+
/** Font family of the tooltip text, undefined for the default font. */
|
|
21
|
+
FontFamily;
|
|
22
|
+
/** Font size of the tooltip text, in points. */
|
|
23
|
+
FontSize = 13;
|
|
24
|
+
/** Corner radius of the tooltip, in points. */
|
|
25
|
+
CornerRadius = 6;
|
|
26
|
+
/** Space around the text, in points. */
|
|
27
|
+
Padding = new Thickness(12, 8);
|
|
28
|
+
/** Longer text wraps at this width, in points. */
|
|
29
|
+
MaxWidth = 320;
|
|
30
|
+
/** How long the mouse rests on a control before its tooltip shows, in milliseconds. */
|
|
31
|
+
ShowDelayMs = 600;
|
|
32
|
+
/** A tooltip that closed less than this many milliseconds ago lets the next one show at once (moving along a toolbar). */
|
|
33
|
+
FollowWindowMs = 500;
|
|
34
|
+
/**
|
|
35
|
+
* False (default): attached to its control, centered 6 pt above it (below it where there is no room). True: below and
|
|
36
|
+
* to the right of the pointer where it rested (above it where there is no room). Either way it stays put while the
|
|
37
|
+
* mouse moves over the control.
|
|
38
|
+
*/
|
|
39
|
+
AtCursor = false;
|
|
40
|
+
/** Moves the tooltip right (negative: left) from where it would go, in points. */
|
|
41
|
+
OffsetX = 0;
|
|
42
|
+
/** Moves the tooltip down (negative: up), in points; on the flipped side it moves the other way, keeping its distance. */
|
|
43
|
+
OffsetY = 0;
|
|
44
|
+
/**
|
|
45
|
+
* Builds the tooltip content for a text instead of the default rounded label. The control is measured and drawn on its
|
|
46
|
+
* own, outside the tree: it takes no input and screen readers do not see it.
|
|
47
|
+
*/
|
|
48
|
+
CreateTooltip;
|
|
49
|
+
constructor(init) { if (init)
|
|
50
|
+
Object.assign(this, init); }
|
|
51
|
+
/** Room left around the default tooltip for its shadow, in points. */
|
|
52
|
+
static ShadowRoom = 8;
|
|
53
|
+
static Visible(c) {
|
|
54
|
+
if (!c || c === "Transparent" || c === "transparent")
|
|
55
|
+
return false;
|
|
56
|
+
const p = Super.ParseColor(c);
|
|
57
|
+
return p[3] > 0;
|
|
58
|
+
}
|
|
59
|
+
/** The default tooltip content: the text on a rounded background. */
|
|
60
|
+
CreateDefault(text) {
|
|
61
|
+
const shadow = TooltipStyle.Visible(this.ShadowColor);
|
|
62
|
+
const border = TooltipStyle.Visible(this.BorderColor);
|
|
63
|
+
const shape = new SkiaShape();
|
|
64
|
+
shape.CornerRadius = this.CornerRadius;
|
|
65
|
+
shape.BackgroundColor = this.BackgroundColor;
|
|
66
|
+
if (border) {
|
|
67
|
+
shape.StrokeColor = this.BorderColor;
|
|
68
|
+
shape.StrokeWidth = 1;
|
|
69
|
+
}
|
|
70
|
+
shape.Padding = this.Padding;
|
|
71
|
+
shape.Margin = shadow ? new Thickness(TooltipStyle.ShadowRoom) : Thickness.Zero; // the shadow is drawn inside the measured size
|
|
72
|
+
shape.MaximumWidthRequest = this.MaxWidth;
|
|
73
|
+
shape.UseCache = "Image";
|
|
74
|
+
if (shadow)
|
|
75
|
+
shape.Shadows = [new SkiaShadow({ X: 0, Y: 2, Blur: 6, Opacity: 1, Color: this.ShadowColor })];
|
|
76
|
+
const label = new SkiaLabel();
|
|
77
|
+
label.Text = text;
|
|
78
|
+
label.TextColor = this.TextColor;
|
|
79
|
+
label.FontSize = this.FontSize;
|
|
80
|
+
if (this.FontFamily)
|
|
81
|
+
label.FontFamily = this.FontFamily;
|
|
82
|
+
shape.AddSubView(label);
|
|
83
|
+
shape.AccessibilityRole = Aria.RolePresentation;
|
|
84
|
+
label.AccessibilityRole = Aria.RolePresentation;
|
|
85
|
+
return shape;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Super.TooltipStyle = new TooltipStyle();
|