drawnui-react 0.1.0-preview.35 → 0.1.0-preview.37
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/SKIPPED.md +3 -0
- package/dist/controls/SkiaButton.js +2 -2
- package/dist/controls/SkiaCarousel.js +31 -3
- package/dist/controls/SkiaCheckbox.js +2 -1
- package/dist/controls/SkiaEditor.d.ts +4 -0
- package/dist/controls/SkiaEditor.js +16 -4
- package/dist/controls/SkiaLabel.d.ts +2 -0
- package/dist/controls/SkiaLabel.js +2 -0
- package/dist/controls/SkiaLayout.d.ts +2 -0
- package/dist/controls/SkiaLayout.js +2 -0
- package/dist/controls/SkiaProgress.js +2 -2
- package/dist/controls/SkiaRadioButton.js +2 -1
- package/dist/controls/SkiaShaderCarousel.js +5 -0
- package/dist/controls/SkiaSlider.js +2 -2
- package/dist/controls/SkiaSwitch.js +4 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +30 -0
- package/dist/core/Accessibility.js +162 -3
- package/dist/core/Canvas.d.ts +76 -3
- package/dist/core/Canvas.js +239 -8
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/Hover.d.ts +4 -0
- package/dist/core/Hover.js +6 -0
- package/dist/core/KeyboardManager.d.ts +7 -0
- package/dist/core/KeyboardManager.js +35 -4
- package/dist/core/PopupWindows.d.ts +92 -0
- package/dist/core/PopupWindows.js +203 -0
- package/dist/core/SkiaControl.d.ts +30 -0
- package/dist/core/SkiaControl.js +60 -3
- package/dist/core/Super.d.ts +7 -0
- package/dist/core/Super.js +7 -0
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/react/index.d.ts +16 -1
- package/dist/react/index.js +51 -11
- package/dist/react/reconciler.d.ts +2 -0
- package/dist/react/reconciler.js +5 -0
- package/package.json +3 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { SKPoint } from "./Gestures";
|
|
2
|
+
import { SKRect } from "./Types";
|
|
3
|
+
import { KeyboardManager } from "./KeyboardManager";
|
|
4
|
+
import { Aria } from "./Accessibility";
|
|
5
|
+
/** Where a popup window opens from, in canvas points, or a control (C# PopupAnchor, Rust PopupAnchor). */
|
|
6
|
+
export class PopupAnchor {
|
|
7
|
+
Rect;
|
|
8
|
+
IsPoint;
|
|
9
|
+
Control;
|
|
10
|
+
constructor(
|
|
11
|
+
/** The point or the rect, in canvas points (empty for a control). */
|
|
12
|
+
Rect,
|
|
13
|
+
/** A point: the popup's top-left corner is there; where the canvas ends it opens to the left of the point, or above it. */
|
|
14
|
+
IsPoint,
|
|
15
|
+
/** A control: the popup opens below the rect it is drawn at now, as for a rect. */
|
|
16
|
+
Control) {
|
|
17
|
+
this.Rect = Rect;
|
|
18
|
+
this.IsPoint = IsPoint;
|
|
19
|
+
this.Control = Control;
|
|
20
|
+
}
|
|
21
|
+
/** A point (where a right click was), in canvas points. */
|
|
22
|
+
static AtPoint(point) { return new PopupAnchor(new SKRect(point.X, point.Y, point.X, point.Y), true); }
|
|
23
|
+
/** A rect (the button a dropdown belongs to), in canvas points: below it, left edges together; where the canvas ends, above it or right edges together. */
|
|
24
|
+
static AtRect(rect) { return new PopupAnchor(rect, false); }
|
|
25
|
+
/** A control: as a rect, with the rect it is drawn at now (moved, scaled, scrolled). */
|
|
26
|
+
static AtControl(control) { return new PopupAnchor(SKRect.Empty, false, control); }
|
|
27
|
+
/** A point, a rect or a control as an anchor. */
|
|
28
|
+
static From(anchor) {
|
|
29
|
+
if (anchor instanceof PopupAnchor)
|
|
30
|
+
return anchor;
|
|
31
|
+
if (typeof anchor.Measure === "function")
|
|
32
|
+
return PopupAnchor.AtControl(anchor);
|
|
33
|
+
if ("Right" in anchor && "Bottom" in anchor) {
|
|
34
|
+
const r = anchor;
|
|
35
|
+
return PopupAnchor.AtRect(new SKRect(r.Left, r.Top, r.Right, r.Bottom));
|
|
36
|
+
}
|
|
37
|
+
const p = anchor;
|
|
38
|
+
return PopupAnchor.AtPoint(new SKPoint(p.X, p.Y));
|
|
39
|
+
}
|
|
40
|
+
/** The anchor in canvas pixels. */
|
|
41
|
+
Pixels(scale) {
|
|
42
|
+
if (this.Control) {
|
|
43
|
+
const r = this.Control.GetAccessibilityPixelRect(); // on screen now: through caches and scroll offsets
|
|
44
|
+
return r.Width > 0 || r.Height > 0 ? r : this.Control.DrawingRect;
|
|
45
|
+
}
|
|
46
|
+
const r = this.Rect;
|
|
47
|
+
return new SKRect(r.Left * scale, r.Top * scale, r.Right * scale, r.Bottom * scale);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The popup windows of one canvas (C# PopupLayer): drawn over everything, given input first, closed by a press outside
|
|
52
|
+
* (the rest of that press goes nowhere, as with native menus).
|
|
53
|
+
*/
|
|
54
|
+
export class PopupLayer {
|
|
55
|
+
canvas;
|
|
56
|
+
popups = [];
|
|
57
|
+
nextId = 0;
|
|
58
|
+
/** A press outside closed the popups: the rest of that press goes nowhere. */
|
|
59
|
+
SwallowPress = false;
|
|
60
|
+
constructor(canvas) {
|
|
61
|
+
this.canvas = canvas;
|
|
62
|
+
}
|
|
63
|
+
get HasAny() { return this.popups.length > 0; }
|
|
64
|
+
get HasInteractive() { return this.popups.some((p) => !p.Options.Passive); }
|
|
65
|
+
/** The content of the top popup window that takes input. */
|
|
66
|
+
get TopInteractive() { for (let i = this.popups.length - 1; i >= 0; i--)
|
|
67
|
+
if (!this.popups[i].Options.Passive)
|
|
68
|
+
return this.popups[i].Root; return undefined; }
|
|
69
|
+
IsOpen(id) { return this.popups.some((p) => p.Id === id); }
|
|
70
|
+
Open(root, anchor, options, superview) {
|
|
71
|
+
root.HorizontalOptions = "Start";
|
|
72
|
+
root.VerticalOptions = "Start";
|
|
73
|
+
if (options.Size) {
|
|
74
|
+
root.WidthRequest = options.Size.Width;
|
|
75
|
+
root.HeightRequest = options.Size.Height;
|
|
76
|
+
}
|
|
77
|
+
if (options.Passive) {
|
|
78
|
+
root.InputTransparent = true;
|
|
79
|
+
root.AccessibilityRole ??= Aria.RolePresentation;
|
|
80
|
+
}
|
|
81
|
+
root.Parent = undefined;
|
|
82
|
+
root._superview = superview;
|
|
83
|
+
const a11y = this.canvas.AccessibilityManager;
|
|
84
|
+
const popup = { Id: ++this.nextId, Root: root, Anchor: anchor, Options: options, Rect: SKRect.Empty, LeftAt: 0 };
|
|
85
|
+
// opened from the keyboard (Enter on a focused control, a key handler such as Alt+F): it takes the keyboard (6ao) and
|
|
86
|
+
// gives it back when it closes, to the control it opens from, else to where the keyboard was (unless that is inside a
|
|
87
|
+
// popup closing now: Left / Right in a menu bar). A popup opened with the mouse leaves the keyboard alone.
|
|
88
|
+
if (!options.Passive && (a11y.FocusedNode || KeyboardManager.IsDispatchingKeyDown)) {
|
|
89
|
+
const keyboard = a11y.FocusedNode;
|
|
90
|
+
popup.Opener = anchor.Control ?? (keyboard && !this.popups.some((p) => PopupLayer.IsInside(keyboard, p.Root)) ? keyboard : undefined);
|
|
91
|
+
a11y.FocusOpenedPopup(root);
|
|
92
|
+
}
|
|
93
|
+
this.popups.push(popup);
|
|
94
|
+
this.UpdateKeyboardScope();
|
|
95
|
+
return popup.Id;
|
|
96
|
+
}
|
|
97
|
+
Close(id) { const p = this.popups.find((x) => x.Id === id); if (p)
|
|
98
|
+
this.Remove(p); }
|
|
99
|
+
CloseTop() {
|
|
100
|
+
for (let i = this.popups.length - 1; i >= 0; i--)
|
|
101
|
+
if (!this.popups[i].Options.Passive) {
|
|
102
|
+
this.Remove(this.popups[i]);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
CloseAll(passiveToo) {
|
|
108
|
+
for (const p of [...this.popups])
|
|
109
|
+
if (passiveToo || !p.Options.Passive)
|
|
110
|
+
this.Remove(p);
|
|
111
|
+
}
|
|
112
|
+
Remove(popup) {
|
|
113
|
+
const i = this.popups.indexOf(popup);
|
|
114
|
+
if (i < 0)
|
|
115
|
+
return;
|
|
116
|
+
this.popups.splice(i, 1);
|
|
117
|
+
// its nodes leave the accessibility tree with this frame, not when the disposal runs after it
|
|
118
|
+
const a11y = this.canvas.AccessibilityManager;
|
|
119
|
+
const focused = a11y.FocusedNode;
|
|
120
|
+
// the keyboard was in it (or nowhere): it goes back to the control the popup opened from, as native menus do
|
|
121
|
+
if (popup.Opener && (!focused || PopupLayer.IsInside(focused, popup.Root)))
|
|
122
|
+
a11y.RequestKeyboardFocus(popup.Opener);
|
|
123
|
+
this.UpdateKeyboardScope();
|
|
124
|
+
a11y.UnregisterSubtree(popup.Root);
|
|
125
|
+
a11y.ForceRebuildOnNextFrame();
|
|
126
|
+
this.canvas.DisposeObject(popup.Root);
|
|
127
|
+
this.canvas.Update();
|
|
128
|
+
this.canvas.RaisePopupWindowClosed(popup.Id);
|
|
129
|
+
}
|
|
130
|
+
static IsInside(control, root) {
|
|
131
|
+
for (let c = control; c; c = c.Parent)
|
|
132
|
+
if (c === root)
|
|
133
|
+
return true;
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
/** Tab stays inside the top popup window that takes input (a menu, a dropdown) while it is open. */
|
|
137
|
+
UpdateKeyboardScope() {
|
|
138
|
+
let top;
|
|
139
|
+
for (let i = this.popups.length - 1; i >= 0 && !top; i--)
|
|
140
|
+
if (!this.popups[i].Options.Passive)
|
|
141
|
+
top = this.popups[i].Root;
|
|
142
|
+
this.canvas.AccessibilityManager.KeyboardScope = top;
|
|
143
|
+
}
|
|
144
|
+
/** The top popup window taking input whose content is under the point (canvas pixels). */
|
|
145
|
+
At(x, y) {
|
|
146
|
+
for (let i = this.popups.length - 1; i >= 0; i--) {
|
|
147
|
+
const p = this.popups[i];
|
|
148
|
+
if (!p.Options.Passive && p.Root.IsVisible && p.Root.HitIsInside(x, y))
|
|
149
|
+
return p.Root;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
/** The pointer is at (x, y) (undefined: off the canvas): popups closing on pointer leave close after 300 ms outside. */
|
|
154
|
+
PointerAt(x, y) {
|
|
155
|
+
const now = performance.now();
|
|
156
|
+
for (const p of [...this.popups]) {
|
|
157
|
+
if (!p.Options.CloseOnPointerLeave)
|
|
158
|
+
continue;
|
|
159
|
+
const inside = x !== undefined && y !== undefined && p.Root.HitIsInside(x, y);
|
|
160
|
+
if (inside) {
|
|
161
|
+
p.LeftAt = 0;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!p.LeftAt) {
|
|
165
|
+
p.LeftAt = now;
|
|
166
|
+
window.setTimeout(() => { if (p.LeftAt && performance.now() - p.LeftAt >= 300)
|
|
167
|
+
this.Remove(p); }, 310);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Where a popup of `w` x `h` goes for `anchor` (pixels) inside `bounds`: at the anchor's corner, flipped to its other side
|
|
173
|
+
* where it does not fit, then kept inside (C# PopupLayer.Place, Rust place_popup).
|
|
174
|
+
*/
|
|
175
|
+
static Place(anchor, point, w, h, bounds) {
|
|
176
|
+
w = Math.max(0, Math.min(w, bounds.Width));
|
|
177
|
+
h = Math.max(0, Math.min(h, bounds.Height));
|
|
178
|
+
let left = anchor.Left;
|
|
179
|
+
if (left + w > bounds.Right)
|
|
180
|
+
left = point ? anchor.Left - w : anchor.Right - w;
|
|
181
|
+
let top = anchor.Bottom;
|
|
182
|
+
if (top + h > bounds.Bottom)
|
|
183
|
+
top = anchor.Top - h;
|
|
184
|
+
left = Math.round(Math.min(Math.max(left, bounds.Left), bounds.Right - w));
|
|
185
|
+
top = Math.round(Math.min(Math.max(top, bounds.Top), bounds.Bottom - h));
|
|
186
|
+
return new SKRect(left, top, left + Math.round(w), top + Math.round(h));
|
|
187
|
+
}
|
|
188
|
+
/** Measures, places and draws every popup over the content, inside `bounds` (canvas pixels). */
|
|
189
|
+
Draw(ctx, bounds) {
|
|
190
|
+
const scale = ctx.Scale;
|
|
191
|
+
for (const p of this.popups) {
|
|
192
|
+
const root = p.Root;
|
|
193
|
+
const size = root.Measure(bounds.Width, bounds.Height, scale).Pixels;
|
|
194
|
+
if (size.Width <= 0 || size.Height <= 0)
|
|
195
|
+
continue;
|
|
196
|
+
p.Rect = PopupLayer.Place(p.Anchor.Pixels(scale), p.Anchor.IsPoint, size.Width, size.Height, bounds);
|
|
197
|
+
root.Arrange(p.Rect, root.WidthRequest, root.HeightRequest, scale);
|
|
198
|
+
root.Render({ Context: ctx.Context, Destination: p.Rect, Scale: scale });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
Dispose() { for (const p of this.popups.splice(0))
|
|
202
|
+
p.Root.Dispose(); }
|
|
203
|
+
}
|
|
@@ -218,6 +218,15 @@ export declare class SkiaControl {
|
|
|
218
218
|
/** Consume every gesture that lands on this control so nothing below (z-order) receives it. */
|
|
219
219
|
BlockGesturesBelow: boolean;
|
|
220
220
|
LockChildrenGestures: LockTouch;
|
|
221
|
+
/**
|
|
222
|
+
* A tap this control takes moves the canvas focus to it, and whatever had it (an editor) lets it go. Default false: a
|
|
223
|
+
* plain control declines the focus, so tapping it (a Send button) leaves the current focus alone.
|
|
224
|
+
*/
|
|
225
|
+
CanBeFocused: boolean;
|
|
226
|
+
/** While this control has the canvas focus, taps elsewhere do not move it. */
|
|
227
|
+
LockFocus: boolean;
|
|
228
|
+
/** The canvas gives (true) or takes (false) the focus; returns whether the control takes it. */
|
|
229
|
+
SetFrameworkFocus(_focus: boolean): boolean;
|
|
221
230
|
private receivesHover?;
|
|
222
231
|
/**
|
|
223
232
|
* Whether this control takes mouse hover: the canvas sets IsHovered while the mouse is over it. Opt-in: false by
|
|
@@ -364,6 +373,16 @@ export declare class SkiaControl {
|
|
|
364
373
|
*/
|
|
365
374
|
get AccessibilityRole(): string | undefined;
|
|
366
375
|
set AccessibilityRole(v: string | undefined);
|
|
376
|
+
private accessibilityModal;
|
|
377
|
+
/**
|
|
378
|
+
* A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
|
|
379
|
+
* screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
|
|
380
|
+
* until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
|
|
381
|
+
* keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
|
|
382
|
+
* of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
|
|
383
|
+
*/
|
|
384
|
+
get AccessibilityModal(): boolean;
|
|
385
|
+
set AccessibilityModal(v: boolean);
|
|
367
386
|
/** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
|
|
368
387
|
static DefaultAccessibilityRole?: string;
|
|
369
388
|
/** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
|
|
@@ -372,6 +391,17 @@ export declare class SkiaControl {
|
|
|
372
391
|
protected DefaultAccessibilityLabel(): string | undefined;
|
|
373
392
|
get AccessibilityHint(): string | undefined;
|
|
374
393
|
set AccessibilityHint(v: string | undefined);
|
|
394
|
+
/** Text of the tooltip shown when the mouse rests on the control (drawnui-cross 6ar); undefined = none. */
|
|
395
|
+
Tooltip?: string;
|
|
396
|
+
/** The control may have tooltip text: the cheap check made on every mouse move. */
|
|
397
|
+
get MayHaveTooltip(): boolean;
|
|
398
|
+
/**
|
|
399
|
+
* The text of this control's tooltip, undefined for none: `Tooltip`, else with `Super.TooltipsFromAccessibility` its
|
|
400
|
+
* `AccessibilityHint`, else its own `AccessibilityLabel` when it shows no text of its own (icon buttons).
|
|
401
|
+
*/
|
|
402
|
+
GetTooltipText(): string | undefined;
|
|
403
|
+
/** The control shows text of its own (a label with text, spans included, inside it). */
|
|
404
|
+
ShowsText(): boolean;
|
|
375
405
|
/**
|
|
376
406
|
* Whether keyboard navigation and assistive technology may focus and use this node: the explicit value, else the class
|
|
377
407
|
* default (true when the control handles Tapped), and in both cases only while a tap could reach the control
|
package/dist/core/SkiaControl.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SkiaStyles } from "./Styles";
|
|
|
3
3
|
import { Colors, SKRect, ScaledSize, Thickness } from "./Types";
|
|
4
4
|
import { 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. */
|
|
@@ -72,7 +72,7 @@ export class CachedObject {
|
|
|
72
72
|
canvas.translate(-this.Bounds.Left, -this.Bounds.Top);
|
|
73
73
|
canvas.drawPicture(this.Picture);
|
|
74
74
|
this.pictureImage = surface.makeImageSnapshot();
|
|
75
|
-
surface.
|
|
75
|
+
surface.dispose(); // a CK.MakeSurface fallback owns its pixels
|
|
76
76
|
return this.pictureImage;
|
|
77
77
|
}
|
|
78
78
|
pictureImage;
|
|
@@ -285,6 +285,16 @@ export class SkiaControl {
|
|
|
285
285
|
/** Consume every gesture that lands on this control so nothing below (z-order) receives it. */
|
|
286
286
|
BlockGesturesBelow = false;
|
|
287
287
|
LockChildrenGestures = "Disabled";
|
|
288
|
+
// ---- focus on a completed tap (drawnui-cross 6ap, C# CanBeFocused / LockFocus / SetFrameworkFocus) ----
|
|
289
|
+
/**
|
|
290
|
+
* A tap this control takes moves the canvas focus to it, and whatever had it (an editor) lets it go. Default false: a
|
|
291
|
+
* plain control declines the focus, so tapping it (a Send button) leaves the current focus alone.
|
|
292
|
+
*/
|
|
293
|
+
CanBeFocused = false;
|
|
294
|
+
/** While this control has the canvas focus, taps elsewhere do not move it. */
|
|
295
|
+
LockFocus = false;
|
|
296
|
+
/** The canvas gives (true) or takes (false) the focus; returns whether the control takes it. */
|
|
297
|
+
SetFrameworkFocus(_focus) { return this.CanBeFocused; }
|
|
288
298
|
// ---- hover (drawnui-cross 6m, C# ReceivesHover / IsHovered / HoverChanged) ----
|
|
289
299
|
receivesHover;
|
|
290
300
|
/**
|
|
@@ -601,11 +611,33 @@ export class SkiaControl {
|
|
|
601
611
|
* ARIA role; setting it exposes the control to assistive technology (use `Aria` constants). Unset = the class
|
|
602
612
|
* default (`SkiaLabel.DefaultAccessibilityRole` etc.), which is itself unset unless the app opts in.
|
|
603
613
|
*/
|
|
604
|
-
get AccessibilityRole() {
|
|
614
|
+
get AccessibilityRole() {
|
|
615
|
+
return this.accessibilityRole ?? (this.accessibilityModal ? Aria.RoleDialog : this.constructor.DefaultAccessibilityRole);
|
|
616
|
+
}
|
|
605
617
|
set AccessibilityRole(v) { if (this.accessibilityRole !== v) {
|
|
606
618
|
this.accessibilityRole = v;
|
|
607
619
|
this.AccessibilityChanged();
|
|
608
620
|
} }
|
|
621
|
+
accessibilityModal = false;
|
|
622
|
+
/**
|
|
623
|
+
* A modal overlay, such as a dialog drawn over the screen (C# AccessibilityModal, drawnui-cross 6av): while it shows,
|
|
624
|
+
* screen readers and Tab reach only its controls (and open popup windows); the content around it leaves accessibility
|
|
625
|
+
* until it goes. With several, the one drawn on top wins. The keyboard moves into it when it appears while the
|
|
626
|
+
* keyboard is in use, and back when it goes. Taps are not affected: blocking them is the backdrop's job. Without a role
|
|
627
|
+
* of its own it reads as a dialog. Default false: nothing changes unless an app sets it.
|
|
628
|
+
*/
|
|
629
|
+
get AccessibilityModal() { return this.accessibilityModal; }
|
|
630
|
+
set AccessibilityModal(v) {
|
|
631
|
+
if (this.accessibilityModal === v)
|
|
632
|
+
return;
|
|
633
|
+
this.accessibilityModal = v;
|
|
634
|
+
if (v)
|
|
635
|
+
AccessibilityModals.add(this);
|
|
636
|
+
else
|
|
637
|
+
AccessibilityModals.delete(this);
|
|
638
|
+
this.AccessibilityChanged();
|
|
639
|
+
this.Superview?.Update();
|
|
640
|
+
}
|
|
609
641
|
/** Per-class default role (React extension): e.g. `SkiaLabel.DefaultAccessibilityRole = Aria.RoleText` reads every label. */
|
|
610
642
|
static DefaultAccessibilityRole;
|
|
611
643
|
/** Spoken label; unset = the control's own text (SkiaLabel.Text, SkiaButton.Text). */
|
|
@@ -620,6 +652,29 @@ export class SkiaControl {
|
|
|
620
652
|
this.accessibilityHint = v;
|
|
621
653
|
this.AccessibilityChanged();
|
|
622
654
|
} }
|
|
655
|
+
/** Text of the tooltip shown when the mouse rests on the control (drawnui-cross 6ar); undefined = none. */
|
|
656
|
+
Tooltip;
|
|
657
|
+
/** The control may have tooltip text: the cheap check made on every mouse move. */
|
|
658
|
+
get MayHaveTooltip() {
|
|
659
|
+
return !!this.Tooltip || (Super.TooltipsFromAccessibility && (this.accessibilityHint != null || this.accessibilityLabel != null));
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* The text of this control's tooltip, undefined for none: `Tooltip`, else with `Super.TooltipsFromAccessibility` its
|
|
663
|
+
* `AccessibilityHint`, else its own `AccessibilityLabel` when it shows no text of its own (icon buttons).
|
|
664
|
+
*/
|
|
665
|
+
GetTooltipText() {
|
|
666
|
+
if (this.Tooltip)
|
|
667
|
+
return this.Tooltip;
|
|
668
|
+
if (!Super.TooltipsFromAccessibility)
|
|
669
|
+
return undefined;
|
|
670
|
+
if (this.accessibilityHint)
|
|
671
|
+
return this.accessibilityHint;
|
|
672
|
+
if (this.accessibilityLabel && !this.ShowsText())
|
|
673
|
+
return this.accessibilityLabel;
|
|
674
|
+
return undefined;
|
|
675
|
+
}
|
|
676
|
+
/** The control shows text of its own (a label with text, spans included, inside it). */
|
|
677
|
+
ShowsText() { return false; }
|
|
623
678
|
/**
|
|
624
679
|
* Whether keyboard navigation and assistive technology may focus and use this node: the explicit value, else the class
|
|
625
680
|
* default (true when the control handles Tapped), and in both cases only while a tap could reach the control
|
|
@@ -1388,6 +1443,8 @@ export class SkiaControl {
|
|
|
1388
1443
|
if (this.IsDisposed)
|
|
1389
1444
|
return;
|
|
1390
1445
|
this.IsDisposed = true;
|
|
1446
|
+
if (this.accessibilityModal)
|
|
1447
|
+
AccessibilityModals.delete(this);
|
|
1391
1448
|
this.OnDisposing();
|
|
1392
1449
|
for (const c of this.ownAnimations.values())
|
|
1393
1450
|
c.abort();
|
package/dist/core/Super.d.ts
CHANGED
|
@@ -46,6 +46,13 @@ export declare class Super {
|
|
|
46
46
|
static readonly Fonts: Map<string, Map<number, Typeface>>;
|
|
47
47
|
/** First registered font, or CanvasKit's built-in one. */
|
|
48
48
|
static DefaultTypeface?: Typeface;
|
|
49
|
+
/**
|
|
50
|
+
* App-wide opt-in (drawnui-cross 6ar): a control without a `Tooltip` shows its `AccessibilityHint` as tooltip, else its
|
|
51
|
+
* `AccessibilityLabel` when it shows no text of its own, so icon buttons get their screen-reader name as tooltip.
|
|
52
|
+
*/
|
|
53
|
+
static TooltipsFromAccessibility: boolean;
|
|
54
|
+
/** Look and timing of the tooltips (a `TooltipStyle`), for every canvas without its own. Read when a tooltip is built. */
|
|
55
|
+
static TooltipStyle?: import("./Tooltips").TooltipStyleLike;
|
|
49
56
|
/** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
|
|
50
57
|
static SkiaDefaultTypeface?: Typeface;
|
|
51
58
|
private static readonly fontCache;
|
package/dist/core/Super.js
CHANGED
|
@@ -116,6 +116,13 @@ export class Super {
|
|
|
116
116
|
static Fonts = new Map();
|
|
117
117
|
/** First registered font, or CanvasKit's built-in one. */
|
|
118
118
|
static DefaultTypeface;
|
|
119
|
+
/**
|
|
120
|
+
* App-wide opt-in (drawnui-cross 6ar): a control without a `Tooltip` shows its `AccessibilityHint` as tooltip, else its
|
|
121
|
+
* `AccessibilityLabel` when it shows no text of its own, so icon buttons get their screen-reader name as tooltip.
|
|
122
|
+
*/
|
|
123
|
+
static TooltipsFromAccessibility = false;
|
|
124
|
+
/** Look and timing of the tooltips (a `TooltipStyle`), for every canvas without its own. Read when a tooltip is built. */
|
|
125
|
+
static TooltipStyle;
|
|
119
126
|
/** CanvasKit's built-in face: what an empty FontFamily resolves to, like C# SKTypeface.CreateDefault(). */
|
|
120
127
|
static SkiaDefaultTypeface;
|
|
121
128
|
static fontCache = new Map();
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { DrawingContext, SkiaControl } from "./SkiaControl";
|
|
2
|
+
import { SKRect } from "./Types";
|
|
3
|
+
/** What the tooltip controller reads from a style (the TooltipStyle class in the controls implements it). */
|
|
4
|
+
export interface TooltipStyleLike {
|
|
5
|
+
MaxWidth: number;
|
|
6
|
+
ShowDelayMs: number;
|
|
7
|
+
FollowWindowMs: number;
|
|
8
|
+
AtCursor: boolean;
|
|
9
|
+
OffsetX: number;
|
|
10
|
+
OffsetY: number;
|
|
11
|
+
CreateTooltip?: (text: string) => SkiaControl;
|
|
12
|
+
CreateDefault(text: string): SkiaControl;
|
|
13
|
+
}
|
|
14
|
+
/** The canvas side the controller needs. */
|
|
15
|
+
interface TooltipHostCanvas {
|
|
16
|
+
readonly RenderingScale: number;
|
|
17
|
+
Update(): void;
|
|
18
|
+
DisposeObject(o: {
|
|
19
|
+
Dispose(): void;
|
|
20
|
+
}): void;
|
|
21
|
+
readonly TooltipStyleUsed: TooltipStyleLike;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
|
|
25
|
+
* with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
|
|
26
|
+
* It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
|
|
27
|
+
* press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
|
|
28
|
+
* no input and no accessibility node.
|
|
29
|
+
*/
|
|
30
|
+
export declare class TooltipController {
|
|
31
|
+
private readonly canvas;
|
|
32
|
+
private owner?;
|
|
33
|
+
private text?;
|
|
34
|
+
private suppressed?;
|
|
35
|
+
private shownText?;
|
|
36
|
+
private anchor;
|
|
37
|
+
private pointer;
|
|
38
|
+
private cursor;
|
|
39
|
+
private closedAt;
|
|
40
|
+
private timer;
|
|
41
|
+
private keysHooked;
|
|
42
|
+
private view?;
|
|
43
|
+
private viewText?;
|
|
44
|
+
private viewRect;
|
|
45
|
+
private viewScale;
|
|
46
|
+
constructor(canvas: TooltipHostCanvas);
|
|
47
|
+
/** The text of the tooltip shown now, undefined when none is shown. */
|
|
48
|
+
get ShownText(): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
|
|
51
|
+
* The innermost control with tooltip text wins.
|
|
52
|
+
*/
|
|
53
|
+
OnPointerMove(path: readonly SkiaControl[], x: number, y: number): void;
|
|
54
|
+
private Show;
|
|
55
|
+
private CancelTimer;
|
|
56
|
+
/** Closes the tooltip and cancels a pending one. */
|
|
57
|
+
private Hide;
|
|
58
|
+
/** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
|
|
59
|
+
CloseOnInput(): void;
|
|
60
|
+
/** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
|
|
61
|
+
/** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
|
|
62
|
+
ForgetGone(gone: (c: SkiaControl | undefined) => boolean): void;
|
|
63
|
+
Reset(): void;
|
|
64
|
+
private readonly onKey;
|
|
65
|
+
private readonly onChar;
|
|
66
|
+
private HookKeys;
|
|
67
|
+
/** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
|
|
68
|
+
Draw(ctx: DrawingContext, bounds: SKRect): void;
|
|
69
|
+
Dispose(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { SKPoint } from "./Gestures";
|
|
2
|
+
import { SKRect } from "./Types";
|
|
3
|
+
import { KeyboardManager } from "./KeyboardManager";
|
|
4
|
+
/** Where a control is on the canvas now, in pixels: through caches, scroll offsets and transforms (C# OnScreenRect). */
|
|
5
|
+
function OnScreenRect(control) {
|
|
6
|
+
const r = control.GetAccessibilityPixelRect();
|
|
7
|
+
return r.Width > 0 || r.Height > 0 ? r : control.DrawingRect;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The tooltip of one canvas (drawnui-cross 6ar, C# DrawnView.Tooltip): after the mouse rests on the innermost control
|
|
11
|
+
* with tooltip text, its tooltip shows, attached to it; the next one shows at once while one is shown or just closed.
|
|
12
|
+
* It closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch, and after a
|
|
13
|
+
* press stays closed until the mouse reaches another control. Separate from hover. Drawn last, inside the canvas, with
|
|
14
|
+
* no input and no accessibility node.
|
|
15
|
+
*/
|
|
16
|
+
export class TooltipController {
|
|
17
|
+
canvas;
|
|
18
|
+
owner;
|
|
19
|
+
text;
|
|
20
|
+
suppressed;
|
|
21
|
+
shownText;
|
|
22
|
+
anchor = SKRect.Empty;
|
|
23
|
+
pointer = SKPoint.Empty;
|
|
24
|
+
cursor = SKPoint.Empty;
|
|
25
|
+
closedAt = 0;
|
|
26
|
+
timer = 0;
|
|
27
|
+
keysHooked = false;
|
|
28
|
+
view;
|
|
29
|
+
viewText;
|
|
30
|
+
viewRect = SKRect.Empty;
|
|
31
|
+
viewScale = 0;
|
|
32
|
+
constructor(canvas) {
|
|
33
|
+
this.canvas = canvas;
|
|
34
|
+
}
|
|
35
|
+
/** The text of the tooltip shown now, undefined when none is shown. */
|
|
36
|
+
get ShownText() { return this.shownText; }
|
|
37
|
+
/**
|
|
38
|
+
* The mouse moved, nothing pressed: `path` is the hover hit path (root first), (x, y) the pointer in canvas pixels.
|
|
39
|
+
* The innermost control with tooltip text wins.
|
|
40
|
+
*/
|
|
41
|
+
OnPointerMove(path, x, y) {
|
|
42
|
+
let owner, text;
|
|
43
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
44
|
+
const c = path[i];
|
|
45
|
+
if (!c.MayHaveTooltip || c.IsDisposed)
|
|
46
|
+
continue;
|
|
47
|
+
text = c.GetTooltipText();
|
|
48
|
+
if (text) {
|
|
49
|
+
owner = c;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// a press closed it: it stays closed until the mouse leaves that control
|
|
54
|
+
if (this.suppressed) {
|
|
55
|
+
if (owner === this.suppressed)
|
|
56
|
+
return;
|
|
57
|
+
this.suppressed = undefined;
|
|
58
|
+
}
|
|
59
|
+
if (!owner || !text) {
|
|
60
|
+
this.owner = undefined;
|
|
61
|
+
this.text = undefined;
|
|
62
|
+
this.Hide();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.pointer = new SKPoint(x, y);
|
|
66
|
+
if (owner === this.owner && text === this.text)
|
|
67
|
+
return; // still on the same control: the tooltip stays where it opened
|
|
68
|
+
this.owner = owner;
|
|
69
|
+
this.text = text;
|
|
70
|
+
this.HookKeys(true);
|
|
71
|
+
const style = this.canvas.TooltipStyleUsed;
|
|
72
|
+
this.CancelTimer();
|
|
73
|
+
if (this.shownText !== undefined || (this.closedAt !== 0 && performance.now() - this.closedAt < style.FollowWindowMs)) {
|
|
74
|
+
// moving from one tooltip to the next: no new wait
|
|
75
|
+
this.Show();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.timer = window.setTimeout(() => { this.timer = 0; if (this.owner)
|
|
79
|
+
this.Show(); }, Math.max(0, style.ShowDelayMs));
|
|
80
|
+
}
|
|
81
|
+
Show() {
|
|
82
|
+
if (!this.owner || !this.text)
|
|
83
|
+
return;
|
|
84
|
+
this.shownText = this.text;
|
|
85
|
+
this.anchor = OnScreenRect(this.owner);
|
|
86
|
+
this.cursor = this.pointer;
|
|
87
|
+
this.canvas.Update();
|
|
88
|
+
}
|
|
89
|
+
CancelTimer() { if (this.timer) {
|
|
90
|
+
clearTimeout(this.timer);
|
|
91
|
+
this.timer = 0;
|
|
92
|
+
} }
|
|
93
|
+
/** Closes the tooltip and cancels a pending one. */
|
|
94
|
+
Hide() {
|
|
95
|
+
this.CancelTimer();
|
|
96
|
+
if (!this.owner)
|
|
97
|
+
this.HookKeys(false);
|
|
98
|
+
if (this.shownText === undefined)
|
|
99
|
+
return;
|
|
100
|
+
this.shownText = undefined;
|
|
101
|
+
this.closedAt = performance.now();
|
|
102
|
+
this.canvas.Update();
|
|
103
|
+
}
|
|
104
|
+
/** Any input that is not a plain mouse move (press, wheel, key, window blur): closed until the mouse reaches another control. */
|
|
105
|
+
CloseOnInput() {
|
|
106
|
+
if (!this.owner && this.shownText === undefined)
|
|
107
|
+
return;
|
|
108
|
+
this.suppressed = this.owner;
|
|
109
|
+
this.owner = undefined;
|
|
110
|
+
this.text = undefined;
|
|
111
|
+
this.Hide();
|
|
112
|
+
this.HookKeys(false);
|
|
113
|
+
}
|
|
114
|
+
/** The pointer left the canvas, content moves under it or a popup opened: closed, its control forgotten. */
|
|
115
|
+
/** A control that left the canvas is forgotten: its tooltip closes, a press on it suppresses nothing any more. */
|
|
116
|
+
ForgetGone(gone) {
|
|
117
|
+
if (gone(this.suppressed))
|
|
118
|
+
this.suppressed = undefined;
|
|
119
|
+
if (gone(this.owner)) {
|
|
120
|
+
this.owner = undefined;
|
|
121
|
+
this.text = undefined;
|
|
122
|
+
this.Hide();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Reset() {
|
|
126
|
+
this.owner = undefined;
|
|
127
|
+
this.text = undefined;
|
|
128
|
+
this.suppressed = undefined;
|
|
129
|
+
this.Hide();
|
|
130
|
+
this.HookKeys(false);
|
|
131
|
+
}
|
|
132
|
+
onKey = () => this.CloseOnInput();
|
|
133
|
+
onChar = () => { };
|
|
134
|
+
HookKeys(on) {
|
|
135
|
+
if (on === this.keysHooked)
|
|
136
|
+
return;
|
|
137
|
+
this.keysHooked = on;
|
|
138
|
+
if (on)
|
|
139
|
+
KeyboardManager.Subscribe(this.onKey, this.onChar);
|
|
140
|
+
else
|
|
141
|
+
KeyboardManager.Unsubscribe(this.onKey, this.onChar);
|
|
142
|
+
}
|
|
143
|
+
/** Draws the tooltip over everything, inside `bounds` (canvas pixels). */
|
|
144
|
+
Draw(ctx, bounds) {
|
|
145
|
+
const text = this.shownText;
|
|
146
|
+
if (text === undefined) {
|
|
147
|
+
if (this.view) {
|
|
148
|
+
this.canvas.DisposeObject(this.view);
|
|
149
|
+
this.view = undefined;
|
|
150
|
+
this.viewText = undefined;
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const scale = ctx.Scale;
|
|
155
|
+
if (!this.view || this.viewText !== text || this.viewScale !== scale) {
|
|
156
|
+
if (this.view)
|
|
157
|
+
this.canvas.DisposeObject(this.view);
|
|
158
|
+
const style = this.canvas.TooltipStyleUsed;
|
|
159
|
+
const view = style.CreateTooltip?.(text) ?? style.CreateDefault(text);
|
|
160
|
+
view._superview = this.canvas;
|
|
161
|
+
view.Parent = undefined;
|
|
162
|
+
view.InputTransparent = true;
|
|
163
|
+
this.view = view;
|
|
164
|
+
this.viewText = text;
|
|
165
|
+
this.viewScale = scale;
|
|
166
|
+
// a finite width lets long text wrap: MaxWidth, never wider than the canvas
|
|
167
|
+
const margin = view.Margin;
|
|
168
|
+
const maxWidth = Math.min(bounds.Width, (style.MaxWidth + margin.HorizontalThickness) * scale);
|
|
169
|
+
const measured = view.Measure(maxWidth, Infinity, scale).Pixels;
|
|
170
|
+
const width = measured.Width, height = measured.Height;
|
|
171
|
+
// attached to its control (centered above it, below where there is no room) or at the cursor (below right of the
|
|
172
|
+
// pointer, above where there is no room); the offsets shift it, the vertical one mirrored on the flipped side
|
|
173
|
+
const boxWidth = width - margin.HorizontalThickness * scale, boxHeight = height - margin.VerticalThickness * scale;
|
|
174
|
+
const gap = 6 * scale, offsetX = style.OffsetX * scale, offsetY = style.OffsetY * scale;
|
|
175
|
+
const anchor = this.anchor, cursor = this.cursor;
|
|
176
|
+
let boxLeft, boxTop, flippedTop;
|
|
177
|
+
if (style.AtCursor) {
|
|
178
|
+
boxLeft = cursor.X + 4 * scale + offsetX;
|
|
179
|
+
boxTop = cursor.Y + 20 * scale + offsetY; // clear of the pointer's arrow
|
|
180
|
+
flippedTop = cursor.Y - gap - boxHeight - offsetY;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
boxLeft = (anchor.Left + anchor.Right) / 2 - boxWidth / 2 + offsetX;
|
|
184
|
+
boxTop = anchor.Top - gap - boxHeight + offsetY;
|
|
185
|
+
flippedTop = anchor.Bottom + gap - offsetY;
|
|
186
|
+
}
|
|
187
|
+
if (style.AtCursor ? boxTop + boxHeight > bounds.Bottom : boxTop < bounds.Top)
|
|
188
|
+
boxTop = flippedTop;
|
|
189
|
+
boxLeft = Math.max(bounds.Left, Math.min(boxLeft, bounds.Right - boxWidth));
|
|
190
|
+
boxTop = Math.max(bounds.Top, Math.min(boxTop, bounds.Bottom - boxHeight));
|
|
191
|
+
const left = boxLeft - margin.Left * scale, top = boxTop - margin.Top * scale;
|
|
192
|
+
this.viewRect = new SKRect(left, top, left + width, top + height);
|
|
193
|
+
view.Arrange(this.viewRect, view.WidthRequest, view.HeightRequest, scale);
|
|
194
|
+
}
|
|
195
|
+
this.view.Render({ Context: ctx.Context, Destination: this.viewRect, Scale: scale });
|
|
196
|
+
}
|
|
197
|
+
Dispose() {
|
|
198
|
+
this.CancelTimer();
|
|
199
|
+
this.HookKeys(false);
|
|
200
|
+
if (this.view) {
|
|
201
|
+
this.view.Dispose();
|
|
202
|
+
this.view = undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|