drawnui-react 0.1.0-preview.4 → 0.1.0-preview.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -14
- package/SKIPPED.md +36 -26
- package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
- package/dist/controls/AnimatedFramesRenderer.js +18 -1
- package/dist/controls/DrawnGame.d.ts +44 -0
- package/dist/controls/DrawnGame.js +82 -0
- package/dist/controls/GridStructure.d.ts +16 -2
- package/dist/controls/GridStructure.js +40 -4
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +17 -3
- package/dist/controls/SkiaButton.js +26 -8
- package/dist/controls/SkiaCarousel.d.ts +22 -3
- package/dist/controls/SkiaCarousel.js +85 -9
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +2 -7
- package/dist/controls/SkiaDrawer.d.ts +15 -0
- package/dist/controls/SkiaDrawer.js +42 -7
- package/dist/controls/SkiaEditor.d.ts +48 -2
- package/dist/controls/SkiaEditor.js +268 -53
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +48 -14
- package/dist/controls/SkiaLabel.d.ts +117 -9
- package/dist/controls/SkiaLabel.js +526 -80
- package/dist/controls/SkiaLabelFps.d.ts +16 -0
- package/dist/controls/SkiaLabelFps.js +41 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +364 -21
- package/dist/controls/SkiaLottie.js +5 -3
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +8 -5
- package/dist/controls/SkiaRadioButton.d.ts +2 -0
- package/dist/controls/SkiaRadioButton.js +16 -4
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +35 -5
- package/dist/controls/SkiaScroll.js +252 -32
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
- package/dist/controls/SkiaShaderCarousel.js +27 -5
- package/dist/controls/SkiaShape.d.ts +13 -2
- package/dist/controls/SkiaShape.js +50 -10
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +61 -7
- package/dist/controls/SkiaSprite.d.ts +4 -0
- package/dist/controls/SkiaSprite.js +22 -10
- package/dist/controls/SkiaSvg.d.ts +4 -0
- package/dist/controls/SkiaSvg.js +28 -4
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +4 -8
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +21 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +134 -0
- package/dist/core/Accessibility.js +675 -9
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +222 -10
- package/dist/core/Canvas.js +698 -37
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +81 -2
- package/dist/core/Gestures.js +177 -3
- package/dist/core/Hover.d.ts +51 -0
- package/dist/core/Hover.js +140 -0
- package/dist/core/ImageEffects.d.ts +2 -0
- package/dist/core/ImageEffects.js +2 -0
- package/dist/core/KeyboardManager.d.ts +40 -0
- package/dist/core/KeyboardManager.js +98 -8
- package/dist/core/PopupWindows.d.ts +94 -0
- package/dist/core/PopupWindows.js +205 -0
- package/dist/core/ScrollAnimators.js +9 -0
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +279 -10
- package/dist/core/SkiaControl.js +621 -64
- package/dist/core/SkiaEffect.d.ts +17 -0
- package/dist/core/SkiaEffect.js +43 -8
- package/dist/core/SkiaImageManager.js +1 -1
- package/dist/core/Super.d.ts +29 -2
- package/dist/core/Super.js +54 -3
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/react/SkiaShell.js +65 -26
- package/dist/react/index.d.ts +33 -4
- package/dist/react/index.js +157 -18
- package/dist/react/reconciler.d.ts +20 -0
- package/dist/react/reconciler.js +69 -14
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +61 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { CanvasLeaveWatchers } from "../core/SkiaControl";
|
|
1
2
|
import { SKPoint } from "../core/Gestures";
|
|
2
3
|
import { Super } from "../core/Super";
|
|
3
|
-
import {
|
|
4
|
-
import { ResolveControlStyle } from "../core/ControlStyle";
|
|
4
|
+
import { DefaultAccent, ResolveControlStyle } from "../core/ControlStyle";
|
|
5
5
|
import { KeyboardManager } from "../core/KeyboardManager";
|
|
6
6
|
import { TextInputProxy } from "../core/TextInputProxy";
|
|
7
7
|
import { Colors, ScaledSize, SKRect, Thickness } from "../core/Types";
|
|
@@ -59,6 +59,8 @@ export class SkiaEditor extends SkiaShape {
|
|
|
59
59
|
CanShowCursor = true;
|
|
60
60
|
SelectionColor = "#5590CFFE";
|
|
61
61
|
cursorPosition = 0;
|
|
62
|
+
/** A caret position was given (by the app, a tap, a selection): focusing keeps it; otherwise focusing puts the caret at the end. */
|
|
63
|
+
cursorPlaced = false;
|
|
62
64
|
selectionLength = 0;
|
|
63
65
|
isFocused = false;
|
|
64
66
|
controlStyle = "Unset";
|
|
@@ -67,18 +69,30 @@ export class SkiaEditor extends SkiaShape {
|
|
|
67
69
|
placeholder = new SkiaLabel();
|
|
68
70
|
scrollX = 0;
|
|
69
71
|
scrollY = 0;
|
|
70
|
-
|
|
72
|
+
/** The caret blinks on a timer, asleep between blinks: no frame runs while it waits (DrawnUi.Rust editor_rules). */
|
|
73
|
+
blinkTimer = 0;
|
|
71
74
|
caretVisible = true;
|
|
72
75
|
subscribed = false;
|
|
73
76
|
stubSelectionStop = -1;
|
|
74
77
|
selectionMovingEdge = -1;
|
|
75
78
|
onKeyDown = (key, e) => this.OnKeyDown(key, e);
|
|
76
|
-
onKeyChar = (ch, e) => {
|
|
79
|
+
onKeyChar = (ch, e) => {
|
|
80
|
+
if (KeyboardManager.IsOwnedByElement(e) || KeyboardManager.IsInputMethodKey(e))
|
|
81
|
+
return; // a page control or the IME owns it
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
this.StubTypeText(ch);
|
|
84
|
+
};
|
|
77
85
|
selectionAnchor = -1;
|
|
78
86
|
dragSelecting = false;
|
|
79
87
|
styleApplied = {};
|
|
80
88
|
layoutVersion = -1;
|
|
81
89
|
boxes = [];
|
|
90
|
+
/** The glyph box starting at a text index, and the one ending at it. */
|
|
91
|
+
boxAt = new Map();
|
|
92
|
+
boxEnd = new Map();
|
|
93
|
+
/** Grapheme boundaries of the text, the places a caret may stand. */
|
|
94
|
+
stops = [0];
|
|
95
|
+
stopsText = "";
|
|
82
96
|
constructor() {
|
|
83
97
|
super();
|
|
84
98
|
this.Type = "Rectangle";
|
|
@@ -93,15 +107,6 @@ export class SkiaEditor extends SkiaShape {
|
|
|
93
107
|
this.placeholder.IsVisible = false;
|
|
94
108
|
this.AddSubView(this.placeholder);
|
|
95
109
|
this.AddSubView(this.Label);
|
|
96
|
-
this.blink.mMinValue = 0;
|
|
97
|
-
this.blink.mMaxValue = 1;
|
|
98
|
-
this.blink.Speed = 1000;
|
|
99
|
-
this.blink.Repeat = -1;
|
|
100
|
-
this.blink.OnUpdated = (v) => { const visible = v < 0.5; if (visible !== this.caretVisible) {
|
|
101
|
-
this.caretVisible = visible;
|
|
102
|
-
this.InvalidateCache();
|
|
103
|
-
this.RepaintComposition();
|
|
104
|
-
} };
|
|
105
110
|
this.ApplyControlStyleVisuals();
|
|
106
111
|
this.UpdateLabel();
|
|
107
112
|
}
|
|
@@ -177,8 +182,11 @@ export class SkiaEditor extends SkiaShape {
|
|
|
177
182
|
get ShouldSubmitOnEnter() { return this.IsMultiline && this.ReturnType === "Send"; }
|
|
178
183
|
/** Caret index (UTF-16 units) = the left edge of the selection when one exists. */
|
|
179
184
|
get CursorPosition() { return this.cursorPosition; }
|
|
185
|
+
/** A position from app code as a whole number: beyond the text (MAX_SAFE_INTEGER, Infinity) is the end, NaN is 0. */
|
|
186
|
+
static Whole(v) { return Number.isNaN(v) ? 0 : Math.trunc(v); }
|
|
180
187
|
set CursorPosition(v) {
|
|
181
|
-
|
|
188
|
+
this.cursorPlaced = true;
|
|
189
|
+
const p = Math.max(0, Math.min(this.text.length, SkiaEditor.Whole(v)));
|
|
182
190
|
if (p === this.cursorPosition)
|
|
183
191
|
return;
|
|
184
192
|
this.cursorPosition = p;
|
|
@@ -186,15 +194,31 @@ export class SkiaEditor extends SkiaShape {
|
|
|
186
194
|
}
|
|
187
195
|
get SelectionLength() { return this.selectionLength; }
|
|
188
196
|
set SelectionLength(v) {
|
|
189
|
-
const l = Math.max(0, Math.min(this.text.length - this.cursorPosition, v
|
|
197
|
+
const l = Math.max(0, Math.min(this.text.length - this.cursorPosition, SkiaEditor.Whole(v)));
|
|
190
198
|
if (l === this.selectionLength)
|
|
191
199
|
return;
|
|
192
200
|
this.selectionLength = l;
|
|
193
201
|
this.OnCursorMoved();
|
|
194
202
|
}
|
|
203
|
+
/** Shows the caret for a full half second, then blinks every 500 ms; while the window is inactive no caret, no timer. */
|
|
204
|
+
StartBlink() {
|
|
205
|
+
this.StopBlink();
|
|
206
|
+
const canvas = this.Superview;
|
|
207
|
+
this.caretVisible = canvas?.IsWindowActive !== false;
|
|
208
|
+
if (!this.caretVisible)
|
|
209
|
+
return;
|
|
210
|
+
this.blinkTimer = window.setInterval(() => { this.caretVisible = !this.caretVisible; this.InvalidateCache(); this.RepaintComposition(); }, 500);
|
|
211
|
+
}
|
|
212
|
+
StopBlink() { if (this.blinkTimer) {
|
|
213
|
+
clearInterval(this.blinkTimer);
|
|
214
|
+
this.blinkTimer = 0;
|
|
215
|
+
} }
|
|
195
216
|
OnCursorMoved() {
|
|
196
217
|
this.ScrollToCaret();
|
|
197
|
-
this.
|
|
218
|
+
if (this.isFocused)
|
|
219
|
+
this.StartBlink();
|
|
220
|
+
else
|
|
221
|
+
this.caretVisible = true;
|
|
198
222
|
TextInputProxy.Sync(this);
|
|
199
223
|
this.CursorMoved?.(this);
|
|
200
224
|
this.InvalidateCache();
|
|
@@ -209,9 +233,16 @@ export class SkiaEditor extends SkiaShape {
|
|
|
209
233
|
if (SkiaEditor.Focused && SkiaEditor.Focused !== this)
|
|
210
234
|
SkiaEditor.Focused.IsFocused = false;
|
|
211
235
|
SkiaEditor.Focused = this;
|
|
236
|
+
// focused with no caret placed (from code, by the keyboard): the caret goes to the end of the text, as a tap after
|
|
237
|
+
// the text does, and the native field takes that position when it attaches (C# 2285b422: typing appends)
|
|
238
|
+
if (!this.cursorPlaced) {
|
|
239
|
+
this.cursorPlaced = true;
|
|
240
|
+
this.cursorPosition = this.text.length;
|
|
241
|
+
this.selectionLength = 0;
|
|
242
|
+
this.ScrollToCaret();
|
|
243
|
+
}
|
|
212
244
|
this.SetFocusNative(true);
|
|
213
|
-
this.
|
|
214
|
-
this.blink.Start();
|
|
245
|
+
this.StartBlink();
|
|
215
246
|
}
|
|
216
247
|
else {
|
|
217
248
|
if (SkiaEditor.Focused === this)
|
|
@@ -220,9 +251,17 @@ export class SkiaEditor extends SkiaShape {
|
|
|
220
251
|
this.dragSelecting = false;
|
|
221
252
|
this.stubSelectionStop = -1;
|
|
222
253
|
this.selectionMovingEdge = -1;
|
|
223
|
-
this.
|
|
254
|
+
this.StopBlink();
|
|
224
255
|
this.SetFocusNative(false);
|
|
225
256
|
}
|
|
257
|
+
// the canvas focus follows the editor's own (a press, Tab, code), so a tap elsewhere can end the editing (6ap)
|
|
258
|
+
const canvas = this.Superview;
|
|
259
|
+
if (canvas) {
|
|
260
|
+
if (v)
|
|
261
|
+
canvas.ReportFocus(this, this);
|
|
262
|
+
else if (canvas.FocusedChild === this)
|
|
263
|
+
canvas.ReportFocus(undefined, this);
|
|
264
|
+
}
|
|
226
265
|
this.FocusChanged?.(this, v);
|
|
227
266
|
this.NotifyAccessibility();
|
|
228
267
|
this.InvalidateCache();
|
|
@@ -241,7 +280,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
241
280
|
: style === "Material" ? { bg: "#EFEBF4", corner: 4, stroke: Colors.Transparent, strokeW: 0, cursor: "#2196F3" }
|
|
242
281
|
: style === "Material3" ? { bg: "#E6E0E9", corner: 4, stroke: Colors.Transparent, strokeW: 0, cursor: "#6750A4" }
|
|
243
282
|
: style === "Windows" ? { bg: "#FFFFFF", corner: 2, stroke: "#8A8A8A", strokeW: 1, cursor: "#0078D4" }
|
|
244
|
-
: { bg: "#F2F3F5", corner: 8, stroke: Colors.Transparent, strokeW: 0, cursor:
|
|
283
|
+
: { bg: "#F2F3F5", corner: 8, stroke: Colors.Transparent, strokeW: 0, cursor: DefaultAccent };
|
|
245
284
|
const apply = (key, current, next, set) => {
|
|
246
285
|
if (!(key in this.styleApplied) || this.styleApplied[key] === current) {
|
|
247
286
|
set();
|
|
@@ -305,6 +344,16 @@ export class SkiaEditor extends SkiaShape {
|
|
|
305
344
|
MeasureAbsolute(w, h, scale) {
|
|
306
345
|
const px = this.Padding.HorizontalThickness * scale, py = this.Padding.VerticalThickness * scale;
|
|
307
346
|
const innerW = isFinite(w) ? Math.max(0, w - px) : Infinity;
|
|
347
|
+
// Single-line: the label is Start-aligned and measures to its content, so Center / End alignment had nothing to
|
|
348
|
+
// align in. Give it the field as a MINIMUM: short text centers in the field, longer text still grows past it and
|
|
349
|
+
// scrolls (C# 2e334ddd). A right-to-left paragraph aligns even with Start (it starts at the right, drawnui-cross 6am,
|
|
350
|
+
// C# 8e4b18ef).
|
|
351
|
+
const aligns = this.horizontalTextAlignment !== "Start" || SkiaLabel.FirstStrongIsRtl(this.Label.Text);
|
|
352
|
+
const minWidth = !this.IsMultiline && aligns && isFinite(innerW) && innerW > 0 ? innerW / scale : -1;
|
|
353
|
+
if (this.Label.MinimumWidthRequest !== minWidth) {
|
|
354
|
+
this.Label.MinimumWidthRequest = minWidth;
|
|
355
|
+
this.Label.NeedMeasure = true;
|
|
356
|
+
}
|
|
308
357
|
const labelSize = this.Label.Measure(this.IsMultiline ? innerW : Infinity, Infinity, scale);
|
|
309
358
|
if (this.placeholder.IsVisible)
|
|
310
359
|
this.placeholder.Measure(innerW, Infinity, scale);
|
|
@@ -355,34 +404,89 @@ export class SkiaEditor extends SkiaShape {
|
|
|
355
404
|
this.OnLayoutChanged();
|
|
356
405
|
}
|
|
357
406
|
// ---- caret / selection geometry (pixels relative to the label's DrawingRect) ----
|
|
407
|
+
// Rules shared with DrawnUi.Rust (drawnui-cross 6ak): boxes are visual, the caret at index i is the trailing edge of
|
|
408
|
+
// character i - 1 on its line (the leading edge of the first character at a line start), taps and Left / Right go to
|
|
409
|
+
// the grapheme boundary whose caret x is nearest.
|
|
358
410
|
Boxes() {
|
|
359
411
|
if (this.layoutVersion !== this.Label.LayoutVersion) {
|
|
360
412
|
this.boxes = this.Label.GetGlyphBoxes();
|
|
361
413
|
this.layoutVersion = this.Label.LayoutVersion;
|
|
414
|
+
this.boxAt.clear();
|
|
415
|
+
this.boxEnd.clear();
|
|
416
|
+
for (const b of this.boxes) {
|
|
417
|
+
this.boxAt.set(b.Index, b);
|
|
418
|
+
this.boxEnd.set(b.Index + b.Length, b);
|
|
419
|
+
}
|
|
362
420
|
}
|
|
363
421
|
return this.boxes;
|
|
364
422
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
423
|
+
Stops() {
|
|
424
|
+
if (this.stopsText !== this.text) {
|
|
425
|
+
this.stopsText = this.text;
|
|
426
|
+
this.stops = SkiaEditor.Graphemes(this.text).map((g) => g.index);
|
|
427
|
+
this.stops.push(this.text.length);
|
|
428
|
+
}
|
|
429
|
+
return this.stops;
|
|
430
|
+
}
|
|
431
|
+
/** The laid-out line a caret index belongs to: the line holding the character before it, else the one starting at it. */
|
|
432
|
+
static LineOf(index, lines) {
|
|
433
|
+
for (const l of lines)
|
|
434
|
+
if (index > l.Start && index <= l.End)
|
|
435
|
+
return l;
|
|
436
|
+
for (const l of lines)
|
|
437
|
+
if (index === l.Start)
|
|
438
|
+
return l;
|
|
439
|
+
let line = lines[0];
|
|
440
|
+
for (const l of lines)
|
|
441
|
+
if (l.Start <= index)
|
|
442
|
+
line = l; // in a space wrapped away: the line before it
|
|
443
|
+
return line;
|
|
444
|
+
}
|
|
445
|
+
/** Where the caret before character `index` stands (label pixels): its x, the direction of the text there, its line box. */
|
|
446
|
+
CaretPlace(index) {
|
|
368
447
|
const lines = this.Label.GetLineBoxes();
|
|
369
448
|
if (lines.length === 0)
|
|
370
449
|
return undefined;
|
|
450
|
+
const boxes = this.Boxes();
|
|
451
|
+
const line = SkiaEditor.LineOf(index, lines);
|
|
452
|
+
const trailing = (b) => ({ X: b.Rtl ? b.Left : b.Left + b.Width, Rtl: !!b.Rtl, Top: b.Top, Height: b.Height });
|
|
453
|
+
if (index > line.Start) {
|
|
454
|
+
let prev = this.boxEnd.get(index);
|
|
455
|
+
if (!prev || prev.Line !== line.Line) {
|
|
456
|
+
prev = undefined;
|
|
457
|
+
for (const b of boxes)
|
|
458
|
+
if (b.Line === line.Line && b.Index < index)
|
|
459
|
+
prev = b;
|
|
460
|
+
}
|
|
461
|
+
if (prev)
|
|
462
|
+
return trailing(prev);
|
|
463
|
+
}
|
|
464
|
+
const cur = this.boxAt.get(index);
|
|
465
|
+
if (cur && cur.Line === line.Line)
|
|
466
|
+
return { X: cur.Rtl ? cur.Left + cur.Width : cur.Left, Rtl: !!cur.Rtl, Top: cur.Top, Height: cur.Height };
|
|
467
|
+
return { X: line.Left, Rtl: false, Top: line.Top, Height: line.Height };
|
|
468
|
+
}
|
|
469
|
+
/** Rect of the caret before character `index` (label pixels), or undefined before the first layout. */
|
|
470
|
+
CaretRectLabelPx(index = this.cursorPosition + this.selectionLength) {
|
|
471
|
+
const place = this.CaretPlace(index);
|
|
472
|
+
if (!place)
|
|
473
|
+
return undefined;
|
|
371
474
|
const caretW = 2 * this.RenderingScale;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
475
|
+
return SKRect.Create(place.Rtl ? place.X - caretW : place.X, place.Top, caretW, place.Height);
|
|
476
|
+
}
|
|
477
|
+
/** The grapheme boundary of a line whose caret x is nearest to `x` (a tie: the smaller index). */
|
|
478
|
+
NearestStop(line, x) {
|
|
479
|
+
let best = -1, bestD = Infinity;
|
|
480
|
+
for (const i of this.Stops()) {
|
|
481
|
+
if (i < line.Start || i > line.End)
|
|
482
|
+
continue;
|
|
483
|
+
const d = Math.abs((this.CaretPlace(i)?.X ?? 0) - x);
|
|
484
|
+
if (d < bestD - 0.01) {
|
|
485
|
+
best = i;
|
|
486
|
+
bestD = d;
|
|
487
|
+
}
|
|
381
488
|
}
|
|
382
|
-
|
|
383
|
-
return SKRect.Create(prev.Left + prev.Width, prev.Top, caretW, prev.Height);
|
|
384
|
-
const first = lines[0];
|
|
385
|
-
return SKRect.Create(first.Left, first.Top, caretW, first.Height);
|
|
489
|
+
return best >= 0 ? best : Math.min(line.Start, this.text.length);
|
|
386
490
|
}
|
|
387
491
|
/** C# GetCursorPosition: the text index nearest to a point in label pixels. */
|
|
388
492
|
HitTestIndex(x, y) {
|
|
@@ -395,16 +499,54 @@ export class SkiaEditor extends SkiaShape {
|
|
|
395
499
|
line = l;
|
|
396
500
|
break;
|
|
397
501
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
502
|
+
return this.NearestStop(line, x);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Left / Right from a caret index: the grapheme boundary on its line whose caret x is nearest that way (equal x: the
|
|
506
|
+
* one logically nearest); at the visual edge of the line one grapheme logically, forward for Right in a
|
|
507
|
+
* left-to-right paragraph and backward in a right-to-left one (Left the other way round).
|
|
508
|
+
*/
|
|
509
|
+
VisualTarget(from, dir) {
|
|
510
|
+
const lines = this.Label.GetLineBoxes();
|
|
511
|
+
const stops = this.Stops();
|
|
512
|
+
let line;
|
|
513
|
+
if (lines.length > 0) {
|
|
514
|
+
line = SkiaEditor.LineOf(from, lines);
|
|
515
|
+
const x0 = this.CaretPlace(from)?.X ?? 0;
|
|
516
|
+
let best = -1, bestX = 0;
|
|
517
|
+
for (const i of stops) {
|
|
518
|
+
if (i < line.Start || i > line.End || i === from)
|
|
519
|
+
continue;
|
|
520
|
+
const x = this.CaretPlace(i)?.X ?? 0;
|
|
521
|
+
if ((x - x0) * dir <= 0.01)
|
|
522
|
+
continue;
|
|
523
|
+
if (best < 0 || (x - bestX) * dir < -0.01 || (Math.abs(x - bestX) <= 0.01 && Math.abs(i - from) < Math.abs(best - from))) {
|
|
524
|
+
best = i;
|
|
525
|
+
bestX = x;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (best >= 0)
|
|
529
|
+
return best;
|
|
530
|
+
}
|
|
531
|
+
const start = Math.max(this.text.lastIndexOf(ParagraphBreak, from - 1) + 1, 0);
|
|
532
|
+
const end = this.text.indexOf(ParagraphBreak, from);
|
|
533
|
+
const step = SkiaLabel.FirstStrongIsRtl(this.text.slice(start, end < 0 ? undefined : end)) ? -dir : dir;
|
|
534
|
+
let to = from;
|
|
535
|
+
if (step > 0) {
|
|
536
|
+
for (const i of stops)
|
|
537
|
+
if (i > from) {
|
|
538
|
+
to = i;
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else
|
|
543
|
+
for (let k = stops.length - 1; k >= 0; k--)
|
|
544
|
+
if (stops[k] < from) {
|
|
545
|
+
to = stops[k];
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
// the step only crosses to the next or previous line: inside a mixed line the visual end stays put
|
|
549
|
+
return line && lines.length > 0 && SkiaEditor.LineOf(to, lines) === line ? from : to;
|
|
408
550
|
}
|
|
409
551
|
LabelPoint(args, apply, starting = false) {
|
|
410
552
|
const loc = starting ? args.Event.StartingLocation : apply.MappedLocation;
|
|
@@ -424,9 +566,10 @@ export class SkiaEditor extends SkiaShape {
|
|
|
424
566
|
const paint = new CK.Paint();
|
|
425
567
|
paint.setColor(Super.ParseColor(this.SelectionColor));
|
|
426
568
|
const end = this.cursorPosition + this.selectionLength;
|
|
569
|
+
// every selected character's own visual box: across a direction boundary the highlight can be two blocks
|
|
427
570
|
for (const b of this.Boxes())
|
|
428
|
-
if (b.Index >= this.cursorPosition && b.Index < end)
|
|
429
|
-
canvas.drawRect(CK.LTRBRect(lr.Left + b.Left, lr.Top + b.Top, lr.Left + b.Left +
|
|
571
|
+
if (b.Index >= this.cursorPosition && b.Index < end && b.Width > 0)
|
|
572
|
+
canvas.drawRect(CK.LTRBRect(lr.Left + b.Left, lr.Top + b.Top, lr.Left + b.Left + b.Width, lr.Top + b.Top + b.Height), paint);
|
|
430
573
|
paint.delete();
|
|
431
574
|
canvas.restoreToCount(saved);
|
|
432
575
|
}
|
|
@@ -468,6 +611,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
468
611
|
this.stubSelectionStop = -1;
|
|
469
612
|
this.selectionMovingEdge = -1;
|
|
470
613
|
}
|
|
614
|
+
this.cursorPlaced = true;
|
|
471
615
|
if (!this.isFocused)
|
|
472
616
|
this.IsFocused = true;
|
|
473
617
|
this.OnCursorMoved();
|
|
@@ -489,6 +633,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
489
633
|
this.SelectWord(this.HitTestIndex(p.X, p.Y));
|
|
490
634
|
this.dragSelecting = true;
|
|
491
635
|
this.selectionAnchor = this.cursorPosition;
|
|
636
|
+
this.cursorPlaced = true;
|
|
492
637
|
if (!this.isFocused)
|
|
493
638
|
this.IsFocused = true;
|
|
494
639
|
return this;
|
|
@@ -500,7 +645,17 @@ export class SkiaEditor extends SkiaShape {
|
|
|
500
645
|
}
|
|
501
646
|
return this;
|
|
502
647
|
}
|
|
503
|
-
|
|
648
|
+
/** The canvas gives or takes the focus (a tap elsewhere): an editor always takes it. */
|
|
649
|
+
SetFrameworkFocus(focus) { this.IsFocused = focus; return true; }
|
|
650
|
+
/** A text field is a Tab stop by default, like a native text box, with no Tapped handler needed. */
|
|
651
|
+
DefaultAccessibilityCanInteract() { return true; }
|
|
652
|
+
/** Keyboard navigation reached the field (Tab) or left it: take the caret and the input sink like a native text box, or release them. */
|
|
653
|
+
OnAccessibilityFocused(focused) { this.IsFocused = focused; }
|
|
654
|
+
/** Enter / Space on the field while it has no caret start editing; while editing they are text. */
|
|
655
|
+
OnAccessibilityActivated() { if (!this.IsFocused)
|
|
656
|
+
this.OnAccessibilityFocused(true); }
|
|
657
|
+
/** While editing, arrows, Home / End and PageUp / PageDown belong to the text: they never move a surrounding group. */
|
|
658
|
+
OnAccessibilityKey(_key) { return this.IsFocused; }
|
|
504
659
|
DefaultAccessibilityLabel() { return this.text || this.placeholderText || undefined; }
|
|
505
660
|
// ---- editing API (C# names) ----
|
|
506
661
|
Submit() {
|
|
@@ -517,6 +672,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
517
672
|
}
|
|
518
673
|
SelectAll() { this.SetSelection(0, this.text.length); }
|
|
519
674
|
SetSelection(start, end) {
|
|
675
|
+
this.cursorPlaced = true;
|
|
520
676
|
const s = Math.max(0, Math.min(this.text.length, Math.min(start, end))), e = Math.max(0, Math.min(this.text.length, Math.max(start, end)));
|
|
521
677
|
this.cursorPosition = s;
|
|
522
678
|
this.selectionLength = e - s;
|
|
@@ -571,15 +727,42 @@ export class SkiaEditor extends SkiaShape {
|
|
|
571
727
|
KeyboardManager.Subscribe(this.onKeyDown, this.onKeyChar);
|
|
572
728
|
KeyboardManager.BlurExternalTextInput();
|
|
573
729
|
TextInputProxy.Attach(this);
|
|
730
|
+
CanvasLeaveWatchers.add(this);
|
|
731
|
+
this.windowCanvas = this.Superview;
|
|
732
|
+
this.windowCanvas?.WindowActiveChanged?.add(this.onWindowActive);
|
|
574
733
|
}
|
|
575
734
|
else {
|
|
576
735
|
TextInputProxy.Detach(this);
|
|
577
736
|
KeyboardManager.Unsubscribe(this.onKeyDown, this.onKeyChar);
|
|
737
|
+
CanvasLeaveWatchers.delete(this);
|
|
738
|
+
this.windowCanvas?.WindowActiveChanged?.delete(this.onWindowActive);
|
|
739
|
+
this.windowCanvas = undefined;
|
|
578
740
|
}
|
|
579
741
|
}
|
|
742
|
+
// the window the editor is focused in (C# WindowActiveChanged, subscribed only while focused)
|
|
743
|
+
windowCanvas;
|
|
744
|
+
/** The window lost the keyboard: the caret hides and stops blinking (no redraws); back: it shows again in this field. */
|
|
745
|
+
onWindowActive = (active) => {
|
|
746
|
+
if (!this.isFocused)
|
|
747
|
+
return;
|
|
748
|
+
if (active)
|
|
749
|
+
this.StartBlink();
|
|
750
|
+
else {
|
|
751
|
+
this.StopBlink();
|
|
752
|
+
this.caretVisible = false;
|
|
753
|
+
}
|
|
754
|
+
this.InvalidateCache();
|
|
755
|
+
this.RepaintComposition();
|
|
756
|
+
};
|
|
757
|
+
/** Removed from the canvas while focused: the editing ends (caret timer, keys, text proxy). */
|
|
758
|
+
OnLeftCanvas() { this.IsFocused = false; }
|
|
580
759
|
OnKeyDown(key, e) {
|
|
581
760
|
const shift = KeyboardManager.IsShiftPressed, ctrl = KeyboardManager.IsControlPressed, alt = KeyboardManager.IsAltPressed;
|
|
582
761
|
const handled = () => e.preventDefault();
|
|
762
|
+
// keys of another element (a page field or button, an overlay node) and of the input method are not the editor's:
|
|
763
|
+
// a composition keeps its arrows, Escape and Backspace (C# 845b26e9, GitHub #231)
|
|
764
|
+
if (KeyboardManager.IsInputMethodKey(e) || (KeyboardManager.IsOwnedByElement(e) && !TextInputProxy.IsProxyTarget(e.target)))
|
|
765
|
+
return;
|
|
583
766
|
// with the hidden textarea focused these keys become input / clipboard events there and are applied from those
|
|
584
767
|
if (TextInputProxy.IsActive(this) && TextInputProxy.IsProxyTarget(e.target) && (key === "Backspace" || key === "Delete" || key === "Enter" || key === "NumpadEnter" || (ctrl && (key === "KeyC" || key === "KeyX" || key === "KeyV"))))
|
|
585
768
|
return;
|
|
@@ -599,11 +782,11 @@ export class SkiaEditor extends SkiaShape {
|
|
|
599
782
|
break;
|
|
600
783
|
case "ArrowLeft":
|
|
601
784
|
handled();
|
|
602
|
-
this.
|
|
785
|
+
this.MoveVisual(-1, shift);
|
|
603
786
|
break;
|
|
604
787
|
case "ArrowRight":
|
|
605
788
|
handled();
|
|
606
|
-
this.
|
|
789
|
+
this.MoveVisual(1, shift);
|
|
607
790
|
break;
|
|
608
791
|
case "ArrowUp":
|
|
609
792
|
if (this.IsMultiline) {
|
|
@@ -725,6 +908,39 @@ export class SkiaEditor extends SkiaShape {
|
|
|
725
908
|
this.selectionMovingEdge = -1;
|
|
726
909
|
this.OnCursorMoved();
|
|
727
910
|
}
|
|
911
|
+
/**
|
|
912
|
+
* Arrow Left (-1) / Right (1): visual moves, as native text fields (see VisualTarget). Without Shift a selection
|
|
913
|
+
* collapses to its visually left (Left) or right (Right) edge; with Shift its moving edge moves.
|
|
914
|
+
*/
|
|
915
|
+
MoveVisual(dir, extendSelection = false) {
|
|
916
|
+
if (!extendSelection && this.HasSelection) {
|
|
917
|
+
const a = this.cursorPosition, b = this.cursorPosition + this.selectionLength;
|
|
918
|
+
const xa = this.CaretPlace(a)?.X ?? 0, xb = this.CaretPlace(b)?.X ?? 0;
|
|
919
|
+
const to = dir < 0 ? (xa <= xb ? a : b) : (xa >= xb ? a : b);
|
|
920
|
+
this.cursorPosition = to;
|
|
921
|
+
this.selectionLength = 0;
|
|
922
|
+
this.stubSelectionStop = -1;
|
|
923
|
+
this.selectionMovingEdge = -1;
|
|
924
|
+
this.OnCursorMoved();
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
// a selection made by dragging has no moving edge yet: its end moves
|
|
928
|
+
if (extendSelection && this.HasSelection && this.selectionMovingEdge < 0) {
|
|
929
|
+
this.stubSelectionStop = this.cursorPosition;
|
|
930
|
+
this.selectionMovingEdge = this.cursorPosition + this.selectionLength;
|
|
931
|
+
}
|
|
932
|
+
const from = extendSelection && this.HasSelection ? this.selectionMovingEdge : this.cursorPosition;
|
|
933
|
+
if (extendSelection && !this.HasSelection) {
|
|
934
|
+
this.stubSelectionStop = this.cursorPosition;
|
|
935
|
+
this.selectionMovingEdge = this.cursorPosition;
|
|
936
|
+
}
|
|
937
|
+
const to = this.VisualTarget(from, dir);
|
|
938
|
+
if (extendSelection) {
|
|
939
|
+
this.StubMoveCursor(to - this.selectionMovingEdge, true);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
this.StubMoveCursor(to - this.cursorPosition, false);
|
|
943
|
+
}
|
|
728
944
|
StubSelectRange(start, length) {
|
|
729
945
|
const len = this.text.length;
|
|
730
946
|
const s = Math.max(0, Math.min(len, start)), l = Math.max(0, Math.min(len - s, length));
|
|
@@ -794,8 +1010,7 @@ export class SkiaEditor extends SkiaShape {
|
|
|
794
1010
|
return out;
|
|
795
1011
|
}
|
|
796
1012
|
OnDisposing() {
|
|
797
|
-
this.
|
|
798
|
-
this.blink.Dispose();
|
|
1013
|
+
this.StopBlink();
|
|
799
1014
|
if (SkiaEditor.Focused === this)
|
|
800
1015
|
SkiaEditor.Focused = undefined;
|
|
801
1016
|
this.SetFocusNative(false);
|
|
@@ -14,6 +14,8 @@ export declare class GifAnimation {
|
|
|
14
14
|
private positionsMs;
|
|
15
15
|
/** Negative = the last frame. */
|
|
16
16
|
SeekFrame(frame: number): void;
|
|
17
|
+
/** Start (ms) of the frame after the one at `msTime`; DurationMs after the last one. */
|
|
18
|
+
NextFrameStartMs(msTime: number): number;
|
|
17
19
|
GetFrameNumber(msTime: number): number;
|
|
18
20
|
/** Decodes every frame of an encoded GIF (CanvasKit AnimatedImage). */
|
|
19
21
|
LoadFromBytes(bytes: ArrayBuffer): void;
|
|
@@ -37,11 +39,16 @@ export declare class SkiaGif extends AnimatedFramesRenderer {
|
|
|
37
39
|
set Source(v: string);
|
|
38
40
|
Start(delayMs?: number): void;
|
|
39
41
|
protected OnAnimatorUpdated(value: number): void;
|
|
42
|
+
protected NextChangeMs(value: number): number | undefined;
|
|
40
43
|
/** Seeks by time in ms (the animator range is 0..DurationMs). */
|
|
41
44
|
protected OnAnimatorSeeking(time: number): void;
|
|
42
45
|
protected OnAnimatorInitializing(): void;
|
|
43
46
|
protected ApplySpeed(): void;
|
|
44
47
|
protected CheckCanStartAnimator(): boolean;
|
|
48
|
+
/** Shows a frame by index, negative = last frame (C# ShowFrame). */
|
|
49
|
+
protected ShowFrame(frame: number): void;
|
|
50
|
+
/** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
|
|
51
|
+
protected ApplyDefaultFrame(): void;
|
|
45
52
|
SetAnimation(animation: GifAnimation, disposePrevious: boolean): void;
|
|
46
53
|
ReloadSource(): void;
|
|
47
54
|
/** Loads (does not apply) a GIF; C# LoadSource. */
|
package/dist/controls/SkiaGif.js
CHANGED
|
@@ -21,6 +21,13 @@ export class GifAnimation {
|
|
|
21
21
|
if (frame >= 0 && frame <= this.TotalFrames - 1)
|
|
22
22
|
this.Frame = this.Frames[frame];
|
|
23
23
|
}
|
|
24
|
+
/** Start (ms) of the frame after the one at `msTime`; DurationMs after the last one. */
|
|
25
|
+
NextFrameStartMs(msTime) {
|
|
26
|
+
for (let i = 0; i < this.positionsMs.length; i++)
|
|
27
|
+
if (msTime < this.positionsMs[i])
|
|
28
|
+
return this.positionsMs[i];
|
|
29
|
+
return this.DurationMs;
|
|
30
|
+
}
|
|
24
31
|
GetFrameNumber(msTime) {
|
|
25
32
|
if (this.positionsMs.length === 0 || this.DurationMs <= 0)
|
|
26
33
|
return 0;
|
|
@@ -87,7 +94,9 @@ export class SkiaGif extends AnimatedFramesRenderer {
|
|
|
87
94
|
loadGeneration = 0;
|
|
88
95
|
constructor() {
|
|
89
96
|
super();
|
|
90
|
-
|
|
97
|
+
// C# ImageDoubleBuffered pays off where a thread bakes the bitmap; on the web it is one offscreen pass per frame
|
|
98
|
+
// change, so the web engines draw a GIF frame with no cache (drawnui-cross rule 3)
|
|
99
|
+
this.UseCache = "None";
|
|
91
100
|
}
|
|
92
101
|
get Source() { return this.source; }
|
|
93
102
|
set Source(v) { if (this.source !== v) {
|
|
@@ -97,6 +106,7 @@ export class SkiaGif extends AnimatedFramesRenderer {
|
|
|
97
106
|
Start(delayMs = 0) { if ((this.Animation?.TotalFrames ?? 0) > 0)
|
|
98
107
|
super.Start(delayMs); }
|
|
99
108
|
OnAnimatorUpdated(value) { this.Seek(value); }
|
|
109
|
+
NextChangeMs(value) { return this.Animation && this.Animation.DurationMs > 0 ? this.Animation.NextFrameStartMs(value) : undefined; }
|
|
100
110
|
/** Seeks by time in ms (the animator range is 0..DurationMs). */
|
|
101
111
|
OnAnimatorSeeking(time) {
|
|
102
112
|
const a = this.Animation;
|
|
@@ -121,9 +131,20 @@ export class SkiaGif extends AnimatedFramesRenderer {
|
|
|
121
131
|
if (!this.Animation || !this.Animator)
|
|
122
132
|
return;
|
|
123
133
|
const d = this.Animation.DurationMs;
|
|
124
|
-
this.Animator.Speed = this.
|
|
134
|
+
this.Animator.Speed = this.GetPlaybackDurationMs(d);
|
|
125
135
|
}
|
|
126
136
|
CheckCanStartAnimator() { return (this.Animation?.TotalFrames ?? 0) > 0; }
|
|
137
|
+
/** Shows a frame by index, negative = last frame (C# ShowFrame). */
|
|
138
|
+
ShowFrame(frame) {
|
|
139
|
+
if (!this.Animation)
|
|
140
|
+
return;
|
|
141
|
+
this.Animation.SeekFrame(frame);
|
|
142
|
+
this.InvalidateCache();
|
|
143
|
+
this.RepaintComposition();
|
|
144
|
+
}
|
|
145
|
+
/** Shows DefaultFrame (a frame index, -1 = last) when not playing. */
|
|
146
|
+
ApplyDefaultFrame() { if (!this.IsPlaying && this.Animation)
|
|
147
|
+
this.ShowFrame(this.DefaultFrame); }
|
|
127
148
|
SetAnimation(animation, disposePrevious) {
|
|
128
149
|
if (!animation || animation === this.Animation)
|
|
129
150
|
return;
|
|
@@ -133,7 +154,7 @@ export class SkiaGif extends AnimatedFramesRenderer {
|
|
|
133
154
|
this.Stop();
|
|
134
155
|
this.Animation = animation;
|
|
135
156
|
this.InitializeAnimator();
|
|
136
|
-
this.
|
|
157
|
+
this.ShowFrame(this.DefaultFrame);
|
|
137
158
|
if (wasPlaying && !this.IsPlaying)
|
|
138
159
|
this.Start();
|
|
139
160
|
if (kill && disposePrevious)
|
|
@@ -158,7 +179,7 @@ export class SkiaGif extends AnimatedFramesRenderer {
|
|
|
158
179
|
async LoadSource(source) {
|
|
159
180
|
if (!source)
|
|
160
181
|
return undefined;
|
|
161
|
-
const r = await fetch(source);
|
|
182
|
+
const r = await fetch(Super.ResolveAssetUrl(source));
|
|
162
183
|
if (!r.ok)
|
|
163
184
|
throw new Error(`${r.status} ${source}`);
|
|
164
185
|
const animation = new GifAnimation();
|
|
@@ -72,4 +72,9 @@ export declare class SkiaImage extends SkiaControl {
|
|
|
72
72
|
*/
|
|
73
73
|
protected MeasureAbsolute(widthConstraint: number, heightConstraint: number, scale: number): ScaledSize;
|
|
74
74
|
protected Paint(ctx: DrawingContext): void;
|
|
75
|
+
private tileShader?;
|
|
76
|
+
private tileShaderKey?;
|
|
77
|
+
/** Repeat shader of the image placed at `display`, kept until the image or its placement changes (C# cached fill shader). */
|
|
78
|
+
private TileShader;
|
|
79
|
+
protected OnDisposing(): void;
|
|
75
80
|
}
|