drawnui-react 0.1.0-preview.35 → 0.1.0-preview.36

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.
Files changed (40) hide show
  1. package/SKIPPED.md +2 -0
  2. package/dist/controls/SkiaButton.js +2 -2
  3. package/dist/controls/SkiaCheckbox.js +2 -1
  4. package/dist/controls/SkiaEditor.d.ts +4 -0
  5. package/dist/controls/SkiaEditor.js +16 -4
  6. package/dist/controls/SkiaLabel.d.ts +2 -0
  7. package/dist/controls/SkiaLabel.js +2 -0
  8. package/dist/controls/SkiaLayout.d.ts +2 -0
  9. package/dist/controls/SkiaLayout.js +2 -0
  10. package/dist/controls/SkiaProgress.js +2 -2
  11. package/dist/controls/SkiaRadioButton.js +2 -1
  12. package/dist/controls/SkiaSlider.js +2 -2
  13. package/dist/controls/SkiaSwitch.js +4 -2
  14. package/dist/controls/TooltipStyle.d.ts +52 -0
  15. package/dist/controls/TooltipStyle.js +88 -0
  16. package/dist/core/Accessibility.d.ts +18 -0
  17. package/dist/core/Accessibility.js +75 -3
  18. package/dist/core/Canvas.d.ts +60 -3
  19. package/dist/core/Canvas.js +185 -5
  20. package/dist/core/ControlStyle.d.ts +2 -0
  21. package/dist/core/ControlStyle.js +2 -0
  22. package/dist/core/Hover.d.ts +4 -0
  23. package/dist/core/Hover.js +6 -0
  24. package/dist/core/KeyboardManager.d.ts +7 -0
  25. package/dist/core/KeyboardManager.js +31 -2
  26. package/dist/core/PopupWindows.d.ts +92 -0
  27. package/dist/core/PopupWindows.js +203 -0
  28. package/dist/core/SkiaControl.d.ts +20 -0
  29. package/dist/core/SkiaControl.js +33 -0
  30. package/dist/core/Super.d.ts +7 -0
  31. package/dist/core/Super.js +7 -0
  32. package/dist/core/Tooltips.d.ts +69 -0
  33. package/dist/core/Tooltips.js +195 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.js +3 -0
  36. package/dist/react/index.d.ts +13 -0
  37. package/dist/react/index.js +32 -0
  38. package/dist/react/reconciler.d.ts +2 -0
  39. package/dist/react/reconciler.js +5 -0
  40. package/package.json +2 -1
package/SKIPPED.md CHANGED
@@ -53,6 +53,8 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
53
53
  | `Gestures` param | ported | Touch: `Lock` applies `touch-action:none`; `Enabled` behaves like MAUI's Enabled inside a native scroll view: `touch-action` is the axes the page (or a scrolling ancestor) can scroll (`pan-y` / `pan-x` / both, `none` when it cannot; inside an iframe the vertical axis always counts, because the embedding page cannot be inspected cross-origin), recomputed on attach, on window / html / body resize and after every touch, so a finger pan along a page axis scrolls the page and the canvas pointer is cancelled (a cancelled pointer never flings a `SkiaScroll`), taps and the other axis stay on the canvas, and a full-page app keeps every touch. `user-select:none` in both. Claimed touches: in `Enabled` a touch or pen Down is processed immediately (queued gestures first) and, when a control used it (same rule as the wheel: marked `Handled`, or a consumer that is not a `BlockGesturesBelow` layer), the touch is claimed and its `touchmove` events are default-prevented until it ends, so the page cannot take that drag mid-gesture (iOS Safari ignores `touch-action` for off-axis drags, w3c/pointerevents#303); unclaimed touches share the page as before. Controls that use a Down: `ConsumeGestures` handlers that set `Consumed`, `SkiaCarousel` (always), `SkiaSlider`, `SkiaEditor`, `SkiaButton` when `OnDown` accepts; `SkiaScroll` and plain `Tapped` controls do not. Mouse wheel: `Enabled` shares it with the page like Blazor's `TouchHandlingStyle.Manual` (the wheel is processed in the DOM handler and the browser default is prevented only when a control used it: a scroll that moved, a `ConsumeGestures` handler that consumed, or any other consumer that is not a `BlockGesturesBelow` layer merely blocking the controls below, so an embedded canvas lets the page scroll over anything that does not scroll, including a shell page, and a scroll at its edge hands the wheel to the page; `TouchActionEventArgs.Handled` is the AppoMobi marker for that use); `Lock` prevents every wheel and also blocks `touchmove` default. Not ported: Blazor's pointer capture policy for `Enabled` (capture only while locked, release when a pan is not consumed); React captures every press. |
54
54
  | Mouse cursor over interactive controls (Blazor `Canvas.razor` `.xaml-a11y-interactive { cursor: pointer }`) | ported (differently) | The overlay here is `pointer-events: none`, so `Canvas.UpdateCursor` hit-tests mouse moves with no active pointer against the accessibility snapshot rects (`CanInteract` = has `Tapped`, buttons, links) and asks each hit control `WantsPointerCursor(x, y)` (default `AccessibilityCanInteract`; `SkiaLabel` also answers for its tappable `TextSpan`s), setting the canvas element's `cursor` only when the answer changes. Touch pointers do nothing. Engine hover (`IsHovered` / `OnHover`, `TouchActionResult.Pointer`) stays skipped, see Gestures. |
55
55
  | `ContextMenu` (right click / long press / Menu key, React extension) | ported (web-only) | `SkiaControl.ContextMenu` / `Canvas.ContextMenu` handlers with `ContextMenuEventArgs` (`Location` points, `Pixels`, `Local` px in the control, `Source`, `Native`); the DOM `contextmenu` event is routed like a tap (`ProcessContextMenu`: visible non-transparent children top-most first through `TransformPointToLocalSpace`, then the control, then the canvas). `true` = handled, browser menu suppressed; nothing handled = browser menu. Not in DrawnUi.Net. |
56
+ | Tooltips (`SkiaControl.Tooltip`, `Super.TooltipsFromAccessibility`, `TooltipStyle`) | ported | drawnui-cross 6ar: shows after `ShowDelayMs` on the innermost control with tooltip text, the next one at once within `FollowWindowMs`; attached to the control (centered 6 pt above, below where there is no room) or `AtCursor`, `OffsetX` / `OffsetY`, anchored on screen now, kept inside the canvas; closes on leave, press, wheel, key, content moving under the pointer and window blur, never on touch; no hover, no accessibility node; `CreateTooltip` for custom content. Drawn in the canvas only (a browser page has no windows past its edge). |
57
+ | Popup windows (`Canvas.OpenPopupWindow` / `ClosePopupWindow` / `ClosePopupWindows` / `IsPopupWindowOpen`, `PopupAnchor`, `PopupWindowOptions`, `PopupWindowClosed`) | ported | drawnui-cross 6at, the DrawnUi.Rust / .NET API (C# names): anchor a point, a rect or a control (below it, flipped where it does not fit, kept inside); drawn over everything, given input and hover first; closes on a press outside (the rest of that press goes nowhere), Escape, the wheel outside, window blur and from code; options `Size`, `CloseOnPointerLeave`, `Passive`; `OnCanvas` / `Cpu` accepted, always on the canvas. React extra: `OpenPopupWindow(canvas, jsx, anchor, options)` renders JSX content and unmounts it on close. |
56
58
  | Keyboard navigation (drawnui-cross 6c) | ported | Through the accessibility overlay, the DrawnUi.Blazor way: Tab / Shift+Tab walk the interactive nodes in reading order, Enter / Space activate (`SkiaAccessibilityManager.Activate`), ArrowLeft / Right / Up / Down, Home / End, PageUp / PageDown go to the focused control first (`OnAccessibilityKey`, `SkiaAccessibilityManager.Key`: `SkiaSlider` steps, `SkiaEditor` keeps them while editing), then to its arrow-key group (`MoveInGroup`). A container with a composite role (`Aria.IsCompositeRole`: list, listbox, grid, toolbar, radiogroup, tablist, menu, menubar) is one Tab stop (roving tabindex, `IsTabStop`, entered on the item focused last); the arrows move by item index (Column: Up / Down, Row: Left / Right, Wrap / Grid / Split: all four, Up / Down by a row), no wrap, items not realized are scrolled in with `ScrollToIndex` and focused once drawn (`OnKeyboardFocusRequested`). `SkiaEditor` is a Tab stop: Tab in takes the caret, Tab / Shift+Tab leave it for the next node (also after a click into it). Focus ring = the overlay element's `:focus-visible` outline; focus scrolls the node into view in every enclosing scroll. Not ported: `FocusedChild` / canvas `KeyboardFocusNode`, Escape leaving the drawn nodes, a canvas-drawn focus ring. |
57
59
  | Canvas draw events | ported | `WillFirstTimeDraw` (once, right before the first frame drawn on a ready surface, with that frame's `{ Canvas, Surface }`), `WasDrawn` (after every frame, no context, like the C# `null`), `WasRendered` (set after the first frame completes, so the first `WasDrawn` still sees `false`, C# order), `CanRender` (surface ready). JSX: `<Canvas WillFirstTimeDraw WasDrawn>`; the engine draws frame 1 in its constructor, so the component hands both callbacks to the constructor's `init`. Not ported: `WillDraw`. |
58
60
  | Rendering stats | partial | `Canvas.FPS` (frames drawn over the last second) and `Canvas.FrameTime` (ms of the last measure + arrange + render, GPU flush excluded) are computed every frame and reachable from React through the `<Canvas>` ref. `SkiaLabelFps` ported (label on top, input-transparent, parent-independent, re-measures itself on draw; its value changes only on frames that running animators request, see PARITY). Not ported: `SkiaLabelFps.ForceRefresh` / `Format` / `MonoForDigits`, `Super.EnableRenderingStats`. |
@@ -3,7 +3,7 @@ import { SKPoint } from "../core/Gestures";
3
3
  import { SkiaLayout } from "./SkiaLayout";
4
4
  import { SkiaLabel } from "./SkiaLabel";
5
5
  import { SkiaShape } from "./SkiaShape";
6
- import { ResolveControlStyle } from "../core/ControlStyle";
6
+ import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
7
7
  /**
8
8
  * Mirrors DrawnUi SkiaButton (default style): a SkiaShape frame tagged "BtnShape" + a centered SkiaLabel
9
9
  * tagged "BtnText". Consumes Down/Up/Tapped inside its rect; releases the pressed state when a pan exceeds
@@ -89,7 +89,7 @@ export class SkiaButton extends SkiaLayout {
89
89
  case "Material": return { bg: "#2196F3", radius: 4, font: 14, weight: 0, minW: 100, minH: 40, shadow: new SkiaShadow({ X: 0, Y: 2, Blur: 4, Opacity: 0.3, Color: Colors.Black }) };
90
90
  case "Material3": return { bg: "#6750A4", radius: 20, font: 14, weight: 0, minW: 100, minH: 40 };
91
91
  case "Windows": return { bg: "#0078D7", radius: 4, font: 15, weight: 500, minW: 100, minH: 32, shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 1, Opacity: 0.2, Color: Colors.Black }) };
92
- default: return { bg: "#DC143C", radius: 8, font: 15, weight: 0, minW: 100, minH: 41 };
92
+ default: return { bg: DefaultAccent, radius: 8, font: 15, weight: 0, minW: 100, minH: 41 };
93
93
  }
94
94
  }
95
95
  MeasureAbsolute(w, h, scale) {
@@ -1,3 +1,4 @@
1
+ import { DefaultAccent } from "../core/ControlStyle";
1
2
  import { Colors, Thickness } from "../core/Types";
2
3
  import { SkiaShape } from "./SkiaShape";
3
4
  import { SkiaSvg } from "./SkiaSvg";
@@ -12,7 +13,7 @@ export class SkiaCheckbox extends SkiaToggle {
12
13
  FrameOn;
13
14
  ViewCheckOn;
14
15
  colorCheckOn;
15
- static DefaultAccent = "#DC143C";
16
+ static DefaultAccent = DefaultAccent;
16
17
  static DefaultOutline = "#8E959D";
17
18
  /** Color of the check mark (inner square for the default look). */
18
19
  get ColorCheckOn() { return this.colorCheckOn ?? (this.UsingControlStyle === "Unset" ? SkiaCheckbox.DefaultAccent : Colors.White); }
@@ -108,6 +108,8 @@ export declare class SkiaEditor extends SkiaShape {
108
108
  get ShouldSubmitOnEnter(): boolean;
109
109
  /** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
110
110
  get CursorPosition(): number;
111
+ /** A position from app code as a whole number: beyond the text (MAX_SAFE_INTEGER, Infinity) is the end, NaN is 0. */
112
+ private static Whole;
111
113
  set CursorPosition(v: number);
112
114
  get SelectionLength(): number;
113
115
  set SelectionLength(v: number);
@@ -153,6 +155,8 @@ export declare class SkiaEditor extends SkiaShape {
153
155
  private LabelPoint;
154
156
  protected Paint(ctx: DrawingContext): void;
155
157
  ProcessGestures(args: SkiaGesturesParameters, apply: GestureEventProcessingInfo): SkiaControl | null;
158
+ /** The canvas gives or takes the focus (a tap elsewhere): an editor always takes it. */
159
+ SetFrameworkFocus(focus: boolean): boolean;
156
160
  /** A text field is a Tab stop by default, like a native text box, with no Tapped handler needed. */
157
161
  protected DefaultAccessibilityCanInteract(): boolean;
158
162
  /** Keyboard navigation reached the field (Tab) or left it: take the caret and the input sink like a native text box, or release them. */
@@ -1,6 +1,6 @@
1
1
  import { SKPoint } from "../core/Gestures";
2
2
  import { Super } from "../core/Super";
3
- import { ResolveControlStyle } from "../core/ControlStyle";
3
+ import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
4
4
  import { KeyboardManager } from "../core/KeyboardManager";
5
5
  import { TextInputProxy } from "../core/TextInputProxy";
6
6
  import { Colors, ScaledSize, SKRect, Thickness } from "../core/Types";
@@ -181,9 +181,11 @@ export class SkiaEditor extends SkiaShape {
181
181
  get ShouldSubmitOnEnter() { return this.IsMultiline && this.ReturnType === "Send"; }
182
182
  /** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
183
183
  get CursorPosition() { return this.cursorPosition; }
184
+ /** A position from app code as a whole number: beyond the text (MAX_SAFE_INTEGER, Infinity) is the end, NaN is 0. */
185
+ static Whole(v) { return Number.isNaN(v) ? 0 : Math.trunc(v); }
184
186
  set CursorPosition(v) {
185
187
  this.cursorPlaced = true;
186
- const p = Math.max(0, Math.min(this.text.length, v | 0));
188
+ const p = Math.max(0, Math.min(this.text.length, SkiaEditor.Whole(v)));
187
189
  if (p === this.cursorPosition)
188
190
  return;
189
191
  this.cursorPosition = p;
@@ -191,7 +193,7 @@ export class SkiaEditor extends SkiaShape {
191
193
  }
192
194
  get SelectionLength() { return this.selectionLength; }
193
195
  set SelectionLength(v) {
194
- const l = Math.max(0, Math.min(this.text.length - this.cursorPosition, v | 0));
196
+ const l = Math.max(0, Math.min(this.text.length - this.cursorPosition, SkiaEditor.Whole(v)));
195
197
  if (l === this.selectionLength)
196
198
  return;
197
199
  this.selectionLength = l;
@@ -248,6 +250,14 @@ export class SkiaEditor extends SkiaShape {
248
250
  this.StopBlink();
249
251
  this.SetFocusNative(false);
250
252
  }
253
+ // the canvas focus follows the editor's own (a press, Tab, code), so a tap elsewhere can end the editing (6ap)
254
+ const canvas = this.Superview;
255
+ if (canvas) {
256
+ if (v)
257
+ canvas.ReportFocus(this, this);
258
+ else if (canvas.FocusedChild === this)
259
+ canvas.ReportFocus(undefined, this);
260
+ }
251
261
  this.FocusChanged?.(this, v);
252
262
  this.NotifyAccessibility();
253
263
  this.InvalidateCache();
@@ -266,7 +276,7 @@ export class SkiaEditor extends SkiaShape {
266
276
  : style === "Material" ? { bg: "#EFEBF4", corner: 4, stroke: Colors.Transparent, strokeW: 0, cursor: "#2196F3" }
267
277
  : style === "Material3" ? { bg: "#E6E0E9", corner: 4, stroke: Colors.Transparent, strokeW: 0, cursor: "#6750A4" }
268
278
  : style === "Windows" ? { bg: "#FFFFFF", corner: 2, stroke: "#8A8A8A", strokeW: 1, cursor: "#0078D4" }
269
- : { bg: "#F2F3F5", corner: 8, stroke: Colors.Transparent, strokeW: 0, cursor: "#DC143C" };
279
+ : { bg: "#F2F3F5", corner: 8, stroke: Colors.Transparent, strokeW: 0, cursor: DefaultAccent };
270
280
  const apply = (key, current, next, set) => {
271
281
  if (!(key in this.styleApplied) || this.styleApplied[key] === current) {
272
282
  set();
@@ -631,6 +641,8 @@ export class SkiaEditor extends SkiaShape {
631
641
  }
632
642
  return this;
633
643
  }
644
+ /** The canvas gives or takes the focus (a tap elsewhere): an editor always takes it. */
645
+ SetFrameworkFocus(focus) { this.IsFocused = focus; return true; }
634
646
  /** A text field is a Tab stop by default, like a native text box, with no Tapped handler needed. */
635
647
  DefaultAccessibilityCanInteract() { return true; }
636
648
  /** Keyboard navigation reached the field (Tab) or left it: take the caret and the input sink like a native text box, or release them. */
@@ -105,6 +105,8 @@ export declare class SkiaLabel extends SkiaControl {
105
105
  set TextTransform(v: TextTransform);
106
106
  get Padding(): Thickness;
107
107
  set Padding(v: ThicknessValue);
108
+ /** A label with text, in Text or in its spans, shows text of its own (no accessibility-label tooltip). */
109
+ ShowsText(): boolean;
108
110
  /** Number of laid-out lines after the last measure. */
109
111
  get LinesCount(): number;
110
112
  AddSubView(control: SkiaControl | TextSpan): void;
@@ -98,6 +98,8 @@ export class SkiaLabel extends SkiaControl {
98
98
  set TextTransform(v) { this.Set("textTransform", v); }
99
99
  get Padding() { return this.padding; }
100
100
  set Padding(v) { this.Set("padding", Thickness.From(v)); }
101
+ /** A label with text, in Text or in its spans, shows text of its own (no accessibility-label tooltip). */
102
+ ShowsText() { return !!this.text || this.Spans.some((s) => !!s.Text); }
101
103
  /** Number of laid-out lines after the last measure. */
102
104
  get LinesCount() { return this.lines.length; }
103
105
  // ---- spans as children (reconciler AddSubView / InsertSubView / RemoveSubView) ----
@@ -129,6 +129,8 @@ export declare class SkiaLayout extends SkiaControl {
129
129
  InsertChild(child: SkiaControl, before?: SkiaControl): void;
130
130
  /** C# OrderViews: the given children, in their order, inside the slots they occupy in the views; nothing else moves. */
131
131
  private OrderChildren;
132
+ /** A child showing text (a caption inside a button) is text of its own: the accessibility label then makes no tooltip. */
133
+ ShowsText(): boolean;
132
134
  /** C# ClearChildren: removes every subview, the control's own parts included. */
133
135
  ClearChildren(): void;
134
136
  private orderedViews?;
@@ -427,6 +427,8 @@ export class SkiaLayout extends SkiaControl {
427
427
  this.InvalidateMeasure();
428
428
  }
429
429
  }
430
+ /** A child showing text (a caption inside a button) is text of its own: the accessibility label then makes no tooltip. */
431
+ ShowsText() { return this.views.some((v) => v.ShowsText()); }
430
432
  /** C# ClearChildren: removes every subview, the control's own parts included. */
431
433
  ClearChildren() {
432
434
  for (const v of [...this.views])
@@ -1,6 +1,6 @@
1
1
  import { SkiaControl } from "../core/SkiaControl";
2
2
  import { Super } from "../core/Super";
3
- import { ResolveControlStyle } from "../core/ControlStyle";
3
+ import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
4
4
  import { ScaledSize } from "../core/Types";
5
5
  /**
6
6
  * Mirrors DrawnUi SkiaProgress (SkiaRangeBase): a horizontal track with a progress trail, per-style track height and
@@ -43,7 +43,7 @@ export class SkiaProgress extends SkiaControl {
43
43
  case "Material": return { track: "#E8EAED", progress: "#2196F3", height: 4, radius: 2 };
44
44
  case "Material3": return { track: "#E6E0E9", progress: "#6750A4", height: 4, radius: 2 };
45
45
  case "Windows": return { track: "#F3F2F1", progress: "#0078D4", height: 6, radius: 3 };
46
- default: return { track: "#D7DBE0", progress: "#DC143C", height: 8, radius: 4 };
46
+ default: return { track: "#D7DBE0", progress: DefaultAccent, height: 8, radius: 4 };
47
47
  }
48
48
  }
49
49
  get Ratio() { return this.max > this.min ? Math.max(0, Math.min(1, (this.value - this.min) / (this.max - this.min))) : 0; }
@@ -1,3 +1,4 @@
1
+ import { DefaultAccent } from "../core/ControlStyle";
1
2
  import { Colors, Thickness } from "../core/Types";
2
3
  import { SkiaLayout } from "./SkiaLayout";
3
4
  import { SkiaLabel } from "./SkiaLabel";
@@ -13,7 +14,7 @@ export class SkiaRadioButton extends SkiaToggle {
13
14
  groupKey;
14
15
  ViewOn;
15
16
  ViewText;
16
- static DefaultAccent = "#DC143C";
17
+ static DefaultAccent = DefaultAccent;
17
18
  static DefaultOutline = "#8E959D";
18
19
  constructor(text = "") {
19
20
  super();
@@ -1,6 +1,6 @@
1
1
  import { SkiaControl } from "../core/SkiaControl";
2
2
  import { Super } from "../core/Super";
3
- import { ResolveControlStyle } from "../core/ControlStyle";
3
+ import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
4
4
  import { Colors, ScaledSize, SkiaShadow, Thickness } from "../core/Types";
5
5
  import { SkiaShape } from "./SkiaShape";
6
6
  /**
@@ -81,7 +81,7 @@ export class SkiaSlider extends SkiaControl {
81
81
  case "Material": return { thumb: 20, trackH: 4, track: "#E8EAED", selected: "#2196F3", thumbColor: "#2196F3", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.3, Color: Colors.Black }) };
82
82
  case "Material3": return { thumb: 20, trackH: 4, track: "#E6E0E9", selected: "#6750A4", thumbColor: "#6750A4", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.3, Color: Colors.Black }) };
83
83
  case "Windows": return { thumb: 20, trackH: 4, track: "#C6C6C6", selected: "#0078D4", thumbColor: "#0078D4", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 2, Opacity: 0.25, Color: Colors.Black }) };
84
- default: return { thumb: 35, trackH: 6, track: "#D7DBE0", selected: "#DC143C", thumbColor: "#DC143C", shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 3, Opacity: 0.25, Color: Colors.Black }) };
84
+ default: return { thumb: 35, trackH: 6, track: "#D7DBE0", selected: DefaultAccent, thumbColor: DefaultAccent, shadow: new SkiaShadow({ X: 0, Y: 1, Blur: 3, Opacity: 0.25, Color: Colors.Black }) };
85
85
  }
86
86
  }
87
87
  /** Thumb shadows paint outside the box: the cache must include them. */
@@ -1,3 +1,4 @@
1
+ import { DefaultAccent } from "../core/ControlStyle";
1
2
  import { Colors, SkiaShadow, Thickness } from "../core/Types";
2
3
  import { Easing } from "../core/Easing";
3
4
  import { SkiaShape } from "./SkiaShape";
@@ -11,7 +12,7 @@ export class SkiaSwitch extends SkiaToggle {
11
12
  static DefaultAccessibilityRole = "switch";
12
13
  Track;
13
14
  Thumb;
14
- static DefaultAccent = "#DC143C"; // Crimson
15
+ static DefaultAccent = DefaultAccent;
15
16
  static DefaultTrack = "#D7DBE0";
16
17
  static MaterialOutline = "#79747E";
17
18
  StyleDefault(name) {
@@ -71,8 +72,9 @@ export class SkiaSwitch extends SkiaToggle {
71
72
  frame.StrokeColor = "#767676";
72
73
  thumb.Margin = new Thickness(5.5);
73
74
  break;
75
+ // the Agent Signals switch size (C# 5c1288f7, drawnui-cross 6as): 46 x 22, the thumb inside its 2 pt margin
74
76
  default:
75
- this.SetContentSize(46, 28);
77
+ this.SetContentSize(46, 22);
76
78
  frame.CornerRadius = 20;
77
79
  thumb.Margin = new Thickness(2);
78
80
  break;
@@ -0,0 +1,52 @@
1
+ import type { SkiaControl } from "../core/SkiaControl";
2
+ import { type Color, Thickness } from "../core/Types";
3
+ /**
4
+ * Look and timing of the tooltips a canvas shows for controls with a `Tooltip` (drawnui-cross 6ar, C# TooltipStyle).
5
+ * Set app-wide with `Super.TooltipStyle`, or per canvas with `Canvas.TooltipStyle`. Read when a tooltip is built, so a
6
+ * change applies from the next tooltip shown.
7
+ */
8
+ export declare class TooltipStyle {
9
+ /** Background of the tooltip: dark, a step lighter than dark app surfaces. */
10
+ BackgroundColor: Color;
11
+ /** Color of the tooltip text. */
12
+ TextColor: Color;
13
+ /** Color of the 1 pt border, lifts the tooltip off dark surfaces. Undefined or transparent for none. */
14
+ BorderColor?: Color;
15
+ /** Color of the soft shadow under the tooltip. Undefined or transparent for none. */
16
+ ShadowColor?: Color;
17
+ /** Font family of the tooltip text, undefined for the default font. */
18
+ FontFamily?: string;
19
+ /** Font size of the tooltip text, in points. */
20
+ FontSize: number;
21
+ /** Corner radius of the tooltip, in points. */
22
+ CornerRadius: number;
23
+ /** Space around the text, in points. */
24
+ Padding: Thickness;
25
+ /** Longer text wraps at this width, in points. */
26
+ MaxWidth: number;
27
+ /** How long the mouse rests on a control before its tooltip shows, in milliseconds. */
28
+ ShowDelayMs: number;
29
+ /** A tooltip that closed less than this many milliseconds ago lets the next one show at once (moving along a toolbar). */
30
+ FollowWindowMs: number;
31
+ /**
32
+ * False (default): attached to its control, centered 6 pt above it (below it where there is no room). True: below and
33
+ * to the right of the pointer where it rested (above it where there is no room). Either way it stays put while the
34
+ * mouse moves over the control.
35
+ */
36
+ AtCursor: boolean;
37
+ /** Moves the tooltip right (negative: left) from where it would go, in points. */
38
+ OffsetX: number;
39
+ /** Moves the tooltip down (negative: up), in points; on the flipped side it moves the other way, keeping its distance. */
40
+ OffsetY: number;
41
+ /**
42
+ * Builds the tooltip content for a text instead of the default rounded label. The control is measured and drawn on its
43
+ * own, outside the tree: it takes no input and screen readers do not see it.
44
+ */
45
+ CreateTooltip?: (text: string) => SkiaControl;
46
+ constructor(init?: Partial<TooltipStyle>);
47
+ /** Room left around the default tooltip for its shadow, in points. */
48
+ static readonly ShadowRoom = 8;
49
+ private static Visible;
50
+ /** The default tooltip content: the text on a rounded background. */
51
+ CreateDefault(text: string): SkiaControl;
52
+ }
@@ -0,0 +1,88 @@
1
+ import { Aria } from "../core/Accessibility";
2
+ import { Super } from "../core/Super";
3
+ import { SkiaShadow, Thickness } from "../core/Types";
4
+ import { SkiaLabel } from "./SkiaLabel";
5
+ import { SkiaShape } from "./SkiaShape";
6
+ /**
7
+ * Look and timing of the tooltips a canvas shows for controls with a `Tooltip` (drawnui-cross 6ar, C# TooltipStyle).
8
+ * Set app-wide with `Super.TooltipStyle`, or per canvas with `Canvas.TooltipStyle`. Read when a tooltip is built, so a
9
+ * change applies from the next tooltip shown.
10
+ */
11
+ export class TooltipStyle {
12
+ /** Background of the tooltip: dark, a step lighter than dark app surfaces. */
13
+ BackgroundColor = "#2B2D31";
14
+ /** Color of the tooltip text. */
15
+ TextColor = "#F2F3F5";
16
+ /** Color of the 1 pt border, lifts the tooltip off dark surfaces. Undefined or transparent for none. */
17
+ BorderColor = "#24FFFFFF";
18
+ /** Color of the soft shadow under the tooltip. Undefined or transparent for none. */
19
+ ShadowColor = "#59000000";
20
+ /** Font family of the tooltip text, undefined for the default font. */
21
+ FontFamily;
22
+ /** Font size of the tooltip text, in points. */
23
+ FontSize = 13;
24
+ /** Corner radius of the tooltip, in points. */
25
+ CornerRadius = 6;
26
+ /** Space around the text, in points. */
27
+ Padding = new Thickness(12, 8);
28
+ /** Longer text wraps at this width, in points. */
29
+ MaxWidth = 320;
30
+ /** How long the mouse rests on a control before its tooltip shows, in milliseconds. */
31
+ ShowDelayMs = 600;
32
+ /** A tooltip that closed less than this many milliseconds ago lets the next one show at once (moving along a toolbar). */
33
+ FollowWindowMs = 500;
34
+ /**
35
+ * False (default): attached to its control, centered 6 pt above it (below it where there is no room). True: below and
36
+ * to the right of the pointer where it rested (above it where there is no room). Either way it stays put while the
37
+ * mouse moves over the control.
38
+ */
39
+ AtCursor = false;
40
+ /** Moves the tooltip right (negative: left) from where it would go, in points. */
41
+ OffsetX = 0;
42
+ /** Moves the tooltip down (negative: up), in points; on the flipped side it moves the other way, keeping its distance. */
43
+ OffsetY = 0;
44
+ /**
45
+ * Builds the tooltip content for a text instead of the default rounded label. The control is measured and drawn on its
46
+ * own, outside the tree: it takes no input and screen readers do not see it.
47
+ */
48
+ CreateTooltip;
49
+ constructor(init) { if (init)
50
+ Object.assign(this, init); }
51
+ /** Room left around the default tooltip for its shadow, in points. */
52
+ static ShadowRoom = 8;
53
+ static Visible(c) {
54
+ if (!c || c === "Transparent" || c === "transparent")
55
+ return false;
56
+ const p = Super.ParseColor(c);
57
+ return p[3] > 0;
58
+ }
59
+ /** The default tooltip content: the text on a rounded background. */
60
+ CreateDefault(text) {
61
+ const shadow = TooltipStyle.Visible(this.ShadowColor);
62
+ const border = TooltipStyle.Visible(this.BorderColor);
63
+ const shape = new SkiaShape();
64
+ shape.CornerRadius = this.CornerRadius;
65
+ shape.BackgroundColor = this.BackgroundColor;
66
+ if (border) {
67
+ shape.StrokeColor = this.BorderColor;
68
+ shape.StrokeWidth = 1;
69
+ }
70
+ shape.Padding = this.Padding;
71
+ shape.Margin = shadow ? new Thickness(TooltipStyle.ShadowRoom) : Thickness.Zero; // the shadow is drawn inside the measured size
72
+ shape.MaximumWidthRequest = this.MaxWidth;
73
+ shape.UseCache = "Image";
74
+ if (shadow)
75
+ shape.Shadows = [new SkiaShadow({ X: 0, Y: 2, Blur: 6, Opacity: 1, Color: this.ShadowColor })];
76
+ const label = new SkiaLabel();
77
+ label.Text = text;
78
+ label.TextColor = this.TextColor;
79
+ label.FontSize = this.FontSize;
80
+ if (this.FontFamily)
81
+ label.FontFamily = this.FontFamily;
82
+ shape.AddSubView(label);
83
+ shape.AccessibilityRole = Aria.RolePresentation;
84
+ label.AccessibilityRole = Aria.RolePresentation;
85
+ return shape;
86
+ }
87
+ }
88
+ Super.TooltipStyle = new TooltipStyle();
@@ -148,6 +148,7 @@ export declare class SkiaAccessibilityManager {
148
148
  static TryFindGroup(control: SkiaControl): {
149
149
  Group: SkiaControl;
150
150
  Item: SkiaControl;
151
+ Holder: SkiaControl;
151
152
  } | undefined;
152
153
  /** Remembers where keyboard focus is inside its group, so the next Tab into the group lands there. */
153
154
  private NoteFocus;
@@ -166,6 +167,23 @@ export declare class SkiaAccessibilityManager {
166
167
  * content, and focused once drawn. True when the key belongs to the group.
167
168
  */
168
169
  MoveInGroup(focused: SkiaControl, key: InputKey): boolean;
170
+ private focusRequest?;
171
+ private popupFocusRoot?;
172
+ /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
173
+ RequestKeyboardFocus(control: SkiaControl): void;
174
+ /**
175
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
176
+ * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
177
+ */
178
+ KeyboardScope?: SkiaControl;
179
+ /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
180
+ NextTabStop(from: SkiaControl | undefined, forward: boolean): SkiaControl | undefined;
181
+ /**
182
+ * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
183
+ * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
184
+ */
185
+ FocusOpenedPopup(root: SkiaControl): void;
186
+ private ProcessFocusRequests;
169
187
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
170
188
  private ProcessGroupFocus;
171
189
  private FocusFromKeyboard;
@@ -106,9 +106,19 @@ export class SkiaAccessibilityManager {
106
106
  * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
107
107
  */
108
108
  static TryFindGroup(control) {
109
+ const path = [];
109
110
  for (let child = control, parent = control.Parent; parent; child = parent, parent = parent.Parent) {
110
- if (Aria.IsCompositeRole(parent.AccessibilityRole))
111
- return { Group: parent, Item: child };
111
+ path.push(child);
112
+ if (!Aria.IsCompositeRole(parent.AccessibilityRole))
113
+ continue;
114
+ // drawnui-cross 6ao: the role may sit on a wrapper (a menu shape around a column of lines); the items are the
115
+ // children of the control that holds them, found down the path through single children that are not nodes
116
+ let holder = parent, k = path.length - 1;
117
+ while (k > 0 && ViewsOf(holder).length === 1 && !IsInteractiveNode(path[k])) {
118
+ holder = path[k];
119
+ k--;
120
+ }
121
+ return { Group: parent, Item: path[k], Holder: holder };
112
122
  }
113
123
  return undefined;
114
124
  }
@@ -124,6 +134,15 @@ export class SkiaAccessibilityManager {
124
134
  * item; the arrow keys move between items. Every node outside a group is a stop.
125
135
  */
126
136
  IsTabStop(node) {
137
+ // an open popup window keeps the keyboard: Tab never leaves it, as with native menus
138
+ const scope = this.KeyboardScope;
139
+ if (scope) {
140
+ let c = node;
141
+ while (c && c !== scope)
142
+ c = c.Parent;
143
+ if (!c)
144
+ return false;
145
+ }
127
146
  const found = SkiaAccessibilityManager.TryFindGroup(node);
128
147
  if (!found)
129
148
  return true;
@@ -158,7 +177,7 @@ export class SkiaAccessibilityManager {
158
177
  const found = SkiaAccessibilityManager.TryFindGroup(focused);
159
178
  if (!found)
160
179
  return false;
161
- const { Group: group, Item: item } = found;
180
+ const { Holder: group, Item: item } = found;
162
181
  const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
163
182
  const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
164
183
  if (current < 0 || count < 1)
@@ -212,6 +231,53 @@ export class SkiaAccessibilityManager {
212
231
  group.Superview?.Update(); // resolved at the end of the next frame, together with the snapshot
213
232
  return true;
214
233
  }
234
+ // ---- keyboard focus moved by popup windows (drawnui-cross 6ao rule 2, and back to the opener on close) ----
235
+ focusRequest;
236
+ popupFocusRoot;
237
+ /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
238
+ RequestKeyboardFocus(control) { this.focusRequest = control; }
239
+ /**
240
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
241
+ * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
242
+ */
243
+ KeyboardScope;
244
+ /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
245
+ NextTabStop(from, forward) {
246
+ const stops = this.Snapshot.filter((n) => n.CanInteract && this.IsTabStop(n.Source)).map((n) => n.Source);
247
+ if (stops.length === 0)
248
+ return undefined;
249
+ let current = from ? stops.indexOf(from) : -1;
250
+ if (current < 0)
251
+ current = forward ? -1 : stops.length;
252
+ const next = forward ? current + 1 : current - 1;
253
+ if (this.KeyboardScope)
254
+ return stops[(next + stops.length) % stops.length];
255
+ return next >= 0 && next < stops.length ? stops[next] : undefined;
256
+ }
257
+ /**
258
+ * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
259
+ * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
260
+ */
261
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; }
262
+ ProcessFocusRequests(scale, w, h) {
263
+ const request = this.focusRequest, root = this.popupFocusRoot;
264
+ this.focusRequest = this.popupFocusRoot = undefined;
265
+ if (root && !root.IsDisposed && root.Superview) {
266
+ this.Rebuild(scale, w, h);
267
+ const inside = (c) => { for (let p = c; p; p = p.Parent)
268
+ if (p === root)
269
+ return true; return false; };
270
+ const choice = (role) => role === Aria.RoleRadio || role === Aria.RoleMenuItemRadio || role === "option" || role === "tab";
271
+ const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && SkiaAccessibilityManager.TryFindGroup(n.Source));
272
+ const target = items.find((n) => n.IsPressed === true && choice(n.Role)) ?? items[0];
273
+ if (target) {
274
+ this.FocusFromKeyboard(target.Source, scale, w, h);
275
+ return;
276
+ }
277
+ }
278
+ if (request && !request.IsDisposed && request.Superview && request.AccessibilityCanInteract)
279
+ this.FocusFromKeyboard(request, scale, w, h);
280
+ }
215
281
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
216
282
  ProcessGroupFocus(scale, w, h, requestFrame) {
217
283
  const request = this.groupRequest;
@@ -285,6 +351,8 @@ export class SkiaAccessibilityManager {
285
351
  */
286
352
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
287
353
  this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
354
+ if (this.focusRequest || this.popupFocusRoot)
355
+ this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
288
356
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
289
357
  return;
290
358
  const now = performance.now();
@@ -401,6 +469,10 @@ function SameValue(a, b) {
401
469
  return a === b || (!!a && !!b && a.Now === b.Now && a.Min === b.Min && a.Max === b.Max && a.Step === b.Step && a.Text === b.Text);
402
470
  }
403
471
  // ---- group helpers (duck-typed layouts and scrolls) ----
472
+ /** A node the keyboard can land on: a role that is not presentation and takes input. */
473
+ function IsInteractiveNode(c) {
474
+ return !!c.AccessibilityRole && c.AccessibilityRole !== Aria.RolePresentation && c.IsAccessibilityElement && c.AccessibilityCanInteract;
475
+ }
404
476
  /** Children of a control (a layout's Views, a scroll's Content). */
405
477
  function ViewsOf(c) {
406
478
  if ("Views" in c)
@@ -3,8 +3,10 @@ import type { DrawingContext, SkiaControl } from "./SkiaControl";
3
3
  import type { AnimatorBase } from "./Animators";
4
4
  import { SkiaAccessibilityManager } from "./Accessibility";
5
5
  import { HoverManager } from "./Hover";
6
- import { type Color, type RenderingModeType } from "./Types";
7
- import { ContextMenuEventArgs, type GesturesMode, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
6
+ import { type TooltipStyleLike } from "./Tooltips";
7
+ import { PopupAnchor, type PopupId, type PopupWindowOptions } from "./PopupWindows";
8
+ import { type Color, type RenderingModeType, SKRect } from "./Types";
9
+ import { ContextMenuEventArgs, type GesturesMode, SKPoint, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
8
10
  /**
9
11
  * Mirrors DrawnUi Canvas (DrawnView): hosts one Content control on an HTML canvas element,
10
12
  * owns RenderingScale (devicePixelRatio), the surface, the on-demand frame loop and raw input.
@@ -45,6 +47,47 @@ export declare class Canvas {
45
47
  readonly AccessibilityManager: SkiaAccessibilityManager;
46
48
  /** Mouse hover of the controls (drawnui-cross 6m): ReceivesHover / IsHovered / HoverChanged. */
47
49
  readonly Hover: HoverManager;
50
+ private tooltipController?;
51
+ /** Made on first use: a canvas that never shows a tooltip allocates nothing for it. */
52
+ private get tooltip();
53
+ /** Look and timing of the tooltips on this canvas; unset uses `Super.TooltipStyle`. */
54
+ TooltipStyle?: TooltipStyleLike;
55
+ get TooltipStyleUsed(): TooltipStyleLike;
56
+ /** The text of the tooltip shown now, undefined when none is shown. */
57
+ get ShownTooltip(): string | undefined;
58
+ private popupLayer?;
59
+ /** Made on first use, like the tooltip. */
60
+ private get popups();
61
+ private popupKeysHooked;
62
+ /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
63
+ readonly PopupWindowClosed: Set<(id: PopupId) => void>;
64
+ /**
65
+ * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
66
+ * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
67
+ * a press outside it, Escape, the wheel outside it, window blur, `ClosePopupWindow` and the options.
68
+ */
69
+ OpenPopupWindow(content: SkiaControl, anchor: PopupAnchor | SKPoint | SKRect | SkiaControl | {
70
+ X: number;
71
+ Y: number;
72
+ }, options?: PopupWindowOptions): PopupId;
73
+ /** Closes the popup window (nothing when it is closed already). */
74
+ ClosePopupWindow(id: PopupId): void;
75
+ /** Closes every popup window. */
76
+ ClosePopupWindows(): void;
77
+ /** The popup window is still open. */
78
+ IsPopupWindowOpen(id: PopupId): boolean;
79
+ /** True while a popup window that takes input is open. */
80
+ get HasPopupWindows(): boolean;
81
+ /** The content of the top popup window that takes input. */
82
+ get TopPopupWindow(): SkiaControl | undefined;
83
+ /** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
84
+ OnWindowDeactivated(): void;
85
+ RaisePopupWindowClosed(id: PopupId): void;
86
+ private AfterPopupsChanged;
87
+ private readonly onPopupKey;
88
+ private readonly onPopupChar;
89
+ private HookPopupKeys;
90
+ private readonly onWindowBlur;
48
91
  private content?;
49
92
  get Content(): SkiaControl | undefined;
50
93
  set Content(value: SkiaControl | undefined);
@@ -210,6 +253,20 @@ export declare class Canvas {
210
253
  private gestureOwner;
211
254
  /** DrawnUi IsSavedGesture: the types replayed to the owner instead of being routed again. */
212
255
  private static IsSavedGesture;
213
- /** Entry into the control tree, same shape as DrawnUi Canvas.ProcessGestures. */
256
+ private focusedChild?;
257
+ private focusAtDown?;
258
+ private tapNoFocus;
259
+ private reportingFocus;
260
+ /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
261
+ get FocusedChild(): SkiaControl | undefined;
262
+ /**
263
+ * Moves the focus. The new control is asked first and the focus moves only when it takes it (a tap on a button leaves an
264
+ * editor focused); undefined clears it. Nothing moves while the focused control has LockFocus. `setter` is a control
265
+ * that focused itself already (an editor on its press) or the focused control letting go itself (Escape, submit).
266
+ */
267
+ ReportFocus(value: SkiaControl | undefined, setter?: SkiaControl): void;
268
+ /** Entry into the control tree; on a completed tap the focus follows it (C# Canvas: focus only on Tapped). */
214
269
  protected ProcessGestures(root: SkiaControl, args: SkiaGesturesParameters): SkiaControl | null;
270
+ /** Same shape as DrawnUi Canvas.ProcessGestures. */
271
+ private RouteGestures;
215
272
  }