drawnui-react 0.1.0-preview.41 → 0.1.0-preview.43
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 +89 -7
- package/SKIPPED.md +7 -7
- package/dist/controls/GridStructure.d.ts +9 -1
- package/dist/controls/GridStructure.js +41 -1
- package/dist/controls/SkiaEditor.d.ts +4 -1
- package/dist/controls/SkiaEditor.js +25 -6
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +32 -5
- package/dist/controls/SkiaLabel.d.ts +85 -4
- package/dist/controls/SkiaLabel.js +406 -20
- package/dist/controls/SkiaLabelFps.d.ts +0 -3
- package/dist/controls/SkiaLabelFps.js +1 -11
- package/dist/controls/SkiaLayout.js +33 -2
- package/dist/controls/SkiaScroll.d.ts +51 -2
- package/dist/controls/SkiaScroll.js +150 -9
- package/dist/controls/SkiaShape.d.ts +2 -0
- package/dist/controls/SkiaShape.js +7 -0
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSprite.js +5 -1
- package/dist/core/Accessibility.d.ts +30 -13
- package/dist/core/Accessibility.js +237 -43
- package/dist/core/Canvas.d.ts +122 -14
- package/dist/core/Canvas.js +585 -47
- package/dist/core/Gestures.d.ts +11 -1
- package/dist/core/Gestures.js +12 -1
- package/dist/core/PopupWindows.js +2 -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 +7 -1
- package/dist/core/SkiaControl.d.ts +24 -4
- package/dist/core/SkiaControl.js +59 -13
- package/dist/core/SkiaEffect.d.ts +12 -1
- package/dist/core/SkiaEffect.js +35 -8
- 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 +4 -0
- package/dist/core/Super.js +4 -9
- package/dist/core/TextInputProxy.d.ts +31 -1
- package/dist/core/TextInputProxy.js +97 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -514
- package/dist/react/index.d.ts +6 -1
- package/dist/react/index.js +51 -40
- package/dist/react/reconciler.d.ts +12 -0
- package/dist/react/reconciler.js +22 -46
- package/package.json +37 -4
package/dist/core/Gestures.d.ts
CHANGED
|
@@ -9,7 +9,15 @@ export declare class SKPoint {
|
|
|
9
9
|
}
|
|
10
10
|
/** Raw platform action (subset of TouchActionType). */
|
|
11
11
|
export type TouchActionType = "Pressed" | "Moved" | "Released" | "Cancelled" | "Wheel" | "Pointer";
|
|
12
|
-
/**
|
|
12
|
+
/** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
|
|
13
|
+
export declare class TouchEffect {
|
|
14
|
+
/**
|
|
15
|
+
* How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
|
|
16
|
+
* point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
|
|
17
|
+
*/
|
|
18
|
+
static LongPressTimeMsDefault: number;
|
|
19
|
+
}
|
|
20
|
+
/** Recognized gesture (TouchActionResult). LongPressing after TouchEffect.LongPressTimeMsDefault held still; Pointer / Touch declared for parity, not produced. */
|
|
13
21
|
export type TouchActionResult = "Touch" | "Down" | "Up" | "Tapped" | "LongPressing" | "Panning" | "Wheel" | "Pointer";
|
|
14
22
|
export type GesturesMode = "Disabled" | "Enabled" | "Lock";
|
|
15
23
|
export type LockTouch = "Disabled" | "Enabled" | "PassNone" | "PassTap" | "PassTapAndLongPress";
|
|
@@ -114,6 +122,7 @@ export declare class TouchActionEventArgs {
|
|
|
114
122
|
/** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
|
|
115
123
|
Manipulation?: ManipulationInfo;
|
|
116
124
|
Scale: number;
|
|
125
|
+
/** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
|
|
117
126
|
Timestamp: number;
|
|
118
127
|
/** ms since the previous event of the same pointer. */
|
|
119
128
|
DeltaTimeMs: number;
|
|
@@ -126,6 +135,7 @@ export declare class TouchActionEventArgs {
|
|
|
126
135
|
Wheel: {
|
|
127
136
|
Delta: number;
|
|
128
137
|
IsHorizontal?: boolean;
|
|
138
|
+
IsZoom?: boolean;
|
|
129
139
|
};
|
|
130
140
|
/**
|
|
131
141
|
* AppoMobi TouchActionEventArgs.Handled: set by a control that actually used the event. The canvas prevents the
|
package/dist/core/Gestures.js
CHANGED
|
@@ -10,6 +10,14 @@ export class SKPoint {
|
|
|
10
10
|
Add(p) { return new SKPoint(this.X + p.X, this.Y + p.Y); }
|
|
11
11
|
Subtract(p) { return new SKPoint(this.X - p.X, this.Y - p.Y); }
|
|
12
12
|
}
|
|
13
|
+
/** Gesture settings shared by every canvas (AppoMobi TouchEffect, same names on every DrawnUI engine). */
|
|
14
|
+
export class TouchEffect {
|
|
15
|
+
/**
|
|
16
|
+
* How long a press is held without moving past Canvas.TappedCancelMoveThresholdPoints to be a LongPressing, at the press
|
|
17
|
+
* point; its release sends no Tapped. A timer, no frames while waiting. Default 750 ms on every engine (drawnui-cross 6cf).
|
|
18
|
+
*/
|
|
19
|
+
static LongPressTimeMsDefault = 750;
|
|
20
|
+
}
|
|
13
21
|
/** TouchActionEventArgs.DistanceInfo. Velocity is pixels per second. */
|
|
14
22
|
export class DistanceInfo {
|
|
15
23
|
Start = SKPoint.Empty;
|
|
@@ -194,6 +202,7 @@ export class TouchActionEventArgs {
|
|
|
194
202
|
/** Panning while two or more fingers are down: how they pinched and turned since the previous move. */
|
|
195
203
|
Manipulation;
|
|
196
204
|
Scale = 1;
|
|
205
|
+
/** When the event happened (ms, performance.now() time): the browser event's timeStamp, now for one made in code. */
|
|
197
206
|
Timestamp = performance.now();
|
|
198
207
|
/** ms since the previous event of the same pointer. */
|
|
199
208
|
DeltaTimeMs = 0;
|
|
@@ -248,7 +257,9 @@ export class SkiaGesturesParameters {
|
|
|
248
257
|
const p = new SkiaGesturesParameters();
|
|
249
258
|
p.Type = action;
|
|
250
259
|
p.Event = args;
|
|
251
|
-
|
|
260
|
+
// when its event happened, not when a frame got to it (a slow frame holds the events back; a double tap is judged
|
|
261
|
+
// by when the taps happened)
|
|
262
|
+
p.ArrivedTimeNanos = Math.round(args.Timestamp * 1e6);
|
|
252
263
|
return p;
|
|
253
264
|
}
|
|
254
265
|
}
|
|
@@ -94,6 +94,8 @@ export class PopupLayer {
|
|
|
94
94
|
}
|
|
95
95
|
this.popups.push(popup);
|
|
96
96
|
this.UpdateKeyboardScope();
|
|
97
|
+
// its nodes join the accessibility tree with its first frame (a Tab right after it opened goes into it)
|
|
98
|
+
a11y.ForceRebuildOnNextFrame();
|
|
97
99
|
return popup.Id;
|
|
98
100
|
}
|
|
99
101
|
Close(id) { const p = this.popups.find((x) => x.Id === id); if (p)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A declared set of property values: names as the C# properties (the JSX props of a control). */
|
|
2
|
+
export type ControlProps = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Assigns the changed values of `next` straight onto the control (same names as the C# properties), as the React
|
|
5
|
+
* renderer does with JSX props; a value `prev` had and `next` lacks goes back to the control's default. Handler values
|
|
6
|
+
* (functions) are swapped without invalidating. Then the control is invalidated as little as the change needs: a size
|
|
7
|
+
* change re-measures, a look change redraws, a transform change only repaints the composition.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ApplyProps(inst: {
|
|
10
|
+
Update(): void;
|
|
11
|
+
}, prev: ControlProps | null, next: ControlProps): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SkiaControl } from "./SkiaControl";
|
|
2
|
+
/** Not properties of the control: React's own keys. */
|
|
3
|
+
const SKIP = new Set(["children", "key", "ref"]);
|
|
4
|
+
/** Props that change how the subtree is composited, not what it contains: repaint, keep caches (DrawnUi RedrawCanvas). */
|
|
5
|
+
const REPAINT_ONLY = new Set(["TranslationX", "TranslationY", "TranslationZ", "Rotation", "RotationX", "RotationY", "RotationZ", "ScaleX", "ScaleY", "Scale", "SkewX", "SkewY", "AnchorX", "AnchorY", "Opacity"]);
|
|
6
|
+
/** Props that change only how a control looks, never its size (C# NeedDraw): an ImageComposite above redraws only its area. */
|
|
7
|
+
const isDrawOnly = (k) => k.endsWith("Color") || k === "FillGradient" || k === "StrokeGradient";
|
|
8
|
+
/**
|
|
9
|
+
* Assigns the changed values of `next` straight onto the control (same names as the C# properties), as the React
|
|
10
|
+
* renderer does with JSX props; a value `prev` had and `next` lacks goes back to the control's default. Handler values
|
|
11
|
+
* (functions) are swapped without invalidating. Then the control is invalidated as little as the change needs: a size
|
|
12
|
+
* change re-measures, a look change redraws, a transform change only repaints the composition.
|
|
13
|
+
*/
|
|
14
|
+
export function ApplyProps(inst, prev, next) {
|
|
15
|
+
let changed = false, repaint = false, layout = false;
|
|
16
|
+
for (const k in next) {
|
|
17
|
+
if (SKIP.has(k) || (prev && prev[k] === next[k]))
|
|
18
|
+
continue;
|
|
19
|
+
inst[k] = next[k];
|
|
20
|
+
if (typeof next[k] === "function")
|
|
21
|
+
continue;
|
|
22
|
+
if (REPAINT_ONLY.has(k))
|
|
23
|
+
repaint = true;
|
|
24
|
+
else {
|
|
25
|
+
changed = true;
|
|
26
|
+
if (!isDrawOnly(k))
|
|
27
|
+
layout = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (prev)
|
|
31
|
+
for (const k in prev)
|
|
32
|
+
if (!SKIP.has(k) && !(k in next)) {
|
|
33
|
+
inst[k] = new inst.constructor()[k];
|
|
34
|
+
changed = layout = true;
|
|
35
|
+
}
|
|
36
|
+
if (changed && prev) {
|
|
37
|
+
if (layout || !(inst instanceof SkiaControl))
|
|
38
|
+
inst.Update();
|
|
39
|
+
else
|
|
40
|
+
inst.UpdateDraw();
|
|
41
|
+
}
|
|
42
|
+
else if (repaint && prev)
|
|
43
|
+
inst.RepaintComposition?.();
|
|
44
|
+
}
|
|
@@ -72,8 +72,14 @@ export declare class VelocityAccumulator {
|
|
|
72
72
|
private readonly samples;
|
|
73
73
|
private static readonly MaxSampleSize;
|
|
74
74
|
private static readonly ConsiderationTimeframeMs;
|
|
75
|
+
/** The clock (ms) the release is judged on, for checks that drive gestures on a virtual clock (C# ClockOverrideNanos). */
|
|
76
|
+
static Clock?: () => number;
|
|
75
77
|
Clear(): void;
|
|
76
78
|
CaptureVelocity(x: number, y: number, arrivedTimeNanos?: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* The release velocity from the samples of the last 150 ms before NOW (as DrawnUi.Net): after a short app freeze a
|
|
81
|
+
* flick handled late does not fling (samples are dated by when their events happened).
|
|
82
|
+
*/
|
|
77
83
|
CalculateFinalVelocity(clampAbsolute?: number): {
|
|
78
84
|
X: number;
|
|
79
85
|
Y: number;
|
|
@@ -199,6 +199,8 @@ export class VelocityAccumulator {
|
|
|
199
199
|
samples = [];
|
|
200
200
|
static MaxSampleSize = 5;
|
|
201
201
|
static ConsiderationTimeframeMs = 150;
|
|
202
|
+
/** The clock (ms) the release is judged on, for checks that drive gestures on a virtual clock (C# ClockOverrideNanos). */
|
|
203
|
+
static Clock;
|
|
202
204
|
Clear() { this.samples.length = 0; }
|
|
203
205
|
CaptureVelocity(x, y, arrivedTimeNanos = 0) {
|
|
204
206
|
const time = arrivedTimeNanos > 0 ? arrivedTimeNanos / 1e6 : performance.now();
|
|
@@ -214,8 +216,12 @@ export class VelocityAccumulator {
|
|
|
214
216
|
this.samples.shift();
|
|
215
217
|
this.samples.push({ X: x, Y: y, time });
|
|
216
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* The release velocity from the samples of the last 150 ms before NOW (as DrawnUi.Net): after a short app freeze a
|
|
221
|
+
* flick handled late does not fling (samples are dated by when their events happened).
|
|
222
|
+
*/
|
|
217
223
|
CalculateFinalVelocity(clampAbsolute = 0) {
|
|
218
|
-
const now = performance.now();
|
|
224
|
+
const now = VelocityAccumulator.Clock?.() ?? performance.now();
|
|
219
225
|
const relevant = this.samples.filter((s) => now - s.time <= VelocityAccumulator.ConsiderationTimeframeMs);
|
|
220
226
|
if (relevant.length === 0)
|
|
221
227
|
return { X: 0, Y: 0 };
|
|
@@ -4,6 +4,7 @@ import { type AnimatorBase, type IOverlayEffect } from "./Animators";
|
|
|
4
4
|
import { Easing } from "./Easing";
|
|
5
5
|
import type { Canvas } from "./Canvas";
|
|
6
6
|
import type { InputKey } from "./KeyboardManager";
|
|
7
|
+
import type { BlendMode } from "./ImageEffects";
|
|
7
8
|
import { ContextMenuEventArgs, ControlTappedEventArgs, GestureEventProcessingInfo, type LockTouch, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters } from "./Gestures";
|
|
8
9
|
import { type CachedTexture, type IPostRendererEffect, type SkiaEffect } from "./SkiaEffect";
|
|
9
10
|
/** Mirrors DrawnUi DrawingContext: ctx.Context.Canvas / Surface, ctx.Destination (pixels), ctx.Scale. */
|
|
@@ -104,6 +105,8 @@ export declare class SkiaControl {
|
|
|
104
105
|
BackgroundColor?: Color;
|
|
105
106
|
/** Gradient painted as the background (over BackgroundColor). */
|
|
106
107
|
FillGradient?: SkiaGradient;
|
|
108
|
+
/** Blend mode of the background fill, an SKBlendMode name (C# FillBlendMode); here a FillGradient's own BlendMode wins, on a SkiaShape this one does. */
|
|
109
|
+
FillBlendMode: BlendMode;
|
|
107
110
|
IsVisible: boolean;
|
|
108
111
|
Tag?: string;
|
|
109
112
|
TranslationX: number;
|
|
@@ -215,6 +218,12 @@ export declare class SkiaControl {
|
|
|
215
218
|
private OutsideClip;
|
|
216
219
|
/** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
|
|
217
220
|
GetTransformedDirtyBounds(): SKRect;
|
|
221
|
+
/**
|
|
222
|
+
* Where the control will be drawn next, from its current transform values: a translation set since the last render is
|
|
223
|
+
* already in (a composite parent erases and clips to this area before the child renders again).
|
|
224
|
+
*/
|
|
225
|
+
GetCurrentDirtyBounds(): SKRect;
|
|
226
|
+
private MapBounds;
|
|
218
227
|
/** Current cache, if any. */
|
|
219
228
|
RenderObject?: CachedObject;
|
|
220
229
|
private cacheDirty;
|
|
@@ -318,6 +327,12 @@ export declare class SkiaControl {
|
|
|
318
327
|
* `Children` list drops only these, so a control's own parts keep their place.
|
|
319
328
|
*/
|
|
320
329
|
IsChildrenItem: boolean;
|
|
330
|
+
/**
|
|
331
|
+
* C# UpdateNonStop (fluent): keeps frames coming while this control is on a canvas, for visuals that change by
|
|
332
|
+
* themselves (a time-driven shader, a clock drawn in code). An endless no-op animator, as C#; it waits for the canvas
|
|
333
|
+
* when the control is not on one yet and stops when the control is disposed. It holds the canvas at full frame rate.
|
|
334
|
+
*/
|
|
335
|
+
UpdateNonStop(): this;
|
|
321
336
|
AddSubView(_control: SkiaControl): void;
|
|
322
337
|
InsertSubView(_index: number, control: SkiaControl): void;
|
|
323
338
|
RemoveSubView(_control: SkiaControl): void;
|
|
@@ -447,8 +462,6 @@ export declare class SkiaControl {
|
|
|
447
462
|
*/
|
|
448
463
|
get AccessibilityTextSelectable(): boolean;
|
|
449
464
|
set AccessibilityTextSelectable(v: boolean);
|
|
450
|
-
/** Text lines for AccessibilityTextSelectable in CSS px relative to the node (SkiaLabel implements it). */
|
|
451
|
-
GetAccessibilityTextLines(_scale: number): import("./Accessibility").AccessibilityTextLine[];
|
|
452
465
|
/** Hit rect in canvas pixels used to position the overlay element: the drawn (transformed) bounds, like C# HitBoxWithTransforms. */
|
|
453
466
|
GetAccessibilityPixelRect(): SKRect;
|
|
454
467
|
/** Registers on first call, marks the snapshot dirty afterwards. */
|
|
@@ -489,6 +502,11 @@ export declare class SkiaControl {
|
|
|
489
502
|
protected static SmartMax(a: number, b: number): number;
|
|
490
503
|
/** DrawnUi SmartMin: smaller of two sizes, an infinite one loses. */
|
|
491
504
|
protected static SmartMin(a: number, b: number): number;
|
|
505
|
+
/**
|
|
506
|
+
* Center (as DrawnUI for Rust and .NET): the box centered in the whole space, then moved by the full margin difference
|
|
507
|
+
* (start minus end), kept inside the space when it fits.
|
|
508
|
+
*/
|
|
509
|
+
private static Centered;
|
|
492
510
|
private static Align;
|
|
493
511
|
/** Called after DrawingRect changed; layouts arrange children here. */
|
|
494
512
|
protected OnLayoutChanged(): void;
|
|
@@ -642,10 +660,12 @@ export declare class SkiaControl {
|
|
|
642
660
|
private static DeepArea;
|
|
643
661
|
/**
|
|
644
662
|
* DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
|
|
645
|
-
* stops here (ancestors composite again, nothing above re-measures).
|
|
646
|
-
* NeedMeasure
|
|
663
|
+
* stops here (ancestors composite again, nothing above re-measures). It measures itself again in its last slot when it
|
|
664
|
+
* draws with NeedMeasure set. Used by SkiaScroll for its scroll bars and by SkiaLabelFps.
|
|
647
665
|
*/
|
|
648
666
|
IsParentIndependent: boolean;
|
|
667
|
+
/** The slot its parent last arranged it in (a parent-independent control measures itself again there). */
|
|
668
|
+
private arrangedIn?;
|
|
649
669
|
/** Size or content may have changed: this control and all ancestors remeasure and re-record. */
|
|
650
670
|
InvalidateMeasure(): void;
|
|
651
671
|
/** Hit rect in pixels (no transforms in this port, so it is DrawingRect). */
|
package/dist/core/SkiaControl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
6
|
import { AccessibilityModals, Aria } from "./Accessibility";
|
|
7
7
|
import { ControlTappedEventArgs, GestureEventProcessingInfo, SKPoint, SkiaGesturesInfo, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
|
|
@@ -127,6 +127,8 @@ export class SkiaControl {
|
|
|
127
127
|
BackgroundColor;
|
|
128
128
|
/** Gradient painted as the background (over BackgroundColor). */
|
|
129
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";
|
|
130
132
|
IsVisible = true;
|
|
131
133
|
Tag;
|
|
132
134
|
// ---- render transforms (MAUI VisualElement names; points, applied at render around DrawingRect) ----
|
|
@@ -273,8 +275,14 @@ export class SkiaControl {
|
|
|
273
275
|
return canvas.quickReject(q);
|
|
274
276
|
}
|
|
275
277
|
/** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
|
|
276
|
-
GetTransformedDirtyBounds() {
|
|
277
|
-
|
|
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);
|
|
278
286
|
if (!m)
|
|
279
287
|
return r;
|
|
280
288
|
const pts = Super.CK.Matrix.mapPoints(m, [r.Left, r.Top, r.Right, r.Top, r.Right, r.Bottom, r.Left, r.Bottom]);
|
|
@@ -449,6 +457,12 @@ export class SkiaControl {
|
|
|
449
457
|
* `Children` list drops only these, so a control's own parts keep their place.
|
|
450
458
|
*/
|
|
451
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; }
|
|
452
466
|
AddSubView(_control) { throw new Error(`DrawnUi: ${this.constructor.name} cannot host children`); }
|
|
453
467
|
InsertSubView(_index, control) { this.AddSubView(control); }
|
|
454
468
|
RemoveSubView(_control) { }
|
|
@@ -550,6 +564,7 @@ export class SkiaControl {
|
|
|
550
564
|
}
|
|
551
565
|
/** Places MeasuredSize inside destination per Margin + Horizontal/VerticalOptions -> DrawingRect. */
|
|
552
566
|
Arrange(destination, _widthRequest, _heightRequest, scale) {
|
|
567
|
+
this.arrangedIn = destination;
|
|
553
568
|
const m = this.Margin;
|
|
554
569
|
const availL = destination.Left + m.Left * scale;
|
|
555
570
|
const availT = destination.Top + m.Top * scale;
|
|
@@ -564,12 +579,20 @@ export class SkiaControl {
|
|
|
564
579
|
availW = Math.ceil(availW * this.HorizontalFillRatio);
|
|
565
580
|
if (this.VerticalFillRatio !== 1)
|
|
566
581
|
availH = Math.ceil(availH * this.VerticalFillRatio);
|
|
567
|
-
|
|
568
|
-
|
|
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);
|
|
569
588
|
// Alignment happens inside the ORIGINAL box (Center/End of a capped control still center/end in the parent).
|
|
570
589
|
const fullW = destination.Width - m.HorizontalThickness * scale, fullH = destination.Height - m.VerticalThickness * scale;
|
|
571
|
-
const x =
|
|
572
|
-
|
|
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);
|
|
573
596
|
const old = this.DrawingRect;
|
|
574
597
|
this.DrawingRect = SKRect.Create(x, y, w, h);
|
|
575
598
|
this.FollowMatrix(old);
|
|
@@ -735,8 +758,6 @@ export class SkiaControl {
|
|
|
735
758
|
this.accessibilityTextSelectable = v;
|
|
736
759
|
this.AccessibilityChanged();
|
|
737
760
|
} }
|
|
738
|
-
/** Text lines for AccessibilityTextSelectable in CSS px relative to the node (SkiaLabel implements it). */
|
|
739
|
-
GetAccessibilityTextLines(_scale) { return []; }
|
|
740
761
|
/** Hit rect in canvas pixels used to position the overlay element: the drawn (transformed) bounds, like C# HitBoxWithTransforms. */
|
|
741
762
|
GetAccessibilityPixelRect() {
|
|
742
763
|
const r = this.DrawingRect, m = this.RenderTransformMatrix;
|
|
@@ -831,6 +852,16 @@ export class SkiaControl {
|
|
|
831
852
|
return b;
|
|
832
853
|
return a;
|
|
833
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
|
+
}
|
|
834
865
|
static Align(o, avail, size) {
|
|
835
866
|
if (o === "Center")
|
|
836
867
|
return (avail - size) / 2;
|
|
@@ -881,6 +912,13 @@ export class SkiaControl {
|
|
|
881
912
|
Render(ctx) {
|
|
882
913
|
if (!this.IsVisible || this.Opacity <= 0 || this.IsDisposed)
|
|
883
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
|
+
}
|
|
884
922
|
const canvas = ctx.Context.Canvas;
|
|
885
923
|
const applyOpacity = this.Opacity < 1;
|
|
886
924
|
// C# Left/Top: a cached control is blitted at an offset, no matrix and no save/restore around the subtree
|
|
@@ -1064,6 +1102,9 @@ export class SkiaControl {
|
|
|
1064
1102
|
// includes what shadows/effects paint outside the box; image caches on whole pixels
|
|
1065
1103
|
const r = cacheType === "Operations" ? this.ExpandedCacheRect(ctx.Scale) : this.AlignedCacheRect(ctx.Scale);
|
|
1066
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;
|
|
1067
1108
|
if (cacheType === "ImageDoubleBuffered") {
|
|
1068
1109
|
// keep the previous frame as the fallback until the new cache exists
|
|
1069
1110
|
if (this.RenderObject) {
|
|
@@ -1094,11 +1135,13 @@ export class SkiaControl {
|
|
|
1094
1135
|
else {
|
|
1095
1136
|
const main = ctx.Context.Surface;
|
|
1096
1137
|
if (!main) {
|
|
1138
|
+
this.cacheDirty = true;
|
|
1097
1139
|
this.PaintContent(ctx);
|
|
1098
1140
|
return;
|
|
1099
1141
|
} // no surface to derive from (e.g. recording): draw live
|
|
1100
1142
|
const offscreen = main.makeSurface({ ...main.imageInfo(), width: w, height: h });
|
|
1101
1143
|
if (!offscreen) {
|
|
1144
|
+
this.cacheDirty = true;
|
|
1102
1145
|
if (!this.RenderObjectPrevious)
|
|
1103
1146
|
this.PaintContent(ctx);
|
|
1104
1147
|
return;
|
|
@@ -1112,7 +1155,6 @@ export class SkiaControl {
|
|
|
1112
1155
|
this.RenderObject = new CachedObject(cacheType, r, ctx.Scale, undefined, image);
|
|
1113
1156
|
this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
|
|
1114
1157
|
}
|
|
1115
|
-
this.cacheDirty = false;
|
|
1116
1158
|
}
|
|
1117
1159
|
/**
|
|
1118
1160
|
* C# ImageComposite (SetupRenderingWithComposition + CreateRenderingObject reuse): the offscreen surface survives
|
|
@@ -1185,7 +1227,7 @@ export class SkiaControl {
|
|
|
1185
1227
|
const dirty = new Set();
|
|
1186
1228
|
const rects = [...areas];
|
|
1187
1229
|
const boundsOf = (c) => {
|
|
1188
|
-
const out = [c.
|
|
1230
|
+
const out = [c.GetCurrentDirtyBounds()]; // where it goes, from its current values, and where it was
|
|
1189
1231
|
if (c.lastCompositeBounds)
|
|
1190
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));
|
|
1191
1233
|
return out;
|
|
@@ -1319,6 +1361,8 @@ export class SkiaControl {
|
|
|
1319
1361
|
paint.setAntiAlias(true);
|
|
1320
1362
|
if (this.BackgroundColor)
|
|
1321
1363
|
paint.setColor(Super.ParseColor(this.BackgroundColor));
|
|
1364
|
+
if (this.FillBlendMode !== "SrcOver")
|
|
1365
|
+
paint.setBlendMode(CK.BlendMode[this.FillBlendMode]);
|
|
1322
1366
|
if (this.FillGradient && this.FillGradientPaintsBackground())
|
|
1323
1367
|
this.SetupGradient(paint, this.FillGradient, rect);
|
|
1324
1368
|
return paint;
|
|
@@ -1615,10 +1659,12 @@ export class SkiaControl {
|
|
|
1615
1659
|
}
|
|
1616
1660
|
/**
|
|
1617
1661
|
* DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
|
|
1618
|
-
* stops here (ancestors composite again, nothing above re-measures).
|
|
1619
|
-
* NeedMeasure
|
|
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.
|
|
1620
1664
|
*/
|
|
1621
1665
|
IsParentIndependent = false;
|
|
1666
|
+
/** The slot its parent last arranged it in (a parent-independent control measures itself again there). */
|
|
1667
|
+
arrangedIn;
|
|
1622
1668
|
/** Size or content may have changed: this control and all ancestors remeasure and re-record. */
|
|
1623
1669
|
InvalidateMeasure() {
|
|
1624
1670
|
this.NeedMeasure = true;
|
|
@@ -59,6 +59,14 @@ export declare function IsPostRendererEffect(e: SkiaEffect): e is SkiaEffect & I
|
|
|
59
59
|
* skipped, declared texture children that are not supplied sample transparent.
|
|
60
60
|
*/
|
|
61
61
|
export declare class SkiaShaderEffect extends SkiaEffect implements IPostRendererEffect {
|
|
62
|
+
/**
|
|
63
|
+
* The clock origin of every shader's iTime: the page time (ms) of the first shader frame, one for all effects so
|
|
64
|
+
* they stay in step (C# ShaderTimeOriginNanos). iTime is a float32 on the GPU: counted from the page load, a tab open
|
|
65
|
+
* for days would move it in visible steps (0.125 s after 18 days).
|
|
66
|
+
*/
|
|
67
|
+
static ShaderTimeOrigin?: number;
|
|
68
|
+
/** Seconds since the first shader frame for a page time in ms, taken in double before the GPU's float (C# GetShaderTime). */
|
|
69
|
+
static GetShaderTime(nowMs: number): number;
|
|
62
70
|
/** Url of the .sksl file (fetched once, compiled once per text). */
|
|
63
71
|
get ShaderSource(): string;
|
|
64
72
|
set ShaderSource(v: string);
|
|
@@ -79,7 +87,7 @@ export declare class SkiaShaderEffect extends SkiaEffect implements IPostRendere
|
|
|
79
87
|
MipmapMode: SkiaMipmapMode;
|
|
80
88
|
/** Tile mode of the input textures. */
|
|
81
89
|
TileMode: ShaderTileMode;
|
|
82
|
-
/** Set every Render
|
|
90
|
+
/** Set every Render: seconds since the first shader frame (GetShaderTime); can be driven manually. */
|
|
83
91
|
TimeSeconds: number;
|
|
84
92
|
/** Shadertoy iMouse.xy, pixels relative to the control. */
|
|
85
93
|
MouseCurrent: {
|
|
@@ -182,6 +190,9 @@ export declare class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
|
|
|
182
190
|
set PrimarySource(v: string);
|
|
183
191
|
get SecondarySource(): string;
|
|
184
192
|
set SecondarySource(v: string);
|
|
193
|
+
/** The textures it draws are held while it draws them (SkiaImageManager.Hold / Free). */
|
|
194
|
+
private HoldPrimary;
|
|
195
|
+
private HoldSecondary;
|
|
185
196
|
private controlFrom?;
|
|
186
197
|
private controlTo?;
|
|
187
198
|
private primarySource;
|
package/dist/core/SkiaEffect.js
CHANGED
|
@@ -45,6 +45,17 @@ const sourceCache = new Map();
|
|
|
45
45
|
* skipped, declared texture children that are not supplied sample transparent.
|
|
46
46
|
*/
|
|
47
47
|
export class SkiaShaderEffect extends SkiaEffect {
|
|
48
|
+
/**
|
|
49
|
+
* The clock origin of every shader's iTime: the page time (ms) of the first shader frame, one for all effects so
|
|
50
|
+
* they stay in step (C# ShaderTimeOriginNanos). iTime is a float32 on the GPU: counted from the page load, a tab open
|
|
51
|
+
* for days would move it in visible steps (0.125 s after 18 days).
|
|
52
|
+
*/
|
|
53
|
+
static ShaderTimeOrigin;
|
|
54
|
+
/** Seconds since the first shader frame for a page time in ms, taken in double before the GPU's float (C# GetShaderTime). */
|
|
55
|
+
static GetShaderTime(nowMs) {
|
|
56
|
+
SkiaShaderEffect.ShaderTimeOrigin ??= nowMs;
|
|
57
|
+
return (nowMs - SkiaShaderEffect.ShaderTimeOrigin) / 1000;
|
|
58
|
+
}
|
|
48
59
|
/** Url of the .sksl file (fetched once, compiled once per text). */
|
|
49
60
|
get ShaderSource() { return this.shaderSource; }
|
|
50
61
|
set ShaderSource(v) { if (this.shaderSource !== v) {
|
|
@@ -74,7 +85,7 @@ export class SkiaShaderEffect extends SkiaEffect {
|
|
|
74
85
|
MipmapMode = "None";
|
|
75
86
|
/** Tile mode of the input textures. */
|
|
76
87
|
TileMode = "Clamp";
|
|
77
|
-
/** Set every Render
|
|
88
|
+
/** Set every Render: seconds since the first shader frame (GetShaderTime); can be driven manually. */
|
|
78
89
|
TimeSeconds = 0;
|
|
79
90
|
/** Shadertoy iMouse.xy, pixels relative to the control. */
|
|
80
91
|
MouseCurrent = { X: 0, Y: 0 };
|
|
@@ -380,7 +391,7 @@ export class SkiaShaderEffect extends SkiaEffect {
|
|
|
380
391
|
}
|
|
381
392
|
/** IPostRendererEffect: draws the shader over ctx.Destination (C# Render). */
|
|
382
393
|
Render(ctx) {
|
|
383
|
-
this.TimeSeconds = performance.now()
|
|
394
|
+
this.TimeSeconds = SkiaShaderEffect.GetShaderTime(performance.now());
|
|
384
395
|
const texture = this.GetPrimaryTexture(ctx, ctx.Destination);
|
|
385
396
|
const built = this.CreateShader(ctx, texture);
|
|
386
397
|
if (!built)
|
|
@@ -423,15 +434,18 @@ export class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
|
|
|
423
434
|
get PrimarySource() { return this.primarySource; }
|
|
424
435
|
set PrimarySource(v) { if (this.primarySource !== v) {
|
|
425
436
|
this.primarySource = v;
|
|
426
|
-
this.
|
|
427
|
-
this.LoadTexture(v, (i) => { this.
|
|
437
|
+
this.HoldPrimary(undefined);
|
|
438
|
+
this.LoadTexture(v, (i) => { this.HoldPrimary(i); this.Update(); });
|
|
428
439
|
} }
|
|
429
440
|
get SecondarySource() { return this.secondarySource; }
|
|
430
441
|
set SecondarySource(v) { if (this.secondarySource !== v) {
|
|
431
442
|
this.secondarySource = v;
|
|
432
|
-
this.
|
|
433
|
-
this.LoadTexture(v, (i) => { this.
|
|
443
|
+
this.HoldSecondary(undefined);
|
|
444
|
+
this.LoadTexture(v, (i) => { this.HoldSecondary(i); this.secondary?.delete(); this.secondary = undefined; this.Update(); });
|
|
434
445
|
} }
|
|
446
|
+
/** The textures it draws are held while it draws them (SkiaImageManager.Hold / Free). */
|
|
447
|
+
HoldPrimary(i) { const old = this.primaryImage; this.primaryImage = i; SkiaImageManager.Instance.Hold(i); SkiaImageManager.Instance.Free(old); }
|
|
448
|
+
HoldSecondary(i) { const old = this.secondaryImage; this.secondaryImage = i; SkiaImageManager.Instance.Hold(i); SkiaImageManager.Instance.Free(old); }
|
|
435
449
|
controlFrom;
|
|
436
450
|
controlTo;
|
|
437
451
|
primarySource = "";
|
|
@@ -444,8 +458,18 @@ export class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
|
|
|
444
458
|
LoadTexture(url, done) {
|
|
445
459
|
if (!url)
|
|
446
460
|
return;
|
|
447
|
-
SkiaImageManager.Instance.
|
|
448
|
-
|
|
461
|
+
SkiaImageManager.Instance.LoadImageManagedAsync(url).then((i) => {
|
|
462
|
+
if (!i) {
|
|
463
|
+
this.SendError(`DrawnUi: cannot load image '${url}'`);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (url !== this.primarySource && url !== this.secondarySource) {
|
|
467
|
+
SkiaImageManager.Instance.Hold(i);
|
|
468
|
+
SkiaImageManager.Instance.Free(i);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
done(i);
|
|
472
|
+
});
|
|
449
473
|
}
|
|
450
474
|
/** C# Resize*LoadedBitmap: the file texture spans the parent box. */
|
|
451
475
|
Resized(ctx, source, slot) {
|
|
@@ -520,6 +544,9 @@ export class ShaderDoubleTexturesEffect extends SkiaShaderEffect {
|
|
|
520
544
|
this.resizedSecondary = undefined;
|
|
521
545
|
this.controlFrom = undefined;
|
|
522
546
|
this.controlTo = undefined;
|
|
547
|
+
this.primarySource = this.secondarySource = "";
|
|
548
|
+
this.HoldPrimary(undefined);
|
|
549
|
+
this.HoldSecondary(undefined);
|
|
523
550
|
super.OnDisposing();
|
|
524
551
|
}
|
|
525
552
|
}
|