drawnui-react 0.1.0-preview.34 → 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 +7 -1
  7. package/dist/controls/SkiaLabel.js +44 -8
  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;
@@ -113,7 +115,11 @@ export declare class SkiaLabel extends SkiaControl {
113
115
  private lines;
114
116
  private mainFonts?;
115
117
  private readonly fontsCache;
116
- private readonly runCache;
118
+ /** Runs of a text per style (Segment), and the same runs carrying a span; cleared when the glyph spacing changes. */
119
+ private runCache;
120
+ private spanRunCache;
121
+ /** Wrap tokens of the text, kept while the label has not changed (NeedMeasure) at the same scale. */
122
+ private tokens?;
117
123
  /** CharacterSpacing in pixels at the measured scale: added after every glyph of a run (its Width includes them). */
118
124
  private glyphSpacing;
119
125
  private ResolveFonts;
@@ -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) ----
@@ -127,7 +129,11 @@ export class SkiaLabel extends SkiaControl {
127
129
  lines = [];
128
130
  mainFonts;
129
131
  fontsCache = new Map();
132
+ /** Runs of a text per style (Segment), and the same runs carrying a span; cleared when the glyph spacing changes. */
130
133
  runCache = new Map();
134
+ spanRunCache = new WeakMap();
135
+ /** Wrap tokens of the text, kept while the label has not changed (NeedMeasure) at the same scale. */
136
+ tokens;
131
137
  /** CharacterSpacing in pixels at the measured scale: added after every glyph of a run (its Width includes them). */
132
138
  glyphSpacing = 0;
133
139
  ResolveFonts(family, weight, italic, sizePx) {
@@ -192,15 +198,20 @@ export class SkiaLabel extends SkiaControl {
192
198
  Segment(text, fonts, span) {
193
199
  if (text.length === 0)
194
200
  return [];
195
- const cacheKey = fonts.Key + " " + text;
196
- let cached = this.runCache.get(cacheKey);
201
+ let byText = this.runCache.get(fonts);
202
+ if (!byText) {
203
+ byText = new Map();
204
+ this.runCache.set(fonts, byText);
205
+ }
206
+ let cached = byText.get(text);
207
+ const cacheKey = text;
197
208
  if (!cached) {
198
209
  const main = fonts.Main;
199
210
  const fbs = fonts.Fallbacks;
200
211
  cached = [];
201
212
  text = SkiaLabel.DropIgnorables(text, main, fbs);
202
213
  if (text.length === 0) {
203
- this.runCache.set(cacheKey, cached);
214
+ byText.set(cacheKey, cached);
204
215
  return cached;
205
216
  }
206
217
  if (fbs.length === 0) {
@@ -231,9 +242,27 @@ export class SkiaLabel extends SkiaControl {
231
242
  const t = cps.slice(start).join("");
232
243
  cached.push({ Text: t, Font: current, Width: this.Advance(current, t), Fonts: fonts });
233
244
  }
234
- this.runCache.set(cacheKey, cached);
245
+ byText.set(cacheKey, cached);
246
+ }
247
+ if (!span)
248
+ return cached;
249
+ // the same runs carrying the span, made once per span, style and text
250
+ let bySpan = this.spanRunCache.get(span);
251
+ if (!bySpan) {
252
+ bySpan = new Map();
253
+ this.spanRunCache.set(span, bySpan);
254
+ }
255
+ let spanByText = bySpan.get(fonts);
256
+ if (!spanByText) {
257
+ spanByText = new Map();
258
+ bySpan.set(fonts, spanByText);
259
+ }
260
+ let withSpan = spanByText.get(cacheKey);
261
+ if (!withSpan) {
262
+ withSpan = cached.map((r) => ({ ...r, Span: span }));
263
+ spanByText.set(cacheKey, withSpan);
235
264
  }
236
- return span ? cached.map((r) => ({ ...r, Span: span })) : cached;
265
+ return withSpan;
237
266
  }
238
267
  Width(runs) { let w = 0; for (const r of runs)
239
268
  w += r.Width; return w; }
@@ -399,7 +428,10 @@ export class SkiaLabel extends SkiaControl {
399
428
  const sp = this.glyphSpacing;
400
429
  const out = [];
401
430
  const empty = (fonts) => { const l = this.NewLine(); l.Ascent = fonts.Ascent; l.Descent = fonts.Descent; return l; };
402
- for (const para of this.Tokenize(scale)) {
431
+ // the text's wrap tokens change only with the label (NeedMeasure) or the scale
432
+ if (this.NeedMeasure || !this.tokens || this.tokens.Scale !== scale)
433
+ this.tokens = { Scale: scale, Paragraphs: this.Tokenize(scale) };
434
+ for (const para of this.tokens.Paragraphs) {
403
435
  let line = this.NewLine();
404
436
  if (out.length > 0 && !para.LineBreak)
405
437
  line.Para = true;
@@ -653,7 +685,10 @@ export class SkiaLabel extends SkiaControl {
653
685
  const b = r.Font.getGlyphBounds([g[0], g[n - 1]]);
654
686
  return [x0 + r.Shaped.Positions[0] + b[0], x0 + r.Shaped.Positions[(n - 1) * 2] + b[6]];
655
687
  }
656
- const ids = r.Font.getGlyphIDs(r.Text);
688
+ // only the first and the last character matter
689
+ const first = String.fromCodePoint(r.Text.codePointAt(0));
690
+ const lastAt = r.Text.length - (r.Text.length > 1 && r.Text.charCodeAt(r.Text.length - 1) >= 0xDC00 && r.Text.charCodeAt(r.Text.length - 1) <= 0xDFFF ? 2 : 1);
691
+ const ids = r.Font.getGlyphIDs(first + r.Text.slice(lastAt));
657
692
  const n = ids.length;
658
693
  const b = r.Font.getGlyphBounds([ids[0], ids[n - 1]]);
659
694
  const lastAdvance = r.Font.getGlyphWidths([ids[n - 1]])[0];
@@ -683,7 +718,8 @@ export class SkiaLabel extends SkiaControl {
683
718
  const glyphSpacing = scale * (this.characterSpacing - 1);
684
719
  if (glyphSpacing !== this.glyphSpacing) {
685
720
  this.glyphSpacing = glyphSpacing;
686
- this.runCache.clear();
721
+ this.runCache = new Map();
722
+ this.spanRunCache = new WeakMap();
687
723
  }
688
724
  const px = this.padding.HorizontalThickness * scale, py = this.padding.VerticalThickness * scale;
689
725
  const extraH = this.EffectsExtra(scale).H;
@@ -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;