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
package/dist/core/SkiaControl.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Super } from "./Super";
|
|
2
2
|
import { SkiaStyles } from "./Styles";
|
|
3
3
|
import { Colors, SKRect, ScaledSize, Thickness } from "./Types";
|
|
4
|
-
import { RippleAnimator, SkiaValueAnimator } from "./Animators";
|
|
4
|
+
import { ActionOnTickAnimator, RippleAnimator, SkiaValueAnimator } from "./Animators";
|
|
5
5
|
import { Easing } from "./Easing";
|
|
6
|
-
import { Aria } from "./Accessibility";
|
|
6
|
+
import { AccessibilityModals, Aria } from "./Accessibility";
|
|
7
7
|
import { ControlTappedEventArgs, GestureEventProcessingInfo, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
|
|
8
8
|
import { IsPostRendererEffect } from "./SkiaEffect";
|
|
9
9
|
/** Mirrors DrawnUi CachedObject: what a cached control replays instead of repainting. */
|
|
@@ -22,12 +22,29 @@ export class CachedObject {
|
|
|
22
22
|
this.Picture = Picture;
|
|
23
23
|
this.Image = Image;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/** Canvas.GpuEpoch it was made in: after a WebGL context restore it is remade (a picture may replay old GPU images). */
|
|
26
|
+
Epoch = 0;
|
|
27
|
+
/** A picture recorded to be drawn distorted: the images in it sample smoothly (C# CachedObject.PlaybackDistorted). */
|
|
28
|
+
PlaybackDistorted = false;
|
|
29
|
+
/** A picture holding image blits, whose sampling was fixed when it was recorded (C# CachedObject.HasImageBlits). */
|
|
30
|
+
HasImageBlits = false;
|
|
31
|
+
/** C# PaintRenderObject: the blit paint is antialiased (else a turned bitmap keeps stair steps along its own border), dithered when distorted. */
|
|
32
|
+
static blitPaint;
|
|
33
|
+
static blitPaintDithered;
|
|
34
|
+
static BlitPaint(dither) {
|
|
35
|
+
const CK = Super.CK;
|
|
36
|
+
const make = () => { const p = new CK.Paint(); p.setAntiAlias(true); p.setDither(dither); return p; };
|
|
37
|
+
return dither ? (CachedObject.blitPaintDithered ??= make()) : (CachedObject.blitPaint ??= make());
|
|
38
|
+
}
|
|
39
|
+
/** Replays the cache with its top-left moved to (left, top); `smooth` = an image drawn distorted (linear + mipmaps). */
|
|
40
|
+
Draw(canvas, left, top, smooth = false) {
|
|
27
41
|
const CK = Super.CK;
|
|
28
42
|
if (this.Image) {
|
|
29
|
-
//
|
|
30
|
-
|
|
43
|
+
// nearest keeps a bitmap blitted 1:1 sharp; once scaled, turned or projected it needs smooth sampling (C# 1e4610f6)
|
|
44
|
+
if (smooth)
|
|
45
|
+
canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Linear, CK.MipmapMode.Linear, CachedObject.BlitPaint(true));
|
|
46
|
+
else
|
|
47
|
+
canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Nearest, CK.MipmapMode.None, CachedObject.BlitPaint(false));
|
|
31
48
|
}
|
|
32
49
|
else if (this.Picture) {
|
|
33
50
|
const saved = canvas.save();
|
|
@@ -36,9 +53,36 @@ export class CachedObject {
|
|
|
36
53
|
canvas.restoreToCount(saved);
|
|
37
54
|
}
|
|
38
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* C# GetPictureImage: the picture of a picture cache (Operations, OperationsFull) drawn into an image, made on the
|
|
58
|
+
* first call (on `main`'s GPU context when given) and kept as long as this cache lives. Shader effects read it as
|
|
59
|
+
* their input, so on such a control they work on its own content, as on an Image cache.
|
|
60
|
+
*/
|
|
61
|
+
GetPictureImage(main) {
|
|
62
|
+
if (this.pictureImage || !this.Picture)
|
|
63
|
+
return this.pictureImage;
|
|
64
|
+
const w = Math.ceil(this.Bounds.Width), h = Math.ceil(this.Bounds.Height);
|
|
65
|
+
if (w <= 0 || h <= 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
const surface = main?.makeSurface({ ...main.imageInfo(), width: w, height: h }) ?? Super.CK.MakeSurface(w, h);
|
|
68
|
+
if (!surface)
|
|
69
|
+
return undefined;
|
|
70
|
+
const canvas = surface.getCanvas();
|
|
71
|
+
canvas.clear(Super.CK.TRANSPARENT);
|
|
72
|
+
canvas.translate(-this.Bounds.Left, -this.Bounds.Top);
|
|
73
|
+
canvas.drawPicture(this.Picture);
|
|
74
|
+
this.pictureImage = surface.makeImageSnapshot();
|
|
75
|
+
surface.dispose(); // a CK.MakeSurface fallback owns its pixels
|
|
76
|
+
return this.pictureImage;
|
|
77
|
+
}
|
|
78
|
+
pictureImage;
|
|
79
|
+
/** The picture drawn into an image, once GetPictureImage made it. */
|
|
80
|
+
get PictureImage() { return this.pictureImage; }
|
|
39
81
|
Dispose() {
|
|
40
82
|
this.Picture?.delete();
|
|
41
83
|
this.Image?.delete();
|
|
84
|
+
this.pictureImage?.delete();
|
|
85
|
+
this.pictureImage = undefined;
|
|
42
86
|
}
|
|
43
87
|
}
|
|
44
88
|
/**
|
|
@@ -48,6 +92,11 @@ export class CachedObject {
|
|
|
48
92
|
* Render(ctx) -> background + Paint(ctx),
|
|
49
93
|
* ProcessGestures(args, apply) -> consumer or null.
|
|
50
94
|
*/
|
|
95
|
+
/**
|
|
96
|
+
* Controls holding something outside the tree while they are on a canvas (a focused editor's keys and caret timer, a
|
|
97
|
+
* game's keys): the canvas calls their OnLeftCanvas when they leave it with a removed or disposed subtree.
|
|
98
|
+
*/
|
|
99
|
+
export const CanvasLeaveWatchers = new Set();
|
|
51
100
|
export class SkiaControl {
|
|
52
101
|
// ---- layout properties (points) ----
|
|
53
102
|
HorizontalOptions = "Start";
|
|
@@ -66,7 +115,10 @@ export class SkiaControl {
|
|
|
66
115
|
Row = 0;
|
|
67
116
|
ColumnSpan = 1;
|
|
68
117
|
RowSpan = 1;
|
|
69
|
-
|
|
118
|
+
margin = Thickness.Zero;
|
|
119
|
+
/** Space around the control (points); a number is the same on every side, as C# XAML (`Thickness.From`). */
|
|
120
|
+
get Margin() { return this.margin; }
|
|
121
|
+
set Margin(v) { this.margin = Thickness.From(v); }
|
|
70
122
|
/**
|
|
71
123
|
* DrawnUi LockRatio: 0 = off; positive = square of the LARGER of the two sizes (requests or constraints),
|
|
72
124
|
* negative = square of the SMALLER one. Infinite sides are ignored, so WidthRequest=150 + LockRatio=1 = 150x150.
|
|
@@ -75,6 +127,8 @@ export class SkiaControl {
|
|
|
75
127
|
BackgroundColor;
|
|
76
128
|
/** Gradient painted as the background (over BackgroundColor). */
|
|
77
129
|
FillGradient;
|
|
130
|
+
/** Blend mode of the background fill, an SKBlendMode name (C# FillBlendMode); here a FillGradient's own BlendMode wins, on a SkiaShape this one does. */
|
|
131
|
+
FillBlendMode = "SrcOver";
|
|
78
132
|
IsVisible = true;
|
|
79
133
|
Tag;
|
|
80
134
|
// ---- render transforms (MAUI VisualElement names; points, applied at render around DrawingRect) ----
|
|
@@ -87,6 +141,14 @@ export class SkiaControl {
|
|
|
87
141
|
/** Degrees. */
|
|
88
142
|
SkewX = 0;
|
|
89
143
|
SkewY = 0;
|
|
144
|
+
/** Degrees, a 3D turn around the horizontal axis through the pivot, seen with perspective (C# RotationX). */
|
|
145
|
+
RotationX = 0;
|
|
146
|
+
/** Degrees, a 3D turn around the vertical axis through the pivot (C# RotationY). */
|
|
147
|
+
RotationY = 0;
|
|
148
|
+
/** Degrees, a 3D turn around the axis facing the viewer, after RotationX and RotationY (C# RotationZ). */
|
|
149
|
+
RotationZ = 0;
|
|
150
|
+
/** Depth: toward the viewer (+, bigger) or away (−, smaller), turned or flat; draws at 576 / (576 − TranslationZ) (C# TranslationZ). */
|
|
151
|
+
TranslationZ = 0;
|
|
90
152
|
/** Pivot for Rotation/Scale/Skew as a fraction of the box (MAUI default 0.5). */
|
|
91
153
|
AnchorX = 0.5;
|
|
92
154
|
AnchorY = 0.5;
|
|
@@ -114,8 +176,9 @@ export class SkiaControl {
|
|
|
114
176
|
get Scale() { return this.ScaleX; }
|
|
115
177
|
set Scale(v) { this.ScaleX = v; this.ScaleY = v; }
|
|
116
178
|
get HasTransform() {
|
|
117
|
-
return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0;
|
|
179
|
+
return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0 || this.Has3d;
|
|
118
180
|
}
|
|
181
|
+
get Has3d() { return this.RotationX !== 0 || this.RotationY !== 0 || this.RotationZ !== 0 || this.TranslationZ !== 0; }
|
|
119
182
|
/** Matrix applied at the last render (canvas space), undefined when none; gestures map through its inverse. */
|
|
120
183
|
RenderTransformMatrix;
|
|
121
184
|
/** Generic numeric parameters (DrawnUi Value1/Value2): SkiaShape Arc uses start angle / sweep angle in degrees. */
|
|
@@ -132,6 +195,7 @@ export class SkiaControl {
|
|
|
132
195
|
return;
|
|
133
196
|
this.bindingContext = value;
|
|
134
197
|
this.OnBindingContextChanged();
|
|
198
|
+
this.Superview?.Hover?.RequestCheck(); // a recycled cell under a still mouse now shows another item
|
|
135
199
|
}
|
|
136
200
|
/** Index of the bound item inside its ItemsSource, -1 when not templated. */
|
|
137
201
|
ContextIndex = -1;
|
|
@@ -164,18 +228,61 @@ export class SkiaControl {
|
|
|
164
228
|
compositeSurface;
|
|
165
229
|
/** Own content or structure changed: the next composite record is a full one. */
|
|
166
230
|
compositeFull = true;
|
|
231
|
+
/** Where the kept composite surface starts relative to DrawingRect (the effects margin it was laid out with). */
|
|
232
|
+
compositeInsetX = 0;
|
|
233
|
+
compositeInsetY = 0;
|
|
167
234
|
/** Canvas-pixel bounds this control covered when its parent last recorded it (composite erase region). */
|
|
168
235
|
lastCompositeBounds;
|
|
169
|
-
/**
|
|
170
|
-
|
|
236
|
+
/**
|
|
237
|
+
* What the last composite record did (diagnostics): "full" or "partial", the number of children re-recorded and which
|
|
238
|
+
* ones; Areas: the pixels erased and drawn again for changes deeper than a child (C# Areas), Changed: the controls
|
|
239
|
+
* those areas belong to (C# Changed).
|
|
240
|
+
*/
|
|
241
|
+
LastCompositeRecord = { Mode: "full", Children: 0, Dirty: [], Areas: [], Changed: [] };
|
|
242
|
+
/** C# MaxCompositionAreas: more areas than this in one composite record draw it whole instead. */
|
|
243
|
+
static MaxCompositionAreas = 16;
|
|
244
|
+
/** C# MaxCompositionShare: areas covering more than this share of a composite draw it whole instead. */
|
|
245
|
+
static MaxCompositionShare = 0.5;
|
|
246
|
+
/**
|
|
247
|
+
* Changes deeper than a direct child since the last composite record (drawnui-cross 6m): the control, the direct child
|
|
248
|
+
* it is in, where it was drawn before the change (its own drawn bounds, as drawn) and its rect then.
|
|
249
|
+
*/
|
|
250
|
+
compositeDeep;
|
|
251
|
+
/** Set while an UpdateDraw climbs: the ancestors re-measure but an ImageComposite among them keeps its partial record. */
|
|
252
|
+
static drawOrigin = null;
|
|
171
253
|
/** The children a composite record can re-record individually; layouts return their views. */
|
|
172
254
|
GetCompositeChildren() { return []; }
|
|
173
255
|
/** C# TrackChildAsDirty (DirtyChildrenTracker): the child changed without a remeasure of this control. */
|
|
174
256
|
TrackChildAsDirty(child) { if (this.IsCacheComposite)
|
|
175
257
|
this.DirtyChildrenInternal.add(child); }
|
|
258
|
+
static rejectRect = new Float32Array(4);
|
|
259
|
+
/** Its cache must be recorded before it can be drawn (none, dirty, another type, scale, size or GPU context). */
|
|
260
|
+
CacheStale(scale) {
|
|
261
|
+
const cacheType = this.UsingCacheType;
|
|
262
|
+
if (cacheType === "None")
|
|
263
|
+
return false;
|
|
264
|
+
const o = this.RenderObject, r = cacheType === "Operations" ? this.ExpandedCacheRect(scale) : this.AlignedCacheRect(scale);
|
|
265
|
+
return this.cacheDirty || !o || o.Type !== cacheType || o.Epoch !== (this.Superview?.GpuEpoch ?? 0) || o.Scale !== scale
|
|
266
|
+
|| Math.round(o.Bounds.Width) !== Math.round(r.Width) || Math.round(o.Bounds.Height) !== Math.round(r.Height);
|
|
267
|
+
}
|
|
268
|
+
/** Its rect grown by its effects margin, through the matrix it is drawn with, lies outside the canvas clip. */
|
|
269
|
+
OutsideClip(canvas, scale) {
|
|
270
|
+
const b = SkiaControl.MapRect(this.RenderTransformMatrix, this.ExpandedCacheRect(scale)), q = SkiaControl.rejectRect;
|
|
271
|
+
q[0] = b.Left;
|
|
272
|
+
q[1] = b.Top;
|
|
273
|
+
q[2] = b.Right;
|
|
274
|
+
q[3] = b.Bottom;
|
|
275
|
+
return canvas.quickReject(q);
|
|
276
|
+
}
|
|
176
277
|
/** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
|
|
177
|
-
GetTransformedDirtyBounds() {
|
|
178
|
-
|
|
278
|
+
GetTransformedDirtyBounds() { return this.MapBounds(this.RenderTransformMatrix); }
|
|
279
|
+
/**
|
|
280
|
+
* Where the control will be drawn next, from its current transform values: a translation set since the last render is
|
|
281
|
+
* already in (a composite parent erases and clips to this area before the child renders again).
|
|
282
|
+
*/
|
|
283
|
+
GetCurrentDirtyBounds() { return this.MapBounds(this.CurrentMatrix(this.RenderingScale)); }
|
|
284
|
+
MapBounds(m) {
|
|
285
|
+
const r = this.ExpandedCacheRect(this.RenderingScale);
|
|
179
286
|
if (!m)
|
|
180
287
|
return r;
|
|
181
288
|
const pts = Super.CK.Matrix.mapPoints(m, [r.Left, r.Top, r.Right, r.Top, r.Right, r.Bottom, r.Left, r.Bottom]);
|
|
@@ -191,6 +298,67 @@ export class SkiaControl {
|
|
|
191
298
|
/** Consume every gesture that lands on this control so nothing below (z-order) receives it. */
|
|
192
299
|
BlockGesturesBelow = false;
|
|
193
300
|
LockChildrenGestures = "Disabled";
|
|
301
|
+
// ---- focus on a completed tap (drawnui-cross 6ap, C# CanBeFocused / LockFocus / SetFrameworkFocus) ----
|
|
302
|
+
/**
|
|
303
|
+
* A tap this control takes moves the canvas focus to it, and whatever had it (an editor) lets it go. Default false: a
|
|
304
|
+
* plain control declines the focus, so tapping it (a Send button) leaves the current focus alone.
|
|
305
|
+
*/
|
|
306
|
+
CanBeFocused = false;
|
|
307
|
+
/** While this control has the canvas focus, taps elsewhere do not move it. */
|
|
308
|
+
LockFocus = false;
|
|
309
|
+
/** The canvas gives (true) or takes (false) the focus; returns whether the control takes it. */
|
|
310
|
+
SetFrameworkFocus(_focus) { return this.CanBeFocused; }
|
|
311
|
+
// ---- hover (drawnui-cross 6m, C# ReceivesHover / IsHovered / HoverChanged) ----
|
|
312
|
+
receivesHover;
|
|
313
|
+
/**
|
|
314
|
+
* Whether this control takes mouse hover: the canvas sets IsHovered while the mouse is over it. Opt-in: false by
|
|
315
|
+
* default, true by default only in the controls that always had hover (SkiaButton, SkiaSlider, the toggles,
|
|
316
|
+
* SkiaRadioButton, SkiaCarousel, SkiaDrawer), never because a control has a tap handler. A HoverChanged handler turns
|
|
317
|
+
* it on (C# fluent OnHovered) unless it is set.
|
|
318
|
+
*/
|
|
319
|
+
get ReceivesHover() { return this.receivesHover ?? (this.HoverChanged ? true : this.ReceivesHoverByDefault()); }
|
|
320
|
+
set ReceivesHover(value) { this.receivesHover = value; }
|
|
321
|
+
/** The value of ReceivesHover until it is set. */
|
|
322
|
+
ReceivesHoverByDefault() { return false; }
|
|
323
|
+
isHovered = false;
|
|
324
|
+
/**
|
|
325
|
+
* True while the mouse is over this control and it takes hover. Every such control under the pointer is hovered at
|
|
326
|
+
* once (a card and the button inside it, as CSS :hover); it stays as it is while content moves under the pointer and
|
|
327
|
+
* is checked again when that stops. Touch never hovers.
|
|
328
|
+
*/
|
|
329
|
+
get IsHovered() { return this.isHovered; }
|
|
330
|
+
/** IsHovered changed: true when the mouse came over this control, false when it left (C# HoverChanged / OnHovered). */
|
|
331
|
+
HoverChanged;
|
|
332
|
+
/** Set by the canvas's HoverManager. */
|
|
333
|
+
ApplyHover(on) {
|
|
334
|
+
if (this.isHovered === on)
|
|
335
|
+
return;
|
|
336
|
+
this.isHovered = on;
|
|
337
|
+
this.HoverChanged?.(this, on);
|
|
338
|
+
}
|
|
339
|
+
/** A scroll, carousel or drawer moving its content right now: hover waits until it stops (C# IsScrolling / InTransition). */
|
|
340
|
+
MovesContent() { return false; }
|
|
341
|
+
/**
|
|
342
|
+
* Hover hit path (HoverManager): this control is under the point (in its own space), its children under it follow,
|
|
343
|
+
* top-most first, by the routing rules of ProcessGestures. True when this subtree blocks gestures below it, so the
|
|
344
|
+
* controls under it get no hover (a popup over a list).
|
|
345
|
+
*/
|
|
346
|
+
CollectHovered(point, into, xs, ys) {
|
|
347
|
+
into.push(this);
|
|
348
|
+
xs?.push(point.X);
|
|
349
|
+
ys?.push(point.Y);
|
|
350
|
+
if (!this.CheckChildrenGesturesLocked("Pointer")) {
|
|
351
|
+
const listeners = this.GetGestureListeners();
|
|
352
|
+
for (let i = listeners.length - 1; i >= 0; i--) {
|
|
353
|
+
const child = listeners[i];
|
|
354
|
+
if (!child.IsVisible || child.InputTransparent || !this.IsGestureForChild(child, point))
|
|
355
|
+
continue;
|
|
356
|
+
if (child.CollectHovered(child.TransformPointToLocalSpace(point), into, xs, ys))
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return this.BlockGesturesBelow;
|
|
361
|
+
}
|
|
194
362
|
// ---- touch feedback (same names as DrawnUi) ----
|
|
195
363
|
TouchEffectColor = Colors.White;
|
|
196
364
|
/** Plays a ripple (from the tap point) when Tapped fires. */
|
|
@@ -199,6 +367,11 @@ export class SkiaControl {
|
|
|
199
367
|
AnimationTappedSpeed = 0;
|
|
200
368
|
/** Overlay effects drawn above this control's content every frame (ripple etc). */
|
|
201
369
|
PostAnimators = [];
|
|
370
|
+
/**
|
|
371
|
+
* C# PendingUnattachedAnimators: animators started while no Canvas was above this control yet (e.g. a game loop
|
|
372
|
+
* started in a constructor). They start on the control's first arrange, where C# starts them in SuperViewChanged.
|
|
373
|
+
*/
|
|
374
|
+
PendingUnattachedAnimators;
|
|
202
375
|
// ---- visual effects (C# VisualEffects: attached SkiaEffect objects) ----
|
|
203
376
|
visualEffects = [];
|
|
204
377
|
/** Post-renderer effects among VisualEffects (C# EffectPostRenderers). */
|
|
@@ -230,10 +403,27 @@ export class SkiaControl {
|
|
|
230
403
|
return [];
|
|
231
404
|
return this.EffectPostRenderers.filter((e) => e.NeedApply);
|
|
232
405
|
}
|
|
233
|
-
/**
|
|
406
|
+
/**
|
|
407
|
+
* C# CachedImage: the cached texture (Image caches only) and the canvas rect it covers NOW. Scrolled content is
|
|
408
|
+
* re-arranged here, not drawn through a translated canvas, so a cache recorded before its control moved is blitted
|
|
409
|
+
* at the control's current aligned rect (RenderContent) and its record-time Bounds are stale: an effect sampling it
|
|
410
|
+
* there (the slides of a SkiaShaderCarousel after the page scrolled) was off by the scroll amount.
|
|
411
|
+
*/
|
|
234
412
|
get CachedImage() {
|
|
235
413
|
const c = this.RenderObject;
|
|
236
|
-
|
|
414
|
+
if (!c)
|
|
415
|
+
return undefined;
|
|
416
|
+
if (c.Image) {
|
|
417
|
+
const r = this.AlignedCacheRect(c.Scale);
|
|
418
|
+
return { Image: c.Image, Bounds: SKRect.Create(r.Left, r.Top, c.Bounds.Width, c.Bounds.Height) };
|
|
419
|
+
}
|
|
420
|
+
// a picture cache: its picture drawn into an image (made in RenderContent), so effects work on this control's
|
|
421
|
+
// content instead of a snapshot of what is behind it (C# caa1c8c1)
|
|
422
|
+
const image = c.PictureImage;
|
|
423
|
+
if (!image)
|
|
424
|
+
return undefined;
|
|
425
|
+
const r = this.ExpandedCacheRect(c.Scale);
|
|
426
|
+
return { Image: image, Bounds: SKRect.Create(r.Left, r.Top, image.width(), image.height()) };
|
|
237
427
|
}
|
|
238
428
|
/** Clip overlay effects to the control's shape (CreateClip). */
|
|
239
429
|
ClipEffects = true;
|
|
@@ -262,6 +452,17 @@ export class SkiaControl {
|
|
|
262
452
|
if (!SkiaStyles.IsEmpty)
|
|
263
453
|
SkiaStyles.Apply(this, atConstruction);
|
|
264
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* C# IsChildrenItem: added by the app (JSX children or the `Children` list), not a part the control made itself. A new
|
|
457
|
+
* `Children` list drops only these, so a control's own parts keep their place.
|
|
458
|
+
*/
|
|
459
|
+
IsChildrenItem = false;
|
|
460
|
+
/**
|
|
461
|
+
* C# UpdateNonStop (fluent): keeps frames coming while this control is on a canvas, for visuals that change by
|
|
462
|
+
* themselves (a time-driven shader, a clock drawn in code). An endless no-op animator, as C#; it waits for the canvas
|
|
463
|
+
* when the control is not on one yet and stops when the control is disposed. It holds the canvas at full frame rate.
|
|
464
|
+
*/
|
|
465
|
+
UpdateNonStop() { new ActionOnTickAnimator(this, () => { }).Start(); return this; }
|
|
265
466
|
AddSubView(_control) { throw new Error(`DrawnUi: ${this.constructor.name} cannot host children`); }
|
|
266
467
|
InsertSubView(_index, control) { this.AddSubView(control); }
|
|
267
468
|
RemoveSubView(_control) { }
|
|
@@ -272,6 +473,14 @@ export class SkiaControl {
|
|
|
272
473
|
}
|
|
273
474
|
// ---- state (pixels) ----
|
|
274
475
|
MeasuredSize = ScaledSize.Default;
|
|
476
|
+
/**
|
|
477
|
+
* The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
|
|
478
|
+
* axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
|
|
479
|
+
* stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
|
|
480
|
+
*/
|
|
481
|
+
FitPixels = { Width: 0, Height: 0 };
|
|
482
|
+
/** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
|
|
483
|
+
fitContentPixels;
|
|
275
484
|
DrawingRect = SKRect.Empty;
|
|
276
485
|
RenderingScale = 1;
|
|
277
486
|
NeedMeasure = true;
|
|
@@ -320,6 +529,7 @@ export class SkiaControl {
|
|
|
320
529
|
locked = true;
|
|
321
530
|
}
|
|
322
531
|
}
|
|
532
|
+
this.fitContentPixels = undefined;
|
|
323
533
|
const content = this.MeasureAbsolute(w, h, scale);
|
|
324
534
|
let rw = locked || reqW >= 0 ? w : this.HorizontalOptions === "Fill" && isFinite(w) ? w : content.Pixels.Width;
|
|
325
535
|
let rh = locked || reqH >= 0 ? h : this.VerticalOptions === "Fill" && isFinite(h) ? h : content.Pixels.Height;
|
|
@@ -332,6 +542,19 @@ export class SkiaControl {
|
|
|
332
542
|
if (this.MaximumHeightRequest >= 0 && reqH < 0)
|
|
333
543
|
rh = Math.min(rh, this.MaximumHeightRequest * scale);
|
|
334
544
|
this.MeasuredSize = ScaledSize.FromPixels(rw + mx, rh + my, scale);
|
|
545
|
+
// fit-content: what the content needs (never more than the constraint), with the requests and min / max
|
|
546
|
+
const fit = this.fitContentPixels ?? { Width: content.Pixels.Width, Height: content.Pixels.Height };
|
|
547
|
+
let fw = locked || reqW >= 0 ? w : Math.min(fit.Width, isFinite(w) ? w : fit.Width);
|
|
548
|
+
let fh = locked || reqH >= 0 ? h : Math.min(fit.Height, isFinite(h) ? h : fit.Height);
|
|
549
|
+
if (this.MinimumWidthRequest >= 0)
|
|
550
|
+
fw = Math.max(fw, this.MinimumWidthRequest * scale);
|
|
551
|
+
if (this.MinimumHeightRequest >= 0)
|
|
552
|
+
fh = Math.max(fh, this.MinimumHeightRequest * scale);
|
|
553
|
+
if (this.MaximumWidthRequest >= 0 && reqW < 0)
|
|
554
|
+
fw = Math.min(fw, this.MaximumWidthRequest * scale);
|
|
555
|
+
if (this.MaximumHeightRequest >= 0 && reqH < 0)
|
|
556
|
+
fh = Math.min(fh, this.MaximumHeightRequest * scale);
|
|
557
|
+
this.FitPixels = { Width: fw + mx, Height: fh + my };
|
|
335
558
|
this.NeedMeasure = false;
|
|
336
559
|
return this.MeasuredSize;
|
|
337
560
|
}
|
|
@@ -341,6 +564,7 @@ export class SkiaControl {
|
|
|
341
564
|
}
|
|
342
565
|
/** Places MeasuredSize inside destination per Margin + Horizontal/VerticalOptions -> DrawingRect. */
|
|
343
566
|
Arrange(destination, _widthRequest, _heightRequest, scale) {
|
|
567
|
+
this.arrangedIn = destination;
|
|
344
568
|
const m = this.Margin;
|
|
345
569
|
const availL = destination.Left + m.Left * scale;
|
|
346
570
|
const availT = destination.Top + m.Top * scale;
|
|
@@ -355,18 +579,51 @@ export class SkiaControl {
|
|
|
355
579
|
availW = Math.ceil(availW * this.HorizontalFillRatio);
|
|
356
580
|
if (this.VerticalFillRatio !== 1)
|
|
357
581
|
availH = Math.ceil(availH * this.VerticalFillRatio);
|
|
358
|
-
|
|
359
|
-
|
|
582
|
+
// Fill stretches only an axis without a size request: with one, the requested size stays at the start (as DrawnUI for
|
|
583
|
+
// Rust and .NET; with LockRatio a single request sizes both axes)
|
|
584
|
+
const fillX = this.HorizontalOptions === "Fill" && this.WidthRequest < 0 && !(this.LockRatio !== 0 && this.HeightRequest >= 0);
|
|
585
|
+
const fillY = this.VerticalOptions === "Fill" && this.HeightRequest < 0 && !(this.LockRatio !== 0 && this.WidthRequest >= 0);
|
|
586
|
+
const w = fillX ? availW : Math.min(availW, this.MeasuredSize.Pixels.Width - m.HorizontalThickness * scale);
|
|
587
|
+
const h = fillY ? availH : Math.min(availH, this.MeasuredSize.Pixels.Height - m.VerticalThickness * scale);
|
|
360
588
|
// Alignment happens inside the ORIGINAL box (Center/End of a capped control still center/end in the parent).
|
|
361
589
|
const fullW = destination.Width - m.HorizontalThickness * scale, fullH = destination.Height - m.VerticalThickness * scale;
|
|
362
|
-
const x =
|
|
363
|
-
|
|
590
|
+
const x = this.HorizontalOptions === "Center"
|
|
591
|
+
? SkiaControl.Centered(destination.Left, destination.Width, w, (m.Left - m.Right) * scale)
|
|
592
|
+
: availL + SkiaControl.Align(this.HorizontalOptions, fullW, w);
|
|
593
|
+
const y = this.VerticalOptions === "Center"
|
|
594
|
+
? SkiaControl.Centered(destination.Top, destination.Height, h, (m.Top - m.Bottom) * scale)
|
|
595
|
+
: availT + SkiaControl.Align(this.VerticalOptions, fullH, h);
|
|
596
|
+
const old = this.DrawingRect;
|
|
364
597
|
this.DrawingRect = SKRect.Create(x, y, w, h);
|
|
598
|
+
this.FollowMatrix(old);
|
|
365
599
|
this.OnLayoutChanged();
|
|
600
|
+
if (this.PendingUnattachedAnimators)
|
|
601
|
+
this.StartPendingAnimators();
|
|
366
602
|
// DrawnUi OnLayoutReady: an accessible control registers itself on its first layout
|
|
367
603
|
if (!this.registeredWithAccessibility && this.IsAccessibilityElement)
|
|
368
604
|
this.NotifyAccessibility();
|
|
369
605
|
}
|
|
606
|
+
/**
|
|
607
|
+
* A cached ancestor replays its picture where a re-arrange moved it (a scroll) without rendering this control again,
|
|
608
|
+
* so the matrix made at its last Render moves with its rect: taps, hover and the accessibility rect stay on what is
|
|
609
|
+
* drawn (C# offsets the cached render tree instead). A control that renders again gets a fresh matrix there.
|
|
610
|
+
*/
|
|
611
|
+
FollowMatrix(old) {
|
|
612
|
+
const m = this.RenderTransformMatrix, r = this.DrawingRect;
|
|
613
|
+
if (!m || (old.Left === r.Left && old.Top === r.Top))
|
|
614
|
+
return;
|
|
615
|
+
const M = Super.CK.Matrix, dx = r.Left - old.Left, dy = r.Top - old.Top;
|
|
616
|
+
this.RenderTransformMatrix = M.multiply(M.translated(dx, dy), m, M.translated(-dx, -dy));
|
|
617
|
+
}
|
|
618
|
+
/** C# SuperViewChanged: starts the animators queued before this control was attached. */
|
|
619
|
+
StartPendingAnimators() {
|
|
620
|
+
if (!this.Superview)
|
|
621
|
+
return;
|
|
622
|
+
const pending = this.PendingUnattachedAnimators;
|
|
623
|
+
this.PendingUnattachedAnimators = undefined;
|
|
624
|
+
for (const animator of pending)
|
|
625
|
+
animator.Start();
|
|
626
|
+
}
|
|
370
627
|
// ---- accessibility (DrawnUi ISkiaAccessibilityNode) ----
|
|
371
628
|
static nextAccessibilityId = 1;
|
|
372
629
|
/** Stable identity for the DOM overlay. */
|
|
@@ -382,11 +639,39 @@ export class SkiaControl {
|
|
|
382
639
|
* ARIA role; setting it exposes the control to assistive technology (use `Aria` constants). Unset = the class
|
|
383
640
|
* default (`SkiaLabel.DefaultAccessibilityRole` etc.), which is itself unset unless the app opts in.
|
|
384
641
|
*/
|
|
385
|
-
get AccessibilityRole() {
|
|
642
|
+
get AccessibilityRole() {
|
|
643
|
+
return this.accessibilityRole ?? (this.accessibilityModal ? Aria.RoleDialog : this.constructor.DefaultAccessibilityRole);
|
|
644
|
+
}
|
|
386
645
|
set AccessibilityRole(v) { if (this.accessibilityRole !== v) {
|
|
387
646
|
this.accessibilityRole = v;
|
|
388
647
|
this.AccessibilityChanged();
|
|
389
648
|
} }
|
|
649
|
+
/**
|
|
650
|
+
* On an arrow-key group (a container with a composite role such as `Aria.RoleMenu` or `Aria.RoleList`): the arrows go
|
|
651
|
+
* round, from the last item to the first and back, instead of stopping at the ends, as in desktop menus. Home / End
|
|
652
|
+
* unchanged. Default false (C# KeyboardWrap, Rust keyboard_wrap).
|
|
653
|
+
*/
|
|
654
|
+
KeyboardWrap = false;
|
|
655
|
+
accessibilityModal = false;
|
|
656
|
+
/**
|
|
657
|
+
* A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
|
|
658
|
+
* screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
|
|
659
|
+
* until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
|
|
660
|
+
* keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
|
|
661
|
+
* of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
|
|
662
|
+
*/
|
|
663
|
+
get AccessibilityModal() { return this.accessibilityModal; }
|
|
664
|
+
set AccessibilityModal(v) {
|
|
665
|
+
if (this.accessibilityModal === v)
|
|
666
|
+
return;
|
|
667
|
+
this.accessibilityModal = v;
|
|
668
|
+
if (v)
|
|
669
|
+
AccessibilityModals.add(this);
|
|
670
|
+
else
|
|
671
|
+
AccessibilityModals.delete(this);
|
|
672
|
+
this.AccessibilityChanged();
|
|
673
|
+
this.Superview?.Update();
|
|
674
|
+
}
|
|
390
675
|
/** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
|
|
391
676
|
static DefaultAccessibilityRole;
|
|
392
677
|
/** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
|
|
@@ -401,8 +686,35 @@ export class SkiaControl {
|
|
|
401
686
|
this.accessibilityHint = v;
|
|
402
687
|
this.AccessibilityChanged();
|
|
403
688
|
} }
|
|
404
|
-
/**
|
|
405
|
-
|
|
689
|
+
/** Text of the tooltip shown when the mouse rests on the control (drawnui-cross 6ar); undefined = none. */
|
|
690
|
+
Tooltip;
|
|
691
|
+
/** The control may have tooltip text: the cheap check made on every mouse move. */
|
|
692
|
+
get MayHaveTooltip() {
|
|
693
|
+
return !!this.Tooltip || (Super.TooltipsFromAccessibility && (this.accessibilityHint != null || this.accessibilityLabel != null));
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* The text of this control's tooltip, undefined for none: `Tooltip`, else with `Super.TooltipsFromAccessibility` its
|
|
697
|
+
* `AccessibilityHint`, else its own `AccessibilityLabel` when it shows no text of its own (icon buttons).
|
|
698
|
+
*/
|
|
699
|
+
GetTooltipText() {
|
|
700
|
+
if (this.Tooltip)
|
|
701
|
+
return this.Tooltip;
|
|
702
|
+
if (!Super.TooltipsFromAccessibility)
|
|
703
|
+
return undefined;
|
|
704
|
+
if (this.accessibilityHint)
|
|
705
|
+
return this.accessibilityHint;
|
|
706
|
+
if (this.accessibilityLabel && !this.ShowsText())
|
|
707
|
+
return this.accessibilityLabel;
|
|
708
|
+
return undefined;
|
|
709
|
+
}
|
|
710
|
+
/** The control shows text of its own (a label with text, spans included, inside it). */
|
|
711
|
+
ShowsText() { return false; }
|
|
712
|
+
/**
|
|
713
|
+
* Whether keyboard navigation and assistive technology may focus and use this node: the explicit value, else the class
|
|
714
|
+
* default (true when the control handles Tapped), and in both cases only while a tap could reach the control
|
|
715
|
+
* (CanReceiveGesture), so Tab, Enter / Space and screen-reader activation never use a control the pointer cannot.
|
|
716
|
+
*/
|
|
717
|
+
get AccessibilityCanInteract() { return (this.accessibilityCanInteract ?? this.DefaultAccessibilityCanInteract()) && this.CanReceiveGesture("Tapped"); }
|
|
406
718
|
set AccessibilityCanInteract(v) { if (this.accessibilityCanInteract !== v) {
|
|
407
719
|
this.accessibilityCanInteract = v;
|
|
408
720
|
this.AccessibilityChanged();
|
|
@@ -413,12 +725,21 @@ export class SkiaControl {
|
|
|
413
725
|
* host's pointer cursor. Default: the control as a whole (AccessibilityCanInteract); SkiaLabel adds its tappable spans.
|
|
414
726
|
*/
|
|
415
727
|
WantsPointerCursor(_x, _y) { return this.AccessibilityCanInteract; }
|
|
728
|
+
/** A range control's value for screen readers (slider, progress); undefined for everything else (drawnui-cross 6c). */
|
|
729
|
+
get AccessibilityValue() { return undefined; }
|
|
416
730
|
/** aria-pressed for toggles; undefined = not a toggle. */
|
|
417
731
|
get AccessibilityIsPressed() { return this.accessibilityIsPressed; }
|
|
418
732
|
set AccessibilityIsPressed(v) { if (this.accessibilityIsPressed !== v) {
|
|
419
733
|
this.accessibilityIsPressed = v;
|
|
420
734
|
this.AccessibilityChanged();
|
|
421
735
|
} }
|
|
736
|
+
accessibilityExpanded;
|
|
737
|
+
/** A control that opens something, such as a menu title: whether it is open now (aria-expanded). Unset: it opens nothing. */
|
|
738
|
+
get AccessibilityExpanded() { return this.accessibilityExpanded; }
|
|
739
|
+
set AccessibilityExpanded(v) { if (this.accessibilityExpanded !== v) {
|
|
740
|
+
this.accessibilityExpanded = v;
|
|
741
|
+
this.AccessibilityChanged();
|
|
742
|
+
} }
|
|
422
743
|
/** aria-live: `Aria.LivePolite` / `Aria.LiveAssertive`; changes are announced immediately. */
|
|
423
744
|
get AccessibilityLive() { return this.accessibilityLive; }
|
|
424
745
|
set AccessibilityLive(v) { if (this.accessibilityLive !== v) {
|
|
@@ -437,8 +758,6 @@ export class SkiaControl {
|
|
|
437
758
|
this.accessibilityTextSelectable = v;
|
|
438
759
|
this.AccessibilityChanged();
|
|
439
760
|
} }
|
|
440
|
-
/** Text lines for AccessibilityTextSelectable in CSS px relative to the node (SkiaLabel implements it). */
|
|
441
|
-
GetAccessibilityTextLines(_scale) { return []; }
|
|
442
761
|
/** Hit rect in canvas pixels used to position the overlay element: the drawn (transformed) bounds, like C# HitBoxWithTransforms. */
|
|
443
762
|
GetAccessibilityPixelRect() {
|
|
444
763
|
const r = this.DrawingRect, m = this.RenderTransformMatrix;
|
|
@@ -487,6 +806,39 @@ export class SkiaControl {
|
|
|
487
806
|
}
|
|
488
807
|
/** Overlay focus arrives on / leaves this node (inputs may activate their sink here). */
|
|
489
808
|
OnAccessibilityFocused(_focused) { }
|
|
809
|
+
/**
|
|
810
|
+
* Keyboard navigation hands this control the keys it may use while it holds keyboard focus (ArrowLeft / Right / Up /
|
|
811
|
+
* Down, Home, End, PageUp, PageDown, DOM `event.code` names). Return true when the key was used; the default uses none,
|
|
812
|
+
* so the key moves focus inside the arrow-key group around the control.
|
|
813
|
+
*/
|
|
814
|
+
OnAccessibilityKey(_key) { return false; }
|
|
815
|
+
/**
|
|
816
|
+
* Whether a pointer gesture of this kind would reach this control, by the rules the gesture dispatch applies: the
|
|
817
|
+
* control and every ancestor draw, none of them is InputTransparent, no ancestor keeps this gesture from its children
|
|
818
|
+
* (LockChildrenGestures, PassNone included) and the control accepts input (AcceptsInput). Opacity does not count, as
|
|
819
|
+
* for the pointer. Keyboard navigation uses it: Tapped for Tab and Enter / Space, Panning for the arrow keys.
|
|
820
|
+
*/
|
|
821
|
+
CanReceiveGesture(gesture) {
|
|
822
|
+
if (!this.IsVisible || this.IsDisposed || this.InputTransparent || !this.AcceptsInput())
|
|
823
|
+
return false;
|
|
824
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
825
|
+
if (!p.IsVisible || p.IsDisposed || p.InputTransparent || p.CheckChildrenGesturesLocked(gesture))
|
|
826
|
+
return false;
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* False while the control ignores input itself: RespondsToGestures = false on a button, toggle, slider, scroll...
|
|
831
|
+
* Taps, keyboard and the accessibility state (reported disabled) all follow it (drawnui-cross 6w). Default true.
|
|
832
|
+
*/
|
|
833
|
+
AcceptsInput() { return true; }
|
|
834
|
+
/**
|
|
835
|
+
* What a control that takes no input returns for a gesture that reached it (C# BlockedGestureResult): it keeps a
|
|
836
|
+
* press, tap or long press, so nothing under it reacts to them, and lets moves and wheel go on to the controls around
|
|
837
|
+
* it (a scroll behind it still scrolls).
|
|
838
|
+
*/
|
|
839
|
+
BlockedGestureResult(args) {
|
|
840
|
+
return args.Type === "Down" || args.Type === "Tapped" || args.Type === "LongPressing" ? this : null;
|
|
841
|
+
}
|
|
490
842
|
NotifyAccessibilityFocused(focused) { this.Superview?.AccessibilityManager.NotifyFocused(focused ? this : undefined); }
|
|
491
843
|
/** DrawnUi SmartMax: larger of two sizes, an infinite one loses. */
|
|
492
844
|
static SmartMax(a, b) {
|
|
@@ -500,6 +852,16 @@ export class SkiaControl {
|
|
|
500
852
|
return b;
|
|
501
853
|
return a;
|
|
502
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* Center (as DrawnUI for Rust and .NET): the box centered in the whole space, then moved by the full margin difference
|
|
857
|
+
* (start minus end), kept inside the space when it fits.
|
|
858
|
+
*/
|
|
859
|
+
static Centered(start, space, size, shift) {
|
|
860
|
+
let at = start + (space - size) / 2 + shift;
|
|
861
|
+
if (size <= space)
|
|
862
|
+
at = Math.min(Math.max(at, start), start + space - size);
|
|
863
|
+
return at;
|
|
864
|
+
}
|
|
503
865
|
static Align(o, avail, size) {
|
|
504
866
|
if (o === "Center")
|
|
505
867
|
return (avail - size) / 2;
|
|
@@ -509,6 +871,8 @@ export class SkiaControl {
|
|
|
509
871
|
}
|
|
510
872
|
/** Called after DrawingRect changed; layouts arrange children here. */
|
|
511
873
|
OnLayoutChanged() { }
|
|
874
|
+
/** A control in CanvasLeaveWatchers left its canvas (removed or disposed): it lets go of what it held there. */
|
|
875
|
+
OnLeftCanvas() { }
|
|
512
876
|
/** Part of DrawingRect that can actually be seen: intersected with every ancestor (a scroll's box clips its content). */
|
|
513
877
|
GetVisibleViewport() {
|
|
514
878
|
const r = this.DrawingRect;
|
|
@@ -548,12 +912,36 @@ export class SkiaControl {
|
|
|
548
912
|
Render(ctx) {
|
|
549
913
|
if (!this.IsVisible || this.Opacity <= 0 || this.IsDisposed)
|
|
550
914
|
return;
|
|
915
|
+
// parent-independent: its own change stopped at it (the parent does not lay out again), so it measures itself again
|
|
916
|
+
// in the slot it was given, before it draws (C# IsParentIndependent)
|
|
917
|
+
const slot = this.arrangedIn;
|
|
918
|
+
if (this.IsParentIndependent && this.NeedMeasure && slot) {
|
|
919
|
+
this.Measure(slot.Width, slot.Height, ctx.Scale);
|
|
920
|
+
this.Arrange(slot, this.WidthRequest, this.HeightRequest, ctx.Scale);
|
|
921
|
+
}
|
|
551
922
|
const canvas = ctx.Context.Canvas;
|
|
552
923
|
const applyOpacity = this.Opacity < 1;
|
|
553
924
|
// C# Left/Top: a cached control is blitted at an offset, no matrix and no save/restore around the subtree
|
|
554
925
|
const offsetOnly = (this.Left !== 0 || this.Top !== 0) && this.UsingCacheType !== "None" && this.TranslationX === 0 && this.TranslationY === 0
|
|
555
|
-
&& this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0;
|
|
926
|
+
&& this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !this.Has3d;
|
|
556
927
|
const needTransform = this.HasTransform && !offsetOnly;
|
|
928
|
+
let dx = 0, dy = 0;
|
|
929
|
+
if (needTransform) {
|
|
930
|
+
this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
|
|
931
|
+
}
|
|
932
|
+
else if (offsetOnly) {
|
|
933
|
+
dx = this.Left * ctx.Scale;
|
|
934
|
+
dy = this.Top * ctx.Scale;
|
|
935
|
+
this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
|
|
936
|
+
}
|
|
937
|
+
else {
|
|
938
|
+
this.RenderTransformMatrix = undefined;
|
|
939
|
+
}
|
|
940
|
+
// drawn entirely outside the clip: skipped with its subtree (C# layout Virtualisation, DrawnUi.Rust); the matrix
|
|
941
|
+
// above stays current for hit tests. A cache that must be recorded is still recorded here, as before, so its cost
|
|
942
|
+
// does not move into the frame where the control scrolls in (DrawnUi.Rust records it then)
|
|
943
|
+
if (this.OutsideClip(canvas, ctx.Scale) && !this.CacheStale(ctx.Scale))
|
|
944
|
+
return;
|
|
557
945
|
let saved = false;
|
|
558
946
|
// same as DrawnUi: opacity = a layer with alpha, transforms = canvas matrix around the whole subtree (cache included)
|
|
559
947
|
if (applyOpacity) {
|
|
@@ -567,19 +955,8 @@ export class SkiaControl {
|
|
|
567
955
|
canvas.save();
|
|
568
956
|
saved = true;
|
|
569
957
|
}
|
|
570
|
-
|
|
571
|
-
if (needTransform) {
|
|
572
|
-
this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
|
|
958
|
+
if (needTransform)
|
|
573
959
|
canvas.concat(this.RenderTransformMatrix);
|
|
574
|
-
}
|
|
575
|
-
else if (offsetOnly) {
|
|
576
|
-
dx = this.Left * ctx.Scale;
|
|
577
|
-
dy = this.Top * ctx.Scale;
|
|
578
|
-
this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
this.RenderTransformMatrix = undefined;
|
|
582
|
-
}
|
|
583
960
|
if (this.IsClippedToBounds) {
|
|
584
961
|
if (!saved) {
|
|
585
962
|
canvas.save();
|
|
@@ -592,11 +969,12 @@ export class SkiaControl {
|
|
|
592
969
|
if (saved)
|
|
593
970
|
canvas.restore();
|
|
594
971
|
}
|
|
595
|
-
/** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · T(pivot) · translation, in canvas pixels. */
|
|
972
|
+
/** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · 3D · T(pivot) · translation, in canvas pixels. */
|
|
596
973
|
CreateRenderTransformMatrix(destination, scale) {
|
|
597
974
|
const M = Super.CK.Matrix;
|
|
598
975
|
const moveX = (this.TranslationX + this.Left) * scale, moveY = (this.TranslationY + this.Top) * scale;
|
|
599
|
-
|
|
976
|
+
const has3d = this.Has3d;
|
|
977
|
+
if (this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !has3d)
|
|
600
978
|
return M.translated(moveX, moveY);
|
|
601
979
|
const px = destination.Left + destination.Width * this.AnchorX;
|
|
602
980
|
const py = destination.Top + destination.Height * this.AnchorY;
|
|
@@ -605,7 +983,36 @@ export class SkiaControl {
|
|
|
605
983
|
const scaleSkew = [this.ScaleX, kx, 0, ky, this.ScaleY, 0, 0, 0, 1];
|
|
606
984
|
const rotation = this.Rotation !== 0 ? M.rotated((Math.PI * this.Rotation) / 180) : M.identity();
|
|
607
985
|
// multiply(a, b, c) = a·b·c, the right-most applies first
|
|
608
|
-
|
|
986
|
+
if (!has3d)
|
|
987
|
+
return M.multiply(M.translated(px + moveX, py + moveY), scaleSkew, rotation, M.translated(-px, -py));
|
|
988
|
+
return M.multiply(M.translated(px + moveX, py + moveY), SkiaControl.Create3dMatrix(this.RotationX, this.RotationY, this.RotationZ, this.TranslationZ), scaleSkew, rotation, M.translated(-px, -py));
|
|
989
|
+
}
|
|
990
|
+
/** C# camera distance of the 3D transforms (Sk3dView.CameraDistance): 8 inches at 72 dpi, in canvas pixels. */
|
|
991
|
+
static CameraDistance = 576;
|
|
992
|
+
/**
|
|
993
|
+
* C# Create3dMatrix (Sk3dView): RotationX, then RotationY, then RotationZ (negated) around the pivot, projected from
|
|
994
|
+
* the camera; TranslationZ is depth, a flat control at depth z draws at camera / (camera − z).
|
|
995
|
+
*/
|
|
996
|
+
static Create3dMatrix(rotationX, rotationY, rotationZ, translationZ) {
|
|
997
|
+
const d = Math.PI / 180, camera = SkiaControl.CameraDistance;
|
|
998
|
+
const sx = Math.sin(rotationX * d), cx = Math.cos(rotationX * d), sy = Math.sin(rotationY * d), cy = Math.cos(rotationY * d);
|
|
999
|
+
const sz = Math.sin(-rotationZ * d), cz = Math.cos(-rotationZ * d);
|
|
1000
|
+
return [
|
|
1001
|
+
cy * cz, cy * sz, 0,
|
|
1002
|
+
sx * sy * cz - cx * sz, sx * sy * sz + cx * cz, 0,
|
|
1003
|
+
(cx * sy * cz + sx * sz) / camera, (cx * sy * sz - sx * cz) / camera, Math.max(camera - translationZ, 1) / camera,
|
|
1004
|
+
];
|
|
1005
|
+
}
|
|
1006
|
+
/** C# SkiaSamplingOptions.IsMoveOnly: the matrix only moves (or mirrors), so a bitmap keeps its pixels 1:1. */
|
|
1007
|
+
static IsMoveOnly(m) {
|
|
1008
|
+
return m[1] === 0 && m[3] === 0 && m[6] === 0 && m[7] === 0 && m[8] === 1 && Math.abs(m[0]) === 1 && Math.abs(m[4]) === 1;
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* C# WillDrawDistorted: what this control draws here ends up scaled, turned, skewed or projected, by its own transforms
|
|
1012
|
+
* or a live ancestor's (both in the canvas matrix) or by the picture it is recorded into. Images then sample smoothly.
|
|
1013
|
+
*/
|
|
1014
|
+
WillDrawDistorted(ctx) {
|
|
1015
|
+
return !!ctx.Context.PlaybackDistorted || !SkiaControl.IsMoveOnly(ctx.Context.Canvas.getTotalMatrix());
|
|
609
1016
|
}
|
|
610
1017
|
/** Maps a point given in the parent's space into this control's untransformed space (DrawnUi TransformPointToLocalSpace). */
|
|
611
1018
|
TransformPointToLocalSpace(point) {
|
|
@@ -641,26 +1048,39 @@ export class SkiaControl {
|
|
|
641
1048
|
}
|
|
642
1049
|
else {
|
|
643
1050
|
const r = cacheType === "Operations" ? this.ExpandedCacheRect(ctx.Scale) : this.AlignedCacheRect(ctx.Scale);
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
1051
|
+
const epoch = this.Superview?.GpuEpoch ?? 0;
|
|
1052
|
+
if (this.RenderObjectPrevious && this.RenderObjectPrevious.Epoch !== epoch)
|
|
1053
|
+
this.DisposePrevious(); // made on a lost GPU context
|
|
1054
|
+
// a picture replays its image blits with the sampling chosen when it was recorded: recorded again once its
|
|
1055
|
+
// playback turns distorted or straight (C# SamplingMismatch), else a cached child of a turning card stays jagged
|
|
1056
|
+
const o = this.RenderObject;
|
|
1057
|
+
if (this.CacheStale(ctx.Scale) || (o?.Picture && o.HasImageBlits && o.PlaybackDistorted !== this.WillDrawDistorted(ctx)))
|
|
648
1058
|
this.CreateRenderingObject({ ...ctx, Destination: this.DrawingRect }, cacheType);
|
|
649
1059
|
if (this.RenderObject) {
|
|
650
|
-
// C# DrawRenderObject: with post renderers
|
|
651
|
-
//
|
|
652
|
-
|
|
653
|
-
|
|
1060
|
+
// C# DrawRenderObject: with post renderers a cache is not blitted, the effects sample it (CachedImage) and paint
|
|
1061
|
+
// the result, so the shader replaces the control; a picture cache hands them its picture drawn into an image
|
|
1062
|
+
// (made once per cache, C# GetPictureImage); drawn as before only when that image could not be made
|
|
1063
|
+
const cache = this.RenderObject;
|
|
1064
|
+
if (post.length > 0 && cache.Picture)
|
|
1065
|
+
cache.GetPictureImage(ctx.Context.Surface);
|
|
1066
|
+
if (post.length === 0 || !(cache.Image ?? cache.PictureImage))
|
|
1067
|
+
this.DrawCache(cache, ctx, r.Left + dx, r.Top + dy);
|
|
654
1068
|
for (const e of post)
|
|
655
1069
|
e.Render(own);
|
|
656
1070
|
}
|
|
657
1071
|
else if (this.RenderObjectPrevious)
|
|
658
|
-
this.
|
|
1072
|
+
this.DrawCache(this.RenderObjectPrevious, ctx, r.Left + dx, r.Top + dy); // double buffer: last good frame
|
|
659
1073
|
else
|
|
660
1074
|
this.DrawPlaceholder(own);
|
|
661
1075
|
}
|
|
662
1076
|
this.ExecutePostAnimators(own);
|
|
663
1077
|
}
|
|
1078
|
+
/** Blits a cache: an image samples smoothly when drawn distorted; a picture being recorded learns it holds image blits. */
|
|
1079
|
+
DrawCache(cache, ctx, left, top) {
|
|
1080
|
+
if (cache.Image || cache.HasImageBlits)
|
|
1081
|
+
ctx.Context.HasImageBlits = true;
|
|
1082
|
+
cache.Draw(ctx.Context.Canvas, left, top, !!cache.Image && this.WillDrawDistorted(ctx));
|
|
1083
|
+
}
|
|
664
1084
|
/** Background + Paint(): the part of the control that a cache captures. */
|
|
665
1085
|
PaintContent(ctx) {
|
|
666
1086
|
if (this.BackgroundColor || (this.FillGradient && this.FillGradientPaintsBackground()) || this.PaintsBackgroundWithoutColor())
|
|
@@ -682,6 +1102,9 @@ export class SkiaControl {
|
|
|
682
1102
|
// includes what shadows/effects paint outside the box; image caches on whole pixels
|
|
683
1103
|
const r = cacheType === "Operations" ? this.ExpandedCacheRect(ctx.Scale) : this.AlignedCacheRect(ctx.Scale);
|
|
684
1104
|
const w = Math.max(1, Math.round(r.Width)), h = Math.max(1, Math.round(r.Height));
|
|
1105
|
+
// clean from here on: a change made while the content records (a child shows a sibling as it paints, an event raised
|
|
1106
|
+
// as a control draws) leaves the cache stale, and the next frame records it again
|
|
1107
|
+
this.cacheDirty = false;
|
|
685
1108
|
if (cacheType === "ImageDoubleBuffered") {
|
|
686
1109
|
// keep the previous frame as the fallback until the new cache exists
|
|
687
1110
|
if (this.RenderObject) {
|
|
@@ -695,11 +1118,16 @@ export class SkiaControl {
|
|
|
695
1118
|
}
|
|
696
1119
|
if (cacheType === "Operations") {
|
|
697
1120
|
const recorder = new CK.PictureRecorder();
|
|
1121
|
+
const playbackDistorted = this.WillDrawDistorted(ctx);
|
|
698
1122
|
const canvas = recorder.beginRecording(CK.LTRBRect(r.Left, r.Top, r.Right, r.Bottom));
|
|
699
|
-
|
|
1123
|
+
const recording = { ...ctx.Context, Canvas: canvas, Recording: true, PlaybackDistorted: playbackDistorted, HasImageBlits: false };
|
|
1124
|
+
this.PaintContent({ ...ctx, Context: recording });
|
|
700
1125
|
const picture = recorder.finishRecordingAsPicture();
|
|
701
1126
|
recorder.delete();
|
|
702
1127
|
this.RenderObject = new CachedObject("Operations", r, ctx.Scale, picture);
|
|
1128
|
+
this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
|
|
1129
|
+
this.RenderObject.PlaybackDistorted = playbackDistorted;
|
|
1130
|
+
this.RenderObject.HasImageBlits = recording.HasImageBlits;
|
|
703
1131
|
}
|
|
704
1132
|
else if (cacheType === "ImageComposite") {
|
|
705
1133
|
this.CreateCompositeRenderingObject(ctx, r, w, h);
|
|
@@ -707,11 +1135,13 @@ export class SkiaControl {
|
|
|
707
1135
|
else {
|
|
708
1136
|
const main = ctx.Context.Surface;
|
|
709
1137
|
if (!main) {
|
|
1138
|
+
this.cacheDirty = true;
|
|
710
1139
|
this.PaintContent(ctx);
|
|
711
1140
|
return;
|
|
712
1141
|
} // no surface to derive from (e.g. recording): draw live
|
|
713
1142
|
const offscreen = main.makeSurface({ ...main.imageInfo(), width: w, height: h });
|
|
714
1143
|
if (!offscreen) {
|
|
1144
|
+
this.cacheDirty = true;
|
|
715
1145
|
if (!this.RenderObjectPrevious)
|
|
716
1146
|
this.PaintContent(ctx);
|
|
717
1147
|
return;
|
|
@@ -723,8 +1153,8 @@ export class SkiaControl {
|
|
|
723
1153
|
const image = offscreen.makeImageSnapshot();
|
|
724
1154
|
offscreen.delete();
|
|
725
1155
|
this.RenderObject = new CachedObject(cacheType, r, ctx.Scale, undefined, image);
|
|
1156
|
+
this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
|
|
726
1157
|
}
|
|
727
|
-
this.cacheDirty = false;
|
|
728
1158
|
}
|
|
729
1159
|
/**
|
|
730
1160
|
* C# ImageComposite (SetupRenderingWithComposition + CreateRenderingObject reuse): the offscreen surface survives
|
|
@@ -741,7 +1171,9 @@ export class SkiaControl {
|
|
|
741
1171
|
}
|
|
742
1172
|
let surface = this.compositeSurface;
|
|
743
1173
|
const prev = this.RenderObject;
|
|
744
|
-
const
|
|
1174
|
+
const epoch = this.Superview?.GpuEpoch ?? 0;
|
|
1175
|
+
// the kept surface belongs to the GPU context it was made on: after a context restore it is made again
|
|
1176
|
+
const sameGeometry = !!surface && !!prev && prev.Type === "ImageComposite" && prev.Scale === ctx.Scale && prev.Epoch === epoch
|
|
745
1177
|
&& Math.round(prev.Bounds.Width) === w && Math.round(prev.Bounds.Height) === h;
|
|
746
1178
|
if (!sameGeometry) {
|
|
747
1179
|
surface?.delete();
|
|
@@ -754,16 +1186,48 @@ export class SkiaControl {
|
|
|
754
1186
|
}
|
|
755
1187
|
const canvas = surface.getCanvas();
|
|
756
1188
|
const children = this.GetCompositeChildren();
|
|
757
|
-
const
|
|
1189
|
+
const deep = this.compositeDeep;
|
|
1190
|
+
// the same size with another effects margin moves the content inside the surface: record whole (C# 97683f19)
|
|
1191
|
+
const insetX = r.Left - this.DrawingRect.Left, insetY = r.Top - this.DrawingRect.Top;
|
|
1192
|
+
const sameInset = insetX === this.compositeInsetX && insetY === this.compositeInsetY;
|
|
1193
|
+
this.compositeInsetX = insetX;
|
|
1194
|
+
this.compositeInsetY = insetY;
|
|
1195
|
+
let partial = sameGeometry && sameInset && !this.compositeFull && children.length > 0 && (this.DirtyChildrenInternal.size > 0 || !!deep?.length);
|
|
1196
|
+
// changes deeper than a child: only their areas, the child they are in drawn clipped to them (drawnui-cross 6m)
|
|
1197
|
+
const areas = [], changed = [], inside = new Set();
|
|
1198
|
+
if (partial && deep?.length) {
|
|
1199
|
+
let covered = 0;
|
|
1200
|
+
for (const d of deep) {
|
|
1201
|
+
if (!children.includes(d.Child) || this.DirtyChildrenInternal.has(d.Child))
|
|
1202
|
+
continue;
|
|
1203
|
+
const area = SkiaControl.DeepArea(d, this, ctx.Scale);
|
|
1204
|
+
if (area === null) {
|
|
1205
|
+
partial = false;
|
|
1206
|
+
break;
|
|
1207
|
+
}
|
|
1208
|
+
if (!area) {
|
|
1209
|
+
this.DirtyChildrenInternal.add(d.Child);
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
areas.push(area);
|
|
1213
|
+
changed.push(d.Origin);
|
|
1214
|
+
inside.add(d.Child);
|
|
1215
|
+
covered += area.Width * area.Height;
|
|
1216
|
+
}
|
|
1217
|
+
if (areas.length > SkiaControl.MaxCompositionAreas || covered > r.Width * r.Height * SkiaControl.MaxCompositionShare)
|
|
1218
|
+
partial = false;
|
|
1219
|
+
}
|
|
1220
|
+
if (deep)
|
|
1221
|
+
deep.length = 0;
|
|
758
1222
|
const offset = prev && sameGeometry ? { X: r.Left - prev.Bounds.Left, Y: r.Top - prev.Bounds.Top } : { X: 0, Y: 0 };
|
|
759
1223
|
const saved = canvas.save();
|
|
760
1224
|
canvas.translate(-r.Left, -r.Top);
|
|
761
1225
|
if (partial) {
|
|
762
1226
|
// dirty = reported children + siblings intersecting their old or new bounds (C# makes intersecting children dirty too)
|
|
763
1227
|
const dirty = new Set();
|
|
764
|
-
const rects = [];
|
|
1228
|
+
const rects = [...areas];
|
|
765
1229
|
const boundsOf = (c) => {
|
|
766
|
-
const out = [c.
|
|
1230
|
+
const out = [c.GetCurrentDirtyBounds()]; // where it goes, from its current values, and where it was
|
|
767
1231
|
if (c.lastCompositeBounds)
|
|
768
1232
|
out.push(new SKRect(c.lastCompositeBounds.Left + offset.X, c.lastCompositeBounds.Top + offset.Y, c.lastCompositeBounds.Right + offset.X, c.lastCompositeBounds.Bottom + offset.Y));
|
|
769
1233
|
return out;
|
|
@@ -777,7 +1241,7 @@ export class SkiaControl {
|
|
|
777
1241
|
while (grew) {
|
|
778
1242
|
grew = false;
|
|
779
1243
|
for (const c of children) {
|
|
780
|
-
if (dirty.has(c) || !c.IsVisible)
|
|
1244
|
+
if (dirty.has(c) || inside.has(c) || !c.IsVisible)
|
|
781
1245
|
continue;
|
|
782
1246
|
const own = boundsOf(c);
|
|
783
1247
|
if (rects.some((d) => own.some((o) => o.Left < d.Right && d.Left < o.Right && o.Top < d.Bottom && d.Top < o.Bottom))) {
|
|
@@ -804,14 +1268,18 @@ export class SkiaControl {
|
|
|
804
1268
|
this.DirtyChildrenInternal.clear();
|
|
805
1269
|
for (const c of dirty)
|
|
806
1270
|
this.DirtyChildrenInternal.add(c);
|
|
1271
|
+
for (const c of inside)
|
|
1272
|
+
this.DirtyChildrenInternal.add(c);
|
|
1273
|
+
// children entirely outside the redrawn areas are skipped by their own clip check (Render)
|
|
807
1274
|
this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
|
|
808
1275
|
this.IsRenderingWithComposition = false;
|
|
809
|
-
|
|
1276
|
+
const redrawn = children.filter((c) => this.DirtyChildrenInternal.has(c));
|
|
1277
|
+
this.LastCompositeRecord = { Mode: "partial", Children: redrawn.length, Dirty: redrawn, Areas: areas, Changed: changed };
|
|
810
1278
|
}
|
|
811
1279
|
else {
|
|
812
1280
|
canvas.clear(CK.TRANSPARENT);
|
|
813
1281
|
this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
|
|
814
|
-
this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children };
|
|
1282
|
+
this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children, Areas: [], Changed: [] };
|
|
815
1283
|
}
|
|
816
1284
|
canvas.restoreToCount(saved);
|
|
817
1285
|
for (const c of children)
|
|
@@ -821,6 +1289,7 @@ export class SkiaControl {
|
|
|
821
1289
|
const image = surface.makeImageSnapshot();
|
|
822
1290
|
const old = this.RenderObject;
|
|
823
1291
|
this.RenderObject = new CachedObject("ImageComposite", r, ctx.Scale, undefined, image);
|
|
1292
|
+
this.RenderObject.Epoch = epoch;
|
|
824
1293
|
if (old) {
|
|
825
1294
|
const sv = this.Superview;
|
|
826
1295
|
if (sv)
|
|
@@ -856,7 +1325,11 @@ export class SkiaControl {
|
|
|
856
1325
|
/** Marks the cache stale; re-recorded on the next frame (a composite records fully: its own content changed). */
|
|
857
1326
|
InvalidateCache() { this.cacheDirty = true; this.compositeFull = true; }
|
|
858
1327
|
/** Effects margin recomputed on the next use (C# InvalidateEffectsMargin). */
|
|
859
|
-
InvalidateEffectsMargin() {
|
|
1328
|
+
InvalidateEffectsMargin() {
|
|
1329
|
+
// a layout's margin aggregates what its children paint outside it: every ancestor recomputes too (C# 97683f19)
|
|
1330
|
+
for (let c = this; c; c = c.Parent)
|
|
1331
|
+
c.effectsMarginCache = undefined;
|
|
1332
|
+
}
|
|
860
1333
|
/** Draws PostAnimators above content; an effect returning true asks for another frame. */
|
|
861
1334
|
ExecutePostAnimators(ctx) {
|
|
862
1335
|
if (this.PostAnimators.length === 0)
|
|
@@ -888,6 +1361,8 @@ export class SkiaControl {
|
|
|
888
1361
|
paint.setAntiAlias(true);
|
|
889
1362
|
if (this.BackgroundColor)
|
|
890
1363
|
paint.setColor(Super.ParseColor(this.BackgroundColor));
|
|
1364
|
+
if (this.FillBlendMode !== "SrcOver")
|
|
1365
|
+
paint.setBlendMode(CK.BlendMode[this.FillBlendMode]);
|
|
891
1366
|
if (this.FillGradient && this.FillGradientPaintsBackground())
|
|
892
1367
|
this.SetupGradient(paint, this.FillGradient, rect);
|
|
893
1368
|
return paint;
|
|
@@ -989,9 +1464,16 @@ export class SkiaControl {
|
|
|
989
1464
|
ey = 0;
|
|
990
1465
|
return [sx, sy, ex, ey];
|
|
991
1466
|
}
|
|
992
|
-
/**
|
|
1467
|
+
/**
|
|
1468
|
+
* A gradient's Light: below 1 red, green and blue multiplied by Light (C# MakeDarker, as Rust); above 1 the HSL
|
|
1469
|
+
* lightness multiplied by Light, clamped to 1, hue and saturation kept (.NET MAUI Color.AddLuminosity, C# f77136c4).
|
|
1470
|
+
*/
|
|
993
1471
|
static AdjustLightness(rgb, light) {
|
|
994
1472
|
const [r, g, b] = rgb;
|
|
1473
|
+
if (light < 1) {
|
|
1474
|
+
const k = Math.max(0, light);
|
|
1475
|
+
return [r * k, g * k, b * k];
|
|
1476
|
+
}
|
|
995
1477
|
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
996
1478
|
let h = 0, s = 0;
|
|
997
1479
|
let l = (max + min) / 2;
|
|
@@ -1006,7 +1488,7 @@ export class SkiaControl {
|
|
|
1006
1488
|
h = (r - g) / d + 4;
|
|
1007
1489
|
h /= 6;
|
|
1008
1490
|
}
|
|
1009
|
-
l =
|
|
1491
|
+
l = l * light;
|
|
1010
1492
|
l = Math.max(0, Math.min(1, l));
|
|
1011
1493
|
if (s === 0)
|
|
1012
1494
|
return [l, l, l];
|
|
@@ -1031,13 +1513,21 @@ export class SkiaControl {
|
|
|
1031
1513
|
Dispose() {
|
|
1032
1514
|
if (this.IsDisposed)
|
|
1033
1515
|
return;
|
|
1516
|
+
// disposed while still on a canvas: its subtree's animators stop, once, from the top disposed control
|
|
1517
|
+
if (!this.Parent?.IsDisposed)
|
|
1518
|
+
this.Superview?.ControlLeft(this, true);
|
|
1034
1519
|
this.IsDisposed = true;
|
|
1520
|
+
if (this.accessibilityModal)
|
|
1521
|
+
AccessibilityModals.delete(this);
|
|
1035
1522
|
this.OnDisposing();
|
|
1036
1523
|
for (const c of this.ownAnimations.values())
|
|
1037
1524
|
c.abort();
|
|
1038
1525
|
this.ownAnimations.clear();
|
|
1039
1526
|
for (const e of [...this.PostAnimators])
|
|
1040
1527
|
e.Stop?.();
|
|
1528
|
+
for (const a of [...(this.PendingUnattachedAnimators ?? [])])
|
|
1529
|
+
a.Stop(); // waiting since it was removed: they end with it
|
|
1530
|
+
this.PendingUnattachedAnimators = undefined;
|
|
1041
1531
|
this.PostAnimators.length = 0;
|
|
1042
1532
|
this.DestroyRenderingObject();
|
|
1043
1533
|
this.compositeSurface?.delete();
|
|
@@ -1066,32 +1556,136 @@ export class SkiaControl {
|
|
|
1066
1556
|
}
|
|
1067
1557
|
/** Redraw without remeasure and WITHOUT dropping caches (position/overlay changes). */
|
|
1068
1558
|
Repaint() {
|
|
1069
|
-
this.
|
|
1559
|
+
if (!this.UnderHiddenParent())
|
|
1560
|
+
this.Superview?.Update();
|
|
1070
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* A parent (not the control itself) is hidden: a change here asks for no frame and the latest state shows when the
|
|
1564
|
+
* parent is shown again (C# 329f6c44 HiddenUpdateTests, DrawnUi.Rust hidden_updates). The control's own visibility
|
|
1565
|
+
* change still draws: it is the one that hides or shows it.
|
|
1566
|
+
*/
|
|
1567
|
+
UnderHiddenParent() {
|
|
1568
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1569
|
+
if (!p.IsVisible)
|
|
1570
|
+
return true;
|
|
1571
|
+
return false;
|
|
1572
|
+
}
|
|
1573
|
+
/** The control or a parent is hidden: its animators pause until it shows again. */
|
|
1574
|
+
HiddenInTree() { return !this.IsVisible || this.UnderHiddenParent(); }
|
|
1575
|
+
/** The control an invalidation started at while it climbs (InvalidateMeasure): a hidden parent of it wakes no frame. */
|
|
1576
|
+
static invalidateOrigin = null;
|
|
1071
1577
|
/**
|
|
1072
1578
|
* Transform / Opacity changed: this control's own cache is still valid (content unchanged) but every ancestor
|
|
1073
1579
|
* cache holds its composited output, so those are staled before redrawing (DrawnUi RedrawCanvas + parent invalidation).
|
|
1074
1580
|
*/
|
|
1075
1581
|
RepaintComposition() {
|
|
1076
|
-
|
|
1077
|
-
|
|
1582
|
+
this.ReportToComposites();
|
|
1583
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1078
1584
|
p.cacheDirty = true;
|
|
1079
|
-
p.TrackChildAsDirty(child);
|
|
1080
|
-
child = p;
|
|
1081
|
-
p = p.Parent;
|
|
1082
|
-
}
|
|
1083
1585
|
this.Repaint();
|
|
1084
1586
|
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Update() for a change of how this control looks, not of its size (a color set through props, C# NeedDraw): the same
|
|
1589
|
+
* re-measure and cache invalidation, but an ImageComposite above redraws only this control's area instead of
|
|
1590
|
+
* recording whole (drawnui-cross 6m). The record still goes whole when the control's rect changed after all.
|
|
1591
|
+
*/
|
|
1592
|
+
UpdateDraw() {
|
|
1593
|
+
this.ReportToComposites();
|
|
1594
|
+
const outer = SkiaControl.drawOrigin;
|
|
1595
|
+
SkiaControl.drawOrigin = this;
|
|
1596
|
+
try {
|
|
1597
|
+
this.InvalidateMeasure();
|
|
1598
|
+
}
|
|
1599
|
+
finally {
|
|
1600
|
+
SkiaControl.drawOrigin = outer;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* A change of this control that keeps its layout, to every ImageComposite above: a direct child is drawn again whole
|
|
1605
|
+
* (C# TrackChildAsDirty), a deeper control by its area, read now as it was drawn (its last matrix and effects margin).
|
|
1606
|
+
*/
|
|
1607
|
+
ReportToComposites() {
|
|
1608
|
+
let before;
|
|
1609
|
+
let child = this;
|
|
1610
|
+
for (let p = this.Parent; p; child = p, p = p.Parent) {
|
|
1611
|
+
if (!p.IsCacheComposite)
|
|
1612
|
+
continue;
|
|
1613
|
+
if (child === this) {
|
|
1614
|
+
p.TrackChildAsDirty(child);
|
|
1615
|
+
continue;
|
|
1616
|
+
}
|
|
1617
|
+
const deep = p.compositeDeep ??= [];
|
|
1618
|
+
if (deep.some((d) => d.Origin === this))
|
|
1619
|
+
continue;
|
|
1620
|
+
before ??= this.GetTransformedDirtyBounds();
|
|
1621
|
+
const r = this.DrawingRect;
|
|
1622
|
+
deep.push({ Origin: this, Child: child, Before: before, Rect: new SKRect(r.Left, r.Top, r.Right, r.Bottom) });
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
/** The matrix this control will be drawn with (Render), from its current properties; undefined when none. */
|
|
1626
|
+
CurrentMatrix(scale) {
|
|
1627
|
+
return this.HasTransform ? this.CreateRenderTransformMatrix(this.DrawingRect, scale) : undefined;
|
|
1628
|
+
}
|
|
1629
|
+
/** Where this control will be drawn: its rect grown by its effects margin, through its current matrix. */
|
|
1630
|
+
DrawnBoundsNow(scale) { return SkiaControl.MapRect(this.CurrentMatrix(scale), this.ExpandedCacheRect(scale)); }
|
|
1631
|
+
static MapRect(m, r) {
|
|
1632
|
+
if (!m)
|
|
1633
|
+
return r;
|
|
1634
|
+
const pts = Super.CK.Matrix.mapPoints(m, [r.Left, r.Top, r.Right, r.Top, r.Right, r.Bottom, r.Left, r.Bottom]);
|
|
1635
|
+
return new SKRect(Math.min(pts[0], pts[2], pts[4], pts[6]), Math.min(pts[1], pts[3], pts[5], pts[7]), Math.max(pts[0], pts[2], pts[4], pts[6]), Math.max(pts[1], pts[3], pts[5], pts[7]));
|
|
1636
|
+
}
|
|
1637
|
+
/** Its output depends on all of its content (a visual effect; a backdrop samples below): a change inside redraws it whole. */
|
|
1638
|
+
get SamplesContent() { return !this.DisableEffects && this.visualEffects.length > 0; }
|
|
1639
|
+
/**
|
|
1640
|
+
* Where a deep change shows inside the composite (drawnui-cross 6m rule b): the control as drawn before and as drawn
|
|
1641
|
+
* now, then through the transform of every ancestor up to the composite. undefined: draw the child whole (an effect
|
|
1642
|
+
* or a backdrop on the way, the control gone from the child); null: the layout changed, record whole.
|
|
1643
|
+
*/
|
|
1644
|
+
static DeepArea(d, composite, scale) {
|
|
1645
|
+
const o = d.Origin, r = o.DrawingRect;
|
|
1646
|
+
if (r.Left !== d.Rect.Left || r.Top !== d.Rect.Top || r.Right !== d.Rect.Right || r.Bottom !== d.Rect.Bottom)
|
|
1647
|
+
return null;
|
|
1648
|
+
if (!o.IsVisible)
|
|
1649
|
+
return undefined;
|
|
1650
|
+
const now = o.DrawnBoundsNow(scale);
|
|
1651
|
+
let area = new SKRect(Math.min(now.Left, d.Before.Left), Math.min(now.Top, d.Before.Top), Math.max(now.Right, d.Before.Right), Math.max(now.Bottom, d.Before.Bottom));
|
|
1652
|
+
let p = o.Parent, child = o;
|
|
1653
|
+
for (; p && p !== composite; child = p, p = p.Parent) {
|
|
1654
|
+
if (p.SamplesContent || !p.IsVisible)
|
|
1655
|
+
return undefined;
|
|
1656
|
+
area = SkiaControl.MapRect(p.CurrentMatrix(scale), area);
|
|
1657
|
+
}
|
|
1658
|
+
return p === composite && child === d.Child ? area : undefined;
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
|
|
1662
|
+
* stops here (ancestors composite again, nothing above re-measures). It measures itself again in its last slot when it
|
|
1663
|
+
* draws with NeedMeasure set. Used by SkiaScroll for its scroll bars and by SkiaLabelFps.
|
|
1664
|
+
*/
|
|
1665
|
+
IsParentIndependent = false;
|
|
1666
|
+
/** The slot its parent last arranged it in (a parent-independent control measures itself again there). */
|
|
1667
|
+
arrangedIn;
|
|
1085
1668
|
/** Size or content may have changed: this control and all ancestors remeasure and re-record. */
|
|
1086
1669
|
InvalidateMeasure() {
|
|
1087
1670
|
this.NeedMeasure = true;
|
|
1088
1671
|
this.cacheDirty = true;
|
|
1089
|
-
|
|
1672
|
+
// structure may change: a composite cannot patch it; a draw-only change (UpdateDraw) reported its area instead
|
|
1673
|
+
if (SkiaControl.drawOrigin === null || SkiaControl.drawOrigin === this)
|
|
1674
|
+
this.compositeFull = true;
|
|
1090
1675
|
this.effectsMarginCache = undefined;
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
this.
|
|
1676
|
+
const outer = SkiaControl.invalidateOrigin;
|
|
1677
|
+
SkiaControl.invalidateOrigin ??= this;
|
|
1678
|
+
try {
|
|
1679
|
+
if (this.Parent && this.IsParentIndependent)
|
|
1680
|
+
this.RepaintComposition();
|
|
1681
|
+
else if (this.Parent)
|
|
1682
|
+
this.Parent.InvalidateMeasure();
|
|
1683
|
+
else if (!SkiaControl.invalidateOrigin.UnderHiddenParent())
|
|
1684
|
+
this.Superview?.Update();
|
|
1685
|
+
}
|
|
1686
|
+
finally {
|
|
1687
|
+
SkiaControl.invalidateOrigin = outer;
|
|
1688
|
+
}
|
|
1095
1689
|
}
|
|
1096
1690
|
// ---- gestures (same names as DrawnUi) ----
|
|
1097
1691
|
/** Hit rect in pixels (no transforms in this port, so it is DrawingRect). */
|
|
@@ -1199,11 +1793,16 @@ export class SkiaControl {
|
|
|
1199
1793
|
return this;
|
|
1200
1794
|
return consumed ?? consumedDefault;
|
|
1201
1795
|
}
|
|
1796
|
+
/**
|
|
1797
|
+
* The gesture comes from a finger, a pen or the primary (left) mouse button (C# IsPrimaryPointer). Tap and press
|
|
1798
|
+
* animations (Ripple) play only for those: a right or middle click raises its events but shows no tap feedback.
|
|
1799
|
+
*/
|
|
1800
|
+
static IsPrimaryPointer(args) { return (args.Event.Pointer?.Button ?? "Left") === "Left"; }
|
|
1202
1801
|
/** Fires Tapped (after AnimationTapped feedback); true when a handler existed (= consumed), like DrawnUi SendTapped. */
|
|
1203
1802
|
SendTapped(args, apply) {
|
|
1204
1803
|
if (!this.Tapped)
|
|
1205
1804
|
return false;
|
|
1206
|
-
if (this.AnimationTapped === "Ripple") {
|
|
1805
|
+
if (this.AnimationTapped === "Ripple" && SkiaControl.IsPrimaryPointer(args)) {
|
|
1207
1806
|
const pts = this.GetOffsetInsideControlInPoints(apply.MappedLocation, apply.ChildOffset);
|
|
1208
1807
|
this.PlayRippleAnimation(this.TouchEffectColor, pts.X, pts.Y, true, this.AnimationTappedSpeed);
|
|
1209
1808
|
}
|
|
@@ -1249,14 +1848,21 @@ export class SkiaControl {
|
|
|
1249
1848
|
AnimateRangeAsync(callback, start, end, ms = 250, easing = Easing.Linear, cancel) {
|
|
1250
1849
|
return this.AnimateAsync((v) => callback(start + (end - start) * v), undefined, ms, easing, cancel);
|
|
1251
1850
|
}
|
|
1252
|
-
/**
|
|
1851
|
+
/**
|
|
1852
|
+
* One running animation per kind, like the per-property CancellationTokenSources in C#. A replaced animation rejects
|
|
1853
|
+
* with an AbortError for code that awaits it, and is quiet otherwise (as a cancelled, unobserved Task in .NET): no
|
|
1854
|
+
* "Uncaught (in promise)" in the console for fire-and-forget calls.
|
|
1855
|
+
*/
|
|
1253
1856
|
RunOwnAnimation(kind, run, cancel) {
|
|
1254
1857
|
this.ownAnimations.get(kind)?.abort();
|
|
1255
1858
|
const controller = new AbortController();
|
|
1256
1859
|
this.ownAnimations.set(kind, controller);
|
|
1257
1860
|
cancel?.addEventListener("abort", () => controller.abort(), { once: true });
|
|
1258
|
-
|
|
1861
|
+
const done = run(controller.signal).finally(() => { if (this.ownAnimations.get(kind) === controller)
|
|
1259
1862
|
this.ownAnimations.delete(kind); });
|
|
1863
|
+
done.catch((e) => { if (e?.name !== "AbortError")
|
|
1864
|
+
throw e; }); // only the abort is quiet
|
|
1865
|
+
return done;
|
|
1260
1866
|
}
|
|
1261
1867
|
FadeToAsync(end, ms = 250, easing = Easing.Linear, cancel) {
|
|
1262
1868
|
const start = this.Opacity;
|