drawnui-react 0.1.0-preview.41 → 0.1.0-preview.42
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 +47 -0
- package/SKIPPED.md +2 -2
- package/dist/controls/SkiaEditor.js +5 -4
- package/dist/controls/SkiaImage.d.ts +5 -0
- package/dist/controls/SkiaImage.js +32 -5
- package/dist/controls/SkiaLabel.d.ts +17 -2
- package/dist/controls/SkiaLabel.js +38 -12
- package/dist/controls/SkiaLabelFps.d.ts +0 -3
- package/dist/controls/SkiaLabelFps.js +1 -11
- package/dist/controls/SkiaLayout.js +33 -2
- package/dist/controls/SkiaScroll.d.ts +17 -0
- package/dist/controls/SkiaScroll.js +51 -6
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSprite.js +5 -1
- package/dist/core/Accessibility.d.ts +12 -0
- package/dist/core/Accessibility.js +62 -14
- package/dist/core/Canvas.d.ts +31 -8
- package/dist/core/Canvas.js +85 -18
- package/dist/core/Gestures.d.ts +1 -0
- package/dist/core/Props.d.ts +11 -0
- package/dist/core/Props.js +44 -0
- package/dist/core/SkiaControl.d.ts +21 -2
- package/dist/core/SkiaControl.js +55 -11
- package/dist/core/SkiaEffect.d.ts +12 -1
- package/dist/core/SkiaEffect.js +35 -8
- package/dist/core/SkiaImageManager.d.ts +100 -18
- package/dist/core/SkiaImageManager.js +309 -64
- package/dist/core/Styles.js +7 -1
- package/dist/core/Super.d.ts +2 -0
- package/dist/core/Super.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -514
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +8 -4
- package/dist/react/reconciler.d.ts +12 -0
- package/dist/react/reconciler.js +22 -46
- package/package.json +19 -2
package/README.md
CHANGED
|
@@ -49,6 +49,53 @@ property names, layout and drawing rules. What you learn here works there, and s
|
|
|
49
49
|
|
|
50
50
|
DrawnUI is MIT licensed in every language and on every platform: desktop, mobile, web and embedded devices. Ship it in commercial products with no attribution badge, no about screen and no per-device royalty.
|
|
51
51
|
|
|
52
|
+
## What's new in 0.1.0-preview.42
|
|
53
|
+
|
|
54
|
+
- **Images:** images that show the same file or URL share one decoded copy; image memory stays within a budget
|
|
55
|
+
(`SkiaImageManager.CacheBudgetMb`, 128 MB by default), and the images no control shows go first. Cached images
|
|
56
|
+
refresh after 30 minutes or on `RemoveFromCache`, and an image stays on screen as long as a control shows it. The
|
|
57
|
+
image manager follows DrawnUi.Net: `ReuseBitmaps`, `UseCache`, retries of failed loads, `RegisterImage`,
|
|
58
|
+
`IsLoadingLocked`; `LoadImageAsync` is a direct load outside the cache.
|
|
59
|
+
- **Controls on a new canvas:** a control shown on a new canvas redraws its GPU and image caches there.
|
|
60
|
+
- **Changes during a cache recording:** a control that changes while a cached parent records it (shown from another
|
|
61
|
+
control's paint, or from an event raised as it draws) is drawn on the next frame.
|
|
62
|
+
- **Parent-independent controls:** a control marked `IsParentIndependent` lays itself out again in its own slot when its
|
|
63
|
+
content changes, so a live counter in a row shows every new value without laying out the row.
|
|
64
|
+
- **`End` in stacks:** a child with `End` in a row or column sits at the stack's end, as in DrawnUI for Rust (a button
|
|
65
|
+
after a text in a full-width row lines up on the right).
|
|
66
|
+
- **Zoom wheels:** `TouchActionEventArgs.Wheel.IsZoom` tells a Ctrl / Cmd + wheel or a touchpad pinch from a plain wheel.
|
|
67
|
+
- **Add-on packages:** `Registry` and `DrawnProps` let a separate package register its own JSX tags.
|
|
68
|
+
- **`SkiaShell` without React:** the shell is an engine control in `drawnui-react/core`: build it in code with
|
|
69
|
+
controls as pages, popups, modals and toasts. The JSX `<SkiaShell>` works as before on top of it.
|
|
70
|
+
- **Quiet console:** WebGL starts and comes back after a lost context without browser warnings, in Chromium and WebKit.
|
|
71
|
+
- **Dialogs for keyboard and screen readers:** an open dialog reads as one named dialog, the keyboard goes into it
|
|
72
|
+
(also when its buttons show a moment later) and comes back to the control that opened it when it closes, also
|
|
73
|
+
after one dialog hands over to another.
|
|
74
|
+
- **`Super.OpenLink` and `UpdateNonStop()`:** open an address in a new tab, and keep a self-animating control (a
|
|
75
|
+
time-driven shader, a clock) drawing every frame while it is shown, as in DrawnUi .NET.
|
|
76
|
+
- **Layout rules as in DrawnUI for .NET and Rust:** a Fill control with a size request keeps the requested size; a
|
|
77
|
+
layer without a size of its own fits its sized children, and an empty Fill background takes that size; Center with
|
|
78
|
+
unequal margins moves by the full margin difference.
|
|
79
|
+
- **Shader time:** `iTime` counts from the first shader frame, shared by every effect, so animated shaders stay smooth
|
|
80
|
+
however long the page has been open.
|
|
81
|
+
- **Screen readers and opacity:** a control faded to opacity 0 is left out of the screen-reader tree, like a hidden one,
|
|
82
|
+
and is read again when it shows.
|
|
83
|
+
- **Styles with code-behind:** a control built in code keeps every property the code set; a registered style fills in
|
|
84
|
+
only the rest.
|
|
85
|
+
- **Nested scrolls:** a drag that starts on an inner list already at its end scrolls the page around it, so a page full
|
|
86
|
+
of lists drags all the way to its end. The mouse wheel works the same way, as in browsers: one spin stays on the list
|
|
87
|
+
it started on, the next one moves the page.
|
|
88
|
+
- **Paragraph spacing:** text with line breaks gets a quarter line between paragraphs by default (`ParagraphSpacing`
|
|
89
|
+
0.25), as in DrawnUi .NET, and a growing editor (`AutoHeight`) fits each of its lines at its own height.
|
|
90
|
+
- **Line spacing from the font:** fonts with built-in leading keep it between lines (times `LineSpacing`), and
|
|
91
|
+
`LineHeightUniform` gives every line of a label the tallest line's height.
|
|
92
|
+
- **Text placed as in DrawnUi .NET:** label lines are whole pixels high and text sits on the same baseline as in
|
|
93
|
+
DrawnUi .NET; with `LineHeight` the extra space is shared above and below the text.
|
|
94
|
+
- **Sharp at any display scale:** the canvas matches the screen's device pixels exactly at fractional display scales,
|
|
95
|
+
so text and lines stay crisp.
|
|
96
|
+
- **Moving inside a composite cache:** a control moved by its translation inside an `ImageComposite` layer draws at its
|
|
97
|
+
new place right away.
|
|
98
|
+
|
|
52
99
|
## What's new in 0.1.0-preview.41
|
|
53
100
|
|
|
54
101
|
- **System light and dark:** `Canvas.SystemTheme` and `SystemThemeChanged` report the browser's light or dark appearance
|
package/SKIPPED.md
CHANGED
|
@@ -30,7 +30,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
|
|
|
30
30
|
| `HorizontalFillRatio`/`VerticalFillRatio` | ported | Applied at arrange like C# `DefineAvailableSize` (the Fill box is scaled, alignment stays inside the full box); measure is not affected (C# passes `useModifiers=false` there too). |
|
|
31
31
|
| `ZIndex` | ported | Static children of a layout are drawn in ZIndex order (stable for equal values), gestures go to the top-most first; the sorted list is cached until a child or a ZIndex changes (C# `GetOrderedSubviews`). Templated cells keep index order. |
|
|
32
32
|
| `FillGradient`, `SkiaShape.StrokeGradient` | ported | `SkiaGradient` as a plain object: `Type` Linear (Start/End ratios or CSS `Angle`), Circular / Conical (radius = half the smaller side), Oval (radial scaled to the box), Sweep (around the center, `Value1`/`Value2` angles), `ColorPositions`, `TileMode`, `Light` (< 1 darker: red, green and blue × `Light`, as C# `MakeDarker`; > 1 lighter: HSL lightness × `Light`, clamped, hue and saturation kept, as .NET MAUI `AddLuminosity` and C# f77136c4), `Opacity`, `BlendMode`; C# `SetupGradient` paint setup (white base); shaders cached per gradient object and rect (C# `Version` cache: a new React literal replaces the old shaders). On a `SkiaLabel` it goes to one place (C# 9637994b): the background when the label has a `BackgroundColor` (its text keeps `TextColor`), else the glyphs. `SkiaLabel.FillGradient` paints the glyphs (`GradientByLines` default true = per line bounds, false = the text block) and the background only when `BackgroundColor` is set, like the C# label override. `SkiaLabel` text stroke (`StrokeColor`, `StrokeWidth` points, `StrokeGradient`) and drop shadow (`DropShadowColor`, `DropShadowSize`, `DropShadowOffsetX/Y`) in the C# order shadow → stroke → fill, measurement inflated by stroke × 2 and shadow size + offset like C#. Not ported: `Background` MAUI brushes, `FillBlendMode`. |
|
|
33
|
-
| `SkiaShell` | partial (React
|
|
33
|
+
| `SkiaShell` | partial | An engine control in `drawnui-react/core` (`new SkiaShell()`, `Routes` / `RootContent` / popups / modals / toasts take controls or factories, usable without React); the JSX `<SkiaShell>` is a thin wrapper over it that renders JSX content through portals. `Routes` (route -> JSX page factory), `GoToAsync(route, animated)` / `GoBackAsync(animated)` / `PopToRootAsync` with the SkiaViewSwitcher slide (`PagesAnimationSpeed` 200 ms, pushed pages opaque over the page below, lower pages hidden when idle), `NavigationStack`, `CanGoBack`, `Route`, nav bar with Back + title, `useShell()`; `OpenPopupAsync(content, { animated, closeWhenBackgroundTapped, showOverlay, backgroundColor })` (C# PopupWrapper: dimmed backdrop, scale 0.5→1 + fade over `PopupsAnimationSpeed`, tap outside the content closes), `ClosePopupAsync`, `CloseAllPopups`; `PushModalAsync(content, { useGestures, animated, freezeBackground })` (C# ModalWrapper: full-screen `SkiaDrawer` FromBottom HeaderSize 0, drag-to-close with `useGestures`), `PopModalAsync`; `ShowToast(text | content, ms)` (C# layout: bottom banner, slide + fade 300/250 ms, `ShellDefaults.Toast*`), `CloseAllToasts`; `PopupsCount`/`ModalsCount`/`ToastsCount`; `ShellDefaults` = the C# statics (`PopupBackgroundColor`, `PopupsBackgroundBlur`, `PopupsAnimationSpeed`, `PopupsCancelAnimationsAfterMs`, `ZIndex*`, `Toast*`, tab colors); popups/modals sit on a `SkiaBackdrop` (blur + tint); `Tabs` (C# SkiaViewSwitcher tabs: bottom tab bar, per-tab page stacks, `SelectedTab`, `SelectTabAsync`, `PopTabToRootAsync`); `GoBackAsync` follows C# `GoBackDefault` (top popup, then modal, then page); React extension `UseBrowserHistory` (default true): pages in the URL hash `#/a/b`, one history entry per page / popup / modal, browser Back unwinds in the same order, deep links restore the page stack. Not ported: `NavigationLayout` view switcher, frozen-screenshot backgrounds, `pixelsScaleInFrom`, `RegisterRoute` by type, `IHandleGoBack`, `PushAsync(page instance)`; `AnimateTabs` + `TabsAnimationSpeed` (150) ported with the C# SelectLeftTab/SelectRightTab slide (0.75 width, fade, back-ease 0.55) — only the tab roots animate, pages pushed inside the leaving tab drop instantly. Browser history: a `popstate` at the same depth with another hash (a plain `<a href="#/route">` link, a typed hash) rebuilds the stack like a forward navigation. |
|
|
34
34
|
| Styles / `ConfigureStyles` | ported | `Super.UseDrawnUi().ConfigureStyles(styles => styles.AddStyle({ TargetType, ApplyToDerivedTypes, Setters }))`, the C# `Style` shape with the `Setter` list written as a plain object (`Setters: { FontFamily: "FontText" }`) because controls hold plain properties instead of BindableProperty. Per-class resolution cached, base-type styles applied furthest-first so the nearest wins, exact type last (C# `ResolveStylesForType`). Applied by the reconciler between `new` and the JSX props, so props override; a control built in code-behind is styled on its first `Measure` and keeps values that differ from its class defaults (the React stand-in for C# `ExplicitPropertiesSet`, which needs BindableProperty). Not ported: `BasedOn`, `Class`, `Triggers`, `Behaviors`, the per-control `Style` property, `ConditionalStyle`. |
|
|
35
35
|
| Animators core: `AnimatorBase` / `SkiaValueAnimator` / `RenderingAnimator` (`IOverlayEffect`), `Canvas.RegisterAnimator`/`AnimatingControls`, `PostAnimators` + `ExecutePostAnimators`, `Easing` (Linear/Cubic*) | ported | Frame-driven: a running animator keeps frames coming, idle canvas draws nothing. An animator started before its control is attached waits in `PendingUnattachedAnimators` and starts on the control's first arrange (C# starts it in `SuperViewChanged`). Frame time = the frame's vsync timestamp, see PARITY "Animators run on vsync time". |
|
|
36
36
|
| `ActionOnTickAnimator` | ported | Runs an action with the frame time on every frame until stopped. |
|
|
@@ -79,7 +79,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
|
|
|
79
79
|
| `SkiaHotspot` | ported | Fill/Fill, `Tapped`, `Down`, `Up`, `LockPanning`, `TouchDown`; consumes only Tapped like the C# one. No `AnimationTapped`/ripple/shimmer. |
|
|
80
80
|
| `SkiaButton` | partial | Default look only: rounded frame radius 8 (hardcoded like the C# default content), centered label, `Text`/`TextColor`/`FontSize`/`FontFamily`/`BackgroundColor`/`IsPressed`/`RespondsToGestures` (`IsDisabled` = its obsolete opposite)/`LockPanning`, `Tapped`/`Down`/`Up`. `RespondsToGestures = false`: no press, no `Tapped`/`Down`/`Up`, a press or tap on it stops there, keyboard skips it, reported disabled (drawnui-cross 6w). `IsPressed` is tracked but has no visual; press feedback = `ApplyEffect="Ripple"`. No `ButtonStyle` platform looks, icons, `TextCase`, elevation, shimmer, `BtnText`/`BtnShape` templating. |
|
|
81
81
|
| `SkiaImage` | partial | Effects ported: `AddEffect` (BlackAndWhite, Grayscale (the 0.21 / 0.72 / 0.07 weights, as C# Grayscale2), Pastel, Sepia, InvertColors, Tint + `ColorTint`/`EffectBlendMode`, Darken, Lighten, Contrast, Saturation, Brightness, TSL, Gamma ≈ linear fit — CanvasKit has no table color filter), `Blur` (image filter, mirror tile), `ZoomX/ZoomY`, `HorizontalOffset/VerticalOffset`; C# color matrices use 0..255 translations, CanvasKit 0..1 — converted. `HSL` (hue from `Gamma`, `Saturation`, `Brightness`, tint blend), `Custom` = your own `PaintColorFilter` (C# public fields `PaintColorFilter` / `PaintImageFilter`, the latter replaces `Blur`), `ImageBitmap` (decoded image shared, not owned), `LoadPriority` of the queued `Source` load. Not ported: `UseGradient`/`StartColor`/`EndColor`, sprites, `InflateAmount`, `EraseChangedContent`, `RescaleSource`/`RescalingQuality`. `Source` (URL), `Aspect` (all `TransformAspect` values; `Tile` repeats the image at its natural size from the aligned copy, as C#, same `RescaleAspect` math), `HorizontalAlignment`/`VerticalAlignment`, `Success`/`Error`, `IsLoading`, `LoadedSource`, `DisplayRect`, `AspectScale`; overflow clipped to the box. Not ported: `LoadSourceOnFirstDraw`, `PreviewBase64`, `ImageBitmap`/`LoadedImageSource`, `RescaleSource`/`CacheRescaledSource`/`RescalingQuality`, all adjustments (`Brightness`…`Blur`, `ColorTint`, gradient, `Zoom*`, offsets), sprites, `DrawWhenEmpty`, `EraseChangedContent`, `UseAssembly`. Measure: bounded box taken as is, unbounded axis from source aspect; no `NeedAutoWidth/Height` from Start alignment. |
|
|
82
|
-
| `SkiaImageManager` |
|
|
82
|
+
| `SkiaImageManager` | ported | As DrawnUi.Net: `LoadImageManagedAsync(url, signal, priority)` caches and goes through the priority queue (High > Normal > Low, `MaxParallelLoads` 5 in flight, one fetch per source serves every requester); `LoadImageAsync(url, signal)` is a direct load outside the cache whose image the caller owns; `ReuseBitmaps` (on: every control on a source shares one decoded image; off: the cache keeps one copy and each caller gets a copy of its own, `GetFromCache` too); `CacheLongevitySecs` (1800) expiry; `CacheBudgetMb` (128, 0 = no limit) of decoded pixels, over it the images no control holds go, used longest ago first (DrawnUI for Rust trim), `Instance.CacheMemoryMb`, `Trim()`; `RemoveFromCache` / `ClearCache` / `AddToCache` / `UpdateInCache` / `GetFromCache` / `GetFromCacheInternal` never delete an image a control holds (`Hold` / `Free`, used by SkiaImage, SkiaSprite and shader-effect textures); keys case-insensitive, local paths normalized; `UseCache`; `EnableHttpRetry` (`HttpRetryMaxAttempts` 3); a failed load resolves to `undefined` and raises `CanReload(source, error)`; `RegisterImage`, `IsLoadingLocked`, `HttpBaseAddress`, `IsOffline`; `PreloadImage(s)`, `CancelAll` (only loads waiting for a slot). React divergence: a cancelled load resolves to `undefined` (C# throws). |
|
|
83
83
|
| `SkiaImageTiles` | ported | `TileWidth` / `TileHeight` (points, nothing drawn until set), `TileAspect` (AspectCover), `TileOffsetX` / `TileOffsetY` (wrap), `TileCacheType` (Image) for the inner tile `SkiaImage` sharing the decoded source, clipped to bounds. |
|
|
84
84
|
| `SkiaSvg` | partial | Inline `SvgString` without `xmlns` gets it injected (browsers refuse to decode an `<img>` SVG without it, SkiaSharp does not care) — the C# check-mark markup relies on that. `Source` (URL) / `SvgString`, `Aspect` (default `AspectFitFill`, uses the shared `RescaleAspect` math, not SkiaSvg's own matrix path; `Tile` repeats the picture at its natural size, one SVG unit per point, from the aligned copy), alignments, `TintColor` (SrcIn), `Success`/`Error`, `IsLoading`, `DisplayRect`. Rendering: browser decodes the SVG, rasterized at the displayed pixel size and cached per size (CanvasKit npm has no SVG module). Not ported: shadows, FontAwesome duotone colors, `FillGradient`, `Zoom*`/offsets/`InflateAmount`, `IconFilePath`/embedded resources, `UseCache=Operations` default (no caching yet). |
|
|
85
85
|
| `SkiaScroll` | partial | Own size as C#: a side without a request that is not `Fill` takes the content's size, up to the space given. `Orientation` Vertical/Horizontal/Both/Neither (Neither: pans never move the viewport, the wheel is not consumed so a parent scroll may take it; programmatic `ScrollTo` still works), single `Content`, `ViewportOffsetX/Y` (points, <= 0), pan with the C# 0.85 delta interpolation, fling on the DrawnUi deceleration curve (`FrictionScrolled`, `ChangeVelocityScrolled`, `MaxVelocity`, edge-cut duration), rubber-band overscroll (`Bounces`, `RubberEffect`) + spring bounce (`RubberDamping`, `MaxBounceVelocity`), mouse wheel (`WheelLineSize` per notch, an event moving by its share of a notch: `Canvas.WheelDeltaPerNotch` 100 CSS px after `deltaMode` lines x 40 / pages x 800, dominant axis, as the C# browser heads; `AutoScrollingSpeedMs` glide for a notch, an event under half a notch moves at once (touchpads, see PARITY); events accumulate onto the running move's exact target, and a restarted glide starts at the event so a fast swipe moves on every frame; `Wheel.IsHorizontal`: a vertical scroll leaves horizontal events, a horizontal scroll takes both, C# ba03cb20), `ScrollTo`/`ScrollToTop`/`ScrollToBottom`/`StopScrolling`, `Scrolled`, `IgnoreWrongDirection`, `RespondsToGestures`, `IsUserPanning`/`IsScrolling`, `ContentSize`, `ContentOffsetBounds`, `OverScrolled`. `Header` / `Footer` (JSX children with `Tag="Header"` / `Tag="Footer"`; the header scrolls in the flow, `HeaderSticky` pins it at the viewport start drawn over the content, `HeaderBehind` draws it under the content, `HeaderParallaxRatio` (1 = with the content, 0.5 = half speed), `ParallaxOverscrollEnabled`, `ContentOffset` between a behind / sticky header and the content; both add to the scroll extent), scroll bars (`ScrollBarsVisibility` None / Vertical / Horizontal / Both creating default `SkiaScrollBar`s, `ScrollBar` / `ScrollBarHorizontal` custom `IScrollBar` controls via `Tag="ScrollBar"` / `"ScrollBarHorizontal"`, `ScrollBarThumbColor` / `ScrollBarTrackColor`; `SkiaScrollBar`: `Dock`, `ThumbColor`, `TrackColor`, `Thickness` 4, `EdgeMargin` 2, `MinThumbSize` 32, `AutoHide` + `HideDelaySecs` 1 + `HideDurationSecs` 0.25, thumb squashed on overscroll, `IsDraggable` + `GrabPadding` 8: the scroll takes a gesture that starts on the bar from down to up, thumb drag keeps the grab point, a track press jumps the thumb under the pointer, the content gets neither the pan nor the tap; a custom `IScrollBar` opts in by implementing `IsDraggable` / `BeginDrag` / `GetDragProgress`; bars are parent-independent (C# `IsParentIndependent`): a thumb resize invalidates the bar alone and the scroll re-measures it on draw, nothing above re-measures), pull to refresh (`RefreshEnabled`, `RefreshCommand` callback, `IsRefreshing` two-way, `RefreshDistanceLimit` 150, `RefreshShowDistance` 50, `RefreshIndicator` `IRefreshIndicator` control via `Tag="RefreshIndicator"`; `RefreshIndicator` base: `Orientation`, `SetDragRatio` slides the view in with the pull and parks it at RefreshShowDistance, `IsRunning` + `OnIsRunningChanged`, `VisibleRatio`), `SnapToChildren` Center / Side after a fling or a release (`Snap`, `CheckNeedToSnap`), `TrackIndexPosition` Start / Center / End + `TrackIndexPositionOffset` reporting `CurrentIndex` / `CurrentIndexChanged`. `ScrollToIndex` Start / Center / End as an open order (C# OrderedScrollToIndex): a row not measured yet is gone to by the estimate and aimed again every frame until its place is measured and the viewport stands on it; a press, the wheel or another scroll drops it; LoadMore waits while it is open. Controls outside the clip are skipped with their subtree (C# stack Virtualisation, for every control; see PARITY). Not ported: zoom (`ViewportZoom`, `ZoomLocked`), `ReverseGestures` (inverted chat), keyboard adaptation, `ResetScrollPositionOnContentSizeChanged`, `ScrollType`, `ScrollingEnded` event, `LottieRefreshIndicator`, virtualization hooks (`Virtualisation`, `UseVirtual`, windowed content bounds); the C# refresh-indicator position curve is replaced by a linear slide-in. |
|
|
@@ -358,12 +358,13 @@ export class SkiaEditor extends SkiaShape {
|
|
|
358
358
|
if (this.placeholder.IsVisible)
|
|
359
359
|
this.placeholder.Measure(innerW, Infinity, scale);
|
|
360
360
|
const lineH = this.Label.MeasuredLineHeight || this.placeholder.MeasuredLineHeight || this.GetSingleLineHeightPts() * scale;
|
|
361
|
-
let
|
|
361
|
+
let contentH = lineH * (this.maxLines > 0 ? this.maxLines : 1);
|
|
362
362
|
if (this.AutoHeight && this.IsMultiline) {
|
|
363
|
-
|
|
364
|
-
|
|
363
|
+
// the visible lines as the label lays them out: each its own height, with line and paragraph spacing between
|
|
364
|
+
const boxes = this.Label.GetLineBoxes();
|
|
365
|
+
const k = this.maxLines > 0 ? Math.min(boxes.length, this.maxLines) : boxes.length;
|
|
366
|
+
contentH = k > 0 ? boxes[k - 1].Top + boxes[k - 1].Height - boxes[0].Top : lineH;
|
|
365
367
|
}
|
|
366
|
-
const contentH = lineH * lines;
|
|
367
368
|
const width = isFinite(w) ? w : labelSize.Pixels.Width + px;
|
|
368
369
|
return ScaledSize.FromPixels(width, Math.ceil(contentH) + py, scale);
|
|
369
370
|
}
|
|
@@ -44,6 +44,11 @@ export declare class SkiaImage extends SkiaControl {
|
|
|
44
44
|
/** C# ImageBitmap: show an already decoded image (shared, not owned) instead of loading a Source. */
|
|
45
45
|
get ImageBitmap(): Image | undefined;
|
|
46
46
|
set ImageBitmap(image: Image | undefined);
|
|
47
|
+
/**
|
|
48
|
+
* Shows an image: the control holds it while it draws it (the image manager never deletes an image a control holds,
|
|
49
|
+
* and deletes a copy of its own once the control lets it go: SkiaImageManager.Hold / Free).
|
|
50
|
+
*/
|
|
51
|
+
private Show;
|
|
47
52
|
IsLoading: boolean;
|
|
48
53
|
/** Where the scaled image was drawn last frame, canvas pixels. */
|
|
49
54
|
DisplayRect: SKRect;
|
|
@@ -69,9 +69,21 @@ export class SkiaImage extends SkiaControl {
|
|
|
69
69
|
return;
|
|
70
70
|
this.loadGeneration++;
|
|
71
71
|
this.IsLoading = false;
|
|
72
|
-
this.
|
|
72
|
+
this.Show(image);
|
|
73
73
|
this.Update();
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Shows an image: the control holds it while it draws it (the image manager never deletes an image a control holds,
|
|
77
|
+
* and deletes a copy of its own once the control lets it go: SkiaImageManager.Hold / Free).
|
|
78
|
+
*/
|
|
79
|
+
Show(image) {
|
|
80
|
+
if (this.LoadedSource === image)
|
|
81
|
+
return;
|
|
82
|
+
const old = this.LoadedSource;
|
|
83
|
+
this.LoadedSource = image;
|
|
84
|
+
SkiaImageManager.Instance.Hold(image);
|
|
85
|
+
SkiaImageManager.Instance.Free(old);
|
|
86
|
+
}
|
|
75
87
|
IsLoading = false;
|
|
76
88
|
/** Where the scaled image was drawn last frame, canvas pixels. */
|
|
77
89
|
DisplayRect = SKRect.Empty;
|
|
@@ -88,16 +100,29 @@ export class SkiaImage extends SkiaControl {
|
|
|
88
100
|
return;
|
|
89
101
|
this.source = value;
|
|
90
102
|
const generation = ++this.loadGeneration;
|
|
91
|
-
this.
|
|
103
|
+
this.Show(undefined);
|
|
92
104
|
if (!value) {
|
|
93
105
|
this.IsLoading = false;
|
|
94
106
|
this.Update();
|
|
95
107
|
return;
|
|
96
108
|
}
|
|
97
109
|
this.IsLoading = true;
|
|
98
|
-
SkiaImageManager.Instance.LoadImageManagedAsync(value, undefined, this.LoadPriority).then((image) => {
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
SkiaImageManager.Instance.LoadImageManagedAsync(value, undefined, this.LoadPriority).then((image) => {
|
|
111
|
+
if (generation !== this.loadGeneration || this.IsDisposed) {
|
|
112
|
+
// a load nobody shows: a copy of its own goes at once, a shared image stays in the cache
|
|
113
|
+
SkiaImageManager.Instance.Hold(image);
|
|
114
|
+
SkiaImageManager.Instance.Free(image);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.IsLoading = false;
|
|
118
|
+
if (!image) {
|
|
119
|
+
this.Error?.(this, new Error(`DrawnUi: cannot load image '${value}'`));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
this.Show(image);
|
|
123
|
+
this.Update();
|
|
124
|
+
this.Success?.(this, value);
|
|
125
|
+
});
|
|
101
126
|
}
|
|
102
127
|
/** Port of DrawnUi SkiaControl.RescaleAspect: per-axis scale to apply to (width, height) inside dest. */
|
|
103
128
|
static RescaleAspect(width, height, dest, stretch) {
|
|
@@ -251,6 +276,8 @@ export class SkiaImage extends SkiaControl {
|
|
|
251
276
|
this.tileShader?.delete();
|
|
252
277
|
this.tileShader = undefined;
|
|
253
278
|
this.tileShaderKey = undefined;
|
|
279
|
+
this.loadGeneration++;
|
|
280
|
+
this.Show(undefined);
|
|
254
281
|
super.OnDisposing();
|
|
255
282
|
}
|
|
256
283
|
}
|
|
@@ -45,6 +45,9 @@ export declare class SkiaLabel extends SkiaControl {
|
|
|
45
45
|
private lineSpacing;
|
|
46
46
|
private lineHeight;
|
|
47
47
|
private paragraphSpacing;
|
|
48
|
+
private lineHeightUniform;
|
|
49
|
+
/** The height every line takes under LineHeightUniform: the tallest laid-out line's (C# MeasuredLineHeight). */
|
|
50
|
+
private uniformLineHeight;
|
|
48
51
|
private characterSpacing;
|
|
49
52
|
private textTransform;
|
|
50
53
|
private padding;
|
|
@@ -90,11 +93,14 @@ export declare class SkiaLabel extends SkiaControl {
|
|
|
90
93
|
get LineHeight(): number;
|
|
91
94
|
set LineHeight(v: number);
|
|
92
95
|
/**
|
|
93
|
-
* Space above every paragraph after the first, in lines (C# ParagraphSpacing
|
|
96
|
+
* Space above every paragraph after the first, in lines of the label's font (C# ParagraphSpacing, default 0.25). A
|
|
94
97
|
* paragraph starts after "\n"; U+2028 breaks the line inside a paragraph.
|
|
95
98
|
*/
|
|
96
99
|
get ParagraphSpacing(): number;
|
|
97
100
|
set ParagraphSpacing(v: number);
|
|
101
|
+
/** LineHeightUniform: true = every line as tall as the tallest one; false (default in every engine) = each line its own height. */
|
|
102
|
+
get LineHeightUniform(): boolean;
|
|
103
|
+
set LineHeightUniform(v: boolean);
|
|
98
104
|
/**
|
|
99
105
|
* C# CharacterSpacing: 1 = the font's own spacing; every glyph is followed by (CharacterSpacing - 1) points more
|
|
100
106
|
* (less below 1), the line measures and wraps at the width it draws (C# 7cf1007c, DrawnUi.Rust label).
|
|
@@ -202,8 +208,17 @@ export declare class SkiaLabel extends SkiaControl {
|
|
|
202
208
|
* in logical order, reversed in a right-to-left run.
|
|
203
209
|
*/
|
|
204
210
|
private static PlaceRuns;
|
|
211
|
+
/** A line's own height: its spans' largest ascent plus largest descent, times LineHeight, rounded once to whole pixels. */
|
|
212
|
+
private OwnLineHeight;
|
|
205
213
|
private LineHeightPx;
|
|
206
|
-
/**
|
|
214
|
+
/** C# GetSpaceBetweenLines: the label font's Leading times LineSpacing when it has one, else (LineSpacing - 1) lines. */
|
|
215
|
+
private LineGap;
|
|
216
|
+
/**
|
|
217
|
+
* As DrawnUi.Net: the baseline sits at the line's bottom minus its descent, the extra space of LineHeight split above and
|
|
218
|
+
* below the text (a line of lh pixels holds lh / LineHeight of text).
|
|
219
|
+
*/
|
|
220
|
+
private BaselineIn;
|
|
221
|
+
/** ParagraphSpacing above a line that starts a paragraph (after the first): that many lines of the label's font, with their gap. */
|
|
207
222
|
private ParagraphSpace;
|
|
208
223
|
private BlockHeight;
|
|
209
224
|
/** Pixels of ink outside the lines' advance boxes, at their left and right ends (side bearings, italic slant). */
|
|
@@ -25,7 +25,10 @@ export class SkiaLabel extends SkiaControl {
|
|
|
25
25
|
verticalTextAlignment = "Start";
|
|
26
26
|
lineSpacing = 1;
|
|
27
27
|
lineHeight = 1;
|
|
28
|
-
paragraphSpacing = 0;
|
|
28
|
+
paragraphSpacing = 0.25;
|
|
29
|
+
lineHeightUniform = false;
|
|
30
|
+
/** The height every line takes under LineHeightUniform: the tallest laid-out line's (C# MeasuredLineHeight). */
|
|
31
|
+
uniformLineHeight = 0;
|
|
29
32
|
characterSpacing = 1;
|
|
30
33
|
textTransform = "None";
|
|
31
34
|
padding = Thickness.Zero;
|
|
@@ -83,11 +86,14 @@ export class SkiaLabel extends SkiaControl {
|
|
|
83
86
|
get LineHeight() { return this.lineHeight; }
|
|
84
87
|
set LineHeight(v) { this.Set("lineHeight", v); }
|
|
85
88
|
/**
|
|
86
|
-
* Space above every paragraph after the first, in lines (C# ParagraphSpacing
|
|
89
|
+
* Space above every paragraph after the first, in lines of the label's font (C# ParagraphSpacing, default 0.25). A
|
|
87
90
|
* paragraph starts after "\n"; U+2028 breaks the line inside a paragraph.
|
|
88
91
|
*/
|
|
89
92
|
get ParagraphSpacing() { return this.paragraphSpacing; }
|
|
90
93
|
set ParagraphSpacing(v) { this.Set("paragraphSpacing", v); }
|
|
94
|
+
/** LineHeightUniform: true = every line as tall as the tallest one; false (default in every engine) = each line its own height. */
|
|
95
|
+
get LineHeightUniform() { return this.lineHeightUniform; }
|
|
96
|
+
set LineHeightUniform(v) { this.Set("lineHeightUniform", v); }
|
|
91
97
|
/**
|
|
92
98
|
* C# CharacterSpacing: 1 = the font's own spacing; every glyph is followed by (CharacterSpacing - 1) points more
|
|
93
99
|
* (less below 1), the line measures and wraps at the width it draws (C# 7cf1007c, DrawnUi.Rust label).
|
|
@@ -144,7 +150,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
144
150
|
const main = Super.GetFont(family, weight, italic, sizePx);
|
|
145
151
|
const m = main.getMetrics();
|
|
146
152
|
f = {
|
|
147
|
-
Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent,
|
|
153
|
+
Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent, Leading: m.leading,
|
|
148
154
|
Fallbacks: this.fontFamilyFallback
|
|
149
155
|
? this.fontFamilyFallback.split(",").map((a) => a.trim()).filter(Boolean).map((a) => Super.GetFont(a, weight, italic, sizePx))
|
|
150
156
|
: [],
|
|
@@ -497,13 +503,13 @@ export class SkiaLabel extends SkiaControl {
|
|
|
497
503
|
if (isFinite(maxHeight)) {
|
|
498
504
|
let used = 0, fit = 0;
|
|
499
505
|
for (let i = 0; i < out.length; i++) {
|
|
500
|
-
const lh = this.
|
|
506
|
+
const lh = this.OwnLineHeight(out[i]);
|
|
501
507
|
// the block height of the first i + 1 lines: spacing after every line but the last, paragraph space above
|
|
502
508
|
const total = used + lh + (i > 0 ? this.ParagraphSpace(out[i]) : 0);
|
|
503
509
|
if (total > maxHeight && fit > 0)
|
|
504
510
|
break;
|
|
505
511
|
fit++;
|
|
506
|
-
used = total
|
|
512
|
+
used = total + this.LineGap(lh);
|
|
507
513
|
}
|
|
508
514
|
kept = Math.min(kept, fit);
|
|
509
515
|
}
|
|
@@ -642,14 +648,31 @@ export class SkiaLabel extends SkiaControl {
|
|
|
642
648
|
x += runs[k].Width;
|
|
643
649
|
}
|
|
644
650
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
651
|
+
/** A line's own height: its spans' largest ascent plus largest descent, times LineHeight, rounded once to whole pixels. */
|
|
652
|
+
OwnLineHeight(line) { return Math.round((line.Ascent + line.Descent) * this.lineHeight); }
|
|
653
|
+
LineHeightPx(line) { return this.lineHeightUniform ? this.uniformLineHeight : this.OwnLineHeight(line); }
|
|
654
|
+
/** C# GetSpaceBetweenLines: the label font's Leading times LineSpacing when it has one, else (LineSpacing - 1) lines. */
|
|
655
|
+
LineGap(lh) {
|
|
656
|
+
const leading = this.mainFonts?.Leading ?? 0;
|
|
657
|
+
return leading > 0 ? leading * this.lineSpacing : lh * (this.lineSpacing - 1);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* As DrawnUi.Net: the baseline sits at the line's bottom minus its descent, the extra space of LineHeight split above and
|
|
661
|
+
* below the text (a line of lh pixels holds lh / LineHeight of text).
|
|
662
|
+
*/
|
|
663
|
+
BaselineIn(line, lh) { return lh - (lh - lh / this.lineHeight) / 2 - line.Descent; }
|
|
664
|
+
/** ParagraphSpacing above a line that starts a paragraph (after the first): that many lines of the label's font, with their gap. */
|
|
665
|
+
ParagraphSpace(line) {
|
|
666
|
+
if (!line.Para || !this.paragraphSpacing)
|
|
667
|
+
return 0;
|
|
668
|
+
const f = this.mainFonts, lh = Math.round((f.Ascent + f.Descent) * this.lineHeight);
|
|
669
|
+
return (lh + this.LineGap(lh)) * this.paragraphSpacing;
|
|
670
|
+
}
|
|
648
671
|
BlockHeight() {
|
|
649
672
|
let h = 0;
|
|
650
673
|
for (let i = 0; i < this.lines.length; i++) {
|
|
651
674
|
const lh = this.LineHeightPx(this.lines[i]);
|
|
652
|
-
h += (i < this.lines.length - 1 ?
|
|
675
|
+
h += lh + (i < this.lines.length - 1 ? this.LineGap(lh) : 0) + this.ParagraphSpace(this.lines[i]);
|
|
653
676
|
}
|
|
654
677
|
return h;
|
|
655
678
|
}
|
|
@@ -727,6 +750,9 @@ export class SkiaLabel extends SkiaControl {
|
|
|
727
750
|
const r = this.reusable;
|
|
728
751
|
if (this.NeedMeasure || !r || r.Scale !== scale || r.Spacing !== glyphSpacing || roomW < r.Width - 0.01 || roomH < r.Height - 0.01) {
|
|
729
752
|
this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(roomW, scale, roomH) : [];
|
|
753
|
+
this.uniformLineHeight = 0;
|
|
754
|
+
for (const l of this.lines)
|
|
755
|
+
this.uniformLineHeight = Math.max(this.uniformLineHeight, this.OwnLineHeight(l));
|
|
730
756
|
this.ShapeLines(this.lines);
|
|
731
757
|
// ink past the lines' ends (a "j" hook, an italic slant) is drawing room for caches; widths unchanged
|
|
732
758
|
const [inkLeft, inkRight] = this.MeasureInkOverhang();
|
|
@@ -780,7 +806,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
780
806
|
let x = this.LineX(line, left, right, lineW);
|
|
781
807
|
x += extra.Stroke / 2;
|
|
782
808
|
out.push({ x, y, w: line.Width, h: lh, text: line.Runs.map((r) => r.Text).join("") });
|
|
783
|
-
y += lh
|
|
809
|
+
y += lh + this.LineGap(lh);
|
|
784
810
|
}
|
|
785
811
|
return out;
|
|
786
812
|
}
|
|
@@ -952,7 +978,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
952
978
|
const lineW = line.Width + extra.W;
|
|
953
979
|
let x = this.LineX(line, left, right, lineW);
|
|
954
980
|
x += extra.Stroke / 2;
|
|
955
|
-
const baseline = y + line
|
|
981
|
+
const baseline = y + this.BaselineIn(line, lh);
|
|
956
982
|
// C# paintDefault gets the gradient over rectDraw, or over line.Bounds per line (GradientByLines)
|
|
957
983
|
const gradientRect = gradient ? (this.GradientByLines ? new SKRect(x, y, x + line.Width, y + lh) : textRect) : undefined;
|
|
958
984
|
if (strokePaint && this.StrokeGradient)
|
|
@@ -996,7 +1022,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
996
1022
|
}
|
|
997
1023
|
x += run.Width;
|
|
998
1024
|
}
|
|
999
|
-
y += lh
|
|
1025
|
+
y += lh + this.LineGap(lh);
|
|
1000
1026
|
}
|
|
1001
1027
|
for (const paint of paints.values())
|
|
1002
1028
|
paint.delete();
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DrawingContext } from "../core/SkiaControl";
|
|
2
|
-
import type { SKRect } from "../core/Types";
|
|
3
2
|
import { SkiaLabel } from "./SkiaLabel";
|
|
4
3
|
/**
|
|
5
4
|
* Mirrors DrawnUi SkiaLabelFps: a label showing the canvas FPS, drawn above its siblings, input-transparent, never
|
|
@@ -10,7 +9,5 @@ import { SkiaLabel } from "./SkiaLabel";
|
|
|
10
9
|
*/
|
|
11
10
|
export declare class SkiaLabelFps extends SkiaLabel {
|
|
12
11
|
constructor();
|
|
13
|
-
private arrangedIn?;
|
|
14
|
-
Arrange(destination: SKRect, widthRequest: number, heightRequest: number, scale: number): void;
|
|
15
12
|
Render(ctx: DrawingContext): void;
|
|
16
13
|
}
|
|
@@ -20,22 +20,12 @@ export class SkiaLabelFps extends SkiaLabel {
|
|
|
20
20
|
this.InputTransparent = true;
|
|
21
21
|
this.ZIndex = Number.MAX_SAFE_INTEGER;
|
|
22
22
|
}
|
|
23
|
-
arrangedIn;
|
|
24
|
-
Arrange(destination, widthRequest, heightRequest, scale) {
|
|
25
|
-
this.arrangedIn = destination;
|
|
26
|
-
super.Arrange(destination, widthRequest, heightRequest, scale);
|
|
27
|
-
}
|
|
28
23
|
Render(ctx) {
|
|
29
24
|
const view = this.Superview;
|
|
30
25
|
// the frame this asks for is requested anyway by the running animators
|
|
31
26
|
if (view && view.AnimatingControls.size > 0)
|
|
32
27
|
this.Text = `FPS ${view.FPS.toFixed(1).padStart(4, "0")}`;
|
|
33
|
-
// parent-independent:
|
|
34
|
-
const d = this.arrangedIn;
|
|
35
|
-
if (this.NeedMeasure && d) {
|
|
36
|
-
this.Measure(d.Width, d.Height, ctx.Scale);
|
|
37
|
-
this.Arrange(d, this.WidthRequest, this.HeightRequest, ctx.Scale);
|
|
38
|
-
}
|
|
28
|
+
// parent-independent: it measures itself again in its slot as it draws (SkiaControl.Render)
|
|
39
29
|
super.Render(ctx);
|
|
40
30
|
}
|
|
41
31
|
}
|
|
@@ -554,6 +554,33 @@ export class SkiaLayout extends SkiaControl {
|
|
|
554
554
|
cw += (v.VerticalOptions === "Fill" && v.HeightRequest < 0 ? v.Measure(Infinity, size, scale) : v.MeasuredSize).Pixels.Width;
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
|
+
else if (this.Type !== "Column" && this.Type !== "Row" && this.LockRatio === 0) {
|
|
558
|
+
// a layer without its own size on an axis is as big as its children there, where a Fill child with no content of
|
|
559
|
+
// its own (a background shape, a backdrop) counts only with its requests: it takes the layer's size, measured again
|
|
560
|
+
// at it (as DrawnUI for Rust and .NET). A Fill child with content still sizes the layer as before.
|
|
561
|
+
const autoW = (this.HorizontalOptions !== "Fill" || !isFinite(w)) && this.WidthRequest < 0;
|
|
562
|
+
const autoH = (this.VerticalOptions !== "Fill" || !isFinite(h)) && this.HeightRequest < 0;
|
|
563
|
+
if (autoW || autoH) {
|
|
564
|
+
const emptyX = (v) => v.HorizontalOptions === "Fill" && v.WidthRequest < 0 && v.FitPixels.Width - v.Margin.HorizontalThickness * scale <= 0;
|
|
565
|
+
const emptyY = (v) => v.VerticalOptions === "Fill" && v.HeightRequest < 0 && v.FitPixels.Height - v.Margin.VerticalThickness * scale <= 0;
|
|
566
|
+
let sw = 0, sh = 0;
|
|
567
|
+
for (const v of visible) {
|
|
568
|
+
sw = Math.max(sw, emptyX(v) ? v.FitPixels.Width : v.MeasuredSize.Pixels.Width);
|
|
569
|
+
sh = Math.max(sh, emptyY(v) ? v.FitPixels.Height : v.MeasuredSize.Pixels.Height);
|
|
570
|
+
}
|
|
571
|
+
if (!autoW)
|
|
572
|
+
sw = cw;
|
|
573
|
+
if (!autoH)
|
|
574
|
+
sh = ch;
|
|
575
|
+
if (sw !== cw || sh !== ch) {
|
|
576
|
+
cw = sw;
|
|
577
|
+
ch = sh;
|
|
578
|
+
for (const v of visible)
|
|
579
|
+
if ((autoW && emptyX(v)) || (autoH && emptyY(v)))
|
|
580
|
+
v.Measure(autoW ? sw : w, autoH ? sh : h, scale);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
557
584
|
const gaps = Math.max(0, n - 1) * gap;
|
|
558
585
|
if (this.Type === "Column")
|
|
559
586
|
ch += gaps;
|
|
@@ -905,17 +932,21 @@ export class SkiaLayout extends SkiaControl {
|
|
|
905
932
|
}
|
|
906
933
|
return;
|
|
907
934
|
}
|
|
935
|
+
// main axis of a stack: an End child gets the room up to the end of the stack, so it sits there (a button after a
|
|
936
|
+
// text in a full-width row); every child still takes only its measured size from the flow (DrawnUI for Rust)
|
|
908
937
|
for (const v of this.LayoutViews()) {
|
|
909
938
|
if (!v.IsVisible)
|
|
910
939
|
continue;
|
|
911
940
|
if (this.Type === "Column") {
|
|
912
941
|
const h = v.MeasuredSize.Pixels.Height;
|
|
913
|
-
v.
|
|
942
|
+
const end = v.VerticalOptions === "End" ? Math.max(inner.Bottom, cursor + h) : cursor + h;
|
|
943
|
+
v.Arrange(new SKRect(inner.Left, cursor, inner.Right, end), v.WidthRequest, v.HeightRequest, scale);
|
|
914
944
|
cursor += h + gap;
|
|
915
945
|
}
|
|
916
946
|
else if (this.Type === "Row") {
|
|
917
947
|
const w = v.MeasuredSize.Pixels.Width;
|
|
918
|
-
v.
|
|
948
|
+
const end = v.HorizontalOptions === "End" ? Math.max(inner.Right, cursor + w) : cursor + w;
|
|
949
|
+
v.Arrange(new SKRect(cursor, inner.Top, end, inner.Bottom), v.WidthRequest, v.HeightRequest, scale);
|
|
919
950
|
cursor += w + gap;
|
|
920
951
|
}
|
|
921
952
|
else {
|
|
@@ -16,6 +16,11 @@ export interface ScaledPoint {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class SkiaScroll extends SkiaControl {
|
|
18
18
|
static WheelLineSize: number;
|
|
19
|
+
/**
|
|
20
|
+
* Wheel events closer than this (ms) are one wheel gesture: they keep the scroll they started on, as browsers latch a
|
|
21
|
+
* scroller (C# SkiaScroll.WheelGestureGapMs, drawnui-cross 6bo).
|
|
22
|
+
*/
|
|
23
|
+
static WheelGestureGapMs: number;
|
|
19
24
|
static ThesholdSwipeOnUp: number;
|
|
20
25
|
static ScrollVelocityThreshold: number;
|
|
21
26
|
Orientation: ScrollOrientation;
|
|
@@ -257,5 +262,17 @@ export declare class SkiaScroll extends SkiaControl {
|
|
|
257
262
|
* aaa871c3); an event under half a notch moves the content at once (no glide). Events arriving while the previous one is still animating add onto its target, so a fast wheel spin
|
|
258
263
|
* travels N steps instead of restarting from the barely-moved current offset.
|
|
259
264
|
*/
|
|
265
|
+
/**
|
|
266
|
+
* drawnui-cross 6bo (DrawnUi.Rust leaves_drag_to_outer), asked once, when this scroll would take a drag: already at its
|
|
267
|
+
* end in the drag's direction (at its start dragged back, at its end dragged on) with a scroll around it moving on the
|
|
268
|
+
* same axis, the outer scroll takes the whole drag. Never toward the start with pull to refresh on; a scroll with nothing
|
|
269
|
+
* around it keeps its edge bounce. Otherwise this scroll keeps the drag to its end.
|
|
270
|
+
*/
|
|
271
|
+
private LeavesDragToOuter;
|
|
272
|
+
private static Contains;
|
|
273
|
+
/** The scroll the current wheel gesture belongs to, and its last event time. */
|
|
274
|
+
private static wheelLatch?;
|
|
275
|
+
/** It scrolls with the wheel on this axis (a vertical scroll leaves the sideways part of a diagonal swipe to what is around it). */
|
|
276
|
+
private WheelUsable;
|
|
260
277
|
private ApplyWheelScroll;
|
|
261
278
|
}
|
|
@@ -13,6 +13,11 @@ import { RubberBandUtils, ScrollFlingAnimator, Spring, SpringWithVelocityAnimato
|
|
|
13
13
|
*/
|
|
14
14
|
export class SkiaScroll extends SkiaControl {
|
|
15
15
|
static WheelLineSize = 150;
|
|
16
|
+
/**
|
|
17
|
+
* Wheel events closer than this (ms) are one wheel gesture: they keep the scroll they started on, as browsers latch a
|
|
18
|
+
* scroller (C# SkiaScroll.WheelGestureGapMs, drawnui-cross 6bo).
|
|
19
|
+
*/
|
|
20
|
+
static WheelGestureGapMs = 300;
|
|
16
21
|
static ThesholdSwipeOnUp = 20;
|
|
17
22
|
static ScrollVelocityThreshold = 5;
|
|
18
23
|
Orientation = "Vertical";
|
|
@@ -989,17 +994,26 @@ export class SkiaScroll extends SkiaControl {
|
|
|
989
994
|
return super.ProcessGestures(args, apply) ?? consumedDefault; // children see Down (buttons press)
|
|
990
995
|
}
|
|
991
996
|
if (args.Type === "Wheel") {
|
|
997
|
+
// one wheel gesture keeps the scroll it started on (6bo): a scroll inside this one that took it keeps it, also at
|
|
998
|
+
// its end (the page waits for the next gesture); one this scroll took is not given to a list that comes under the pointer
|
|
999
|
+
const now = performance.now(), latch = SkiaScroll.wheelLatch;
|
|
1000
|
+
const latched = latch && now - latch.At < SkiaScroll.WheelGestureGapMs && !latch.Scroll.IsDisposed && latch.Scroll.Superview ? latch.Scroll : undefined;
|
|
1001
|
+
if (latched && latched !== this && SkiaScroll.Contains(this, latched)) {
|
|
1002
|
+
latch.At = now;
|
|
1003
|
+
if (latched.WheelUsable(e.Wheel.IsHorizontal))
|
|
1004
|
+
latched.ApplyWheelScroll(e.Wheel.Delta);
|
|
1005
|
+
e.Handled = true;
|
|
1006
|
+
return latched;
|
|
1007
|
+
}
|
|
992
1008
|
// a nested scroll under the pointer takes the wheel first; the outer one scrolls when the inner is at its edge
|
|
993
|
-
const child = super.ProcessGestures(args, apply);
|
|
1009
|
+
const child = latched === this ? null : super.ProcessGestures(args, apply);
|
|
994
1010
|
if (child && child !== this)
|
|
995
1011
|
return child;
|
|
996
|
-
if (!this.
|
|
997
|
-
return child ?? consumedDefault; //
|
|
998
|
-
// a vertical scroll leaves horizontal events (the sideways part of a diagonal swipe) to whatever is around it
|
|
999
|
-
if (e.Wheel.IsHorizontal && this.Orientation === "Vertical")
|
|
1000
|
-
return child ?? consumedDefault;
|
|
1012
|
+
if (!this.WheelUsable(e.Wheel.IsHorizontal))
|
|
1013
|
+
return child ?? consumedDefault; // not used, a parent scroll may take it
|
|
1001
1014
|
if (!this.ApplyWheelScroll(e.Wheel.Delta))
|
|
1002
1015
|
return consumedDefault; // at its edge: not used, the page may take it
|
|
1016
|
+
SkiaScroll.wheelLatch = { Scroll: this, At: now };
|
|
1003
1017
|
e.Handled = true;
|
|
1004
1018
|
return this;
|
|
1005
1019
|
}
|
|
@@ -1024,6 +1038,8 @@ export class SkiaScroll extends SkiaControl {
|
|
|
1024
1038
|
const v = this.Orientation === "Vertical" ? this.velocityY : this.Orientation === "Horizontal" ? this.velocityX : Math.max(Math.abs(this.velocityX), Math.abs(this.velocityY));
|
|
1025
1039
|
if (Math.abs(v) <= SkiaScroll.ScrollVelocityThreshold)
|
|
1026
1040
|
return consumedDefault;
|
|
1041
|
+
if (this.LeavesDragToOuter(e.Distance.Total))
|
|
1042
|
+
return null; // not used: the scroll around it takes the whole drag
|
|
1027
1043
|
}
|
|
1028
1044
|
if (!this.IsUserFocused)
|
|
1029
1045
|
this.ResetPan();
|
|
@@ -1143,6 +1159,35 @@ export class SkiaScroll extends SkiaControl {
|
|
|
1143
1159
|
* aaa871c3); an event under half a notch moves the content at once (no glide). Events arriving while the previous one is still animating add onto its target, so a fast wheel spin
|
|
1144
1160
|
* travels N steps instead of restarting from the barely-moved current offset.
|
|
1145
1161
|
*/
|
|
1162
|
+
/**
|
|
1163
|
+
* drawnui-cross 6bo (DrawnUi.Rust leaves_drag_to_outer), asked once, when this scroll would take a drag: already at its
|
|
1164
|
+
* end in the drag's direction (at its start dragged back, at its end dragged on) with a scroll around it moving on the
|
|
1165
|
+
* same axis, the outer scroll takes the whole drag. Never toward the start with pull to refresh on; a scroll with nothing
|
|
1166
|
+
* around it keeps its edge bounce. Otherwise this scroll keeps the drag to its end.
|
|
1167
|
+
*/
|
|
1168
|
+
LeavesDragToOuter(total) {
|
|
1169
|
+
const vertical = this.Orientation === "Vertical" || (this.Orientation === "Both" && Math.abs(total.Y) >= Math.abs(total.X));
|
|
1170
|
+
const d = vertical ? total.Y : total.X; // finger down / right = toward the start (offset grows to 0)
|
|
1171
|
+
if (d === 0 || (d > 0 && this.RefreshEnabled))
|
|
1172
|
+
return false;
|
|
1173
|
+
const b = this.ContentOffsetBounds;
|
|
1174
|
+
const offset = vertical ? this.offsetY : this.offsetX;
|
|
1175
|
+
if (d > 0 ? offset < (vertical ? b.Bottom : b.Right) : offset > (vertical ? b.Top : b.Left))
|
|
1176
|
+
return false;
|
|
1177
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1178
|
+
if (p instanceof SkiaScroll && p.RespondsToGestures && p.Orientation !== "Neither" && p.Orientation !== (vertical ? "Horizontal" : "Vertical"))
|
|
1179
|
+
return true;
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
static Contains(root, c) { for (let p = c.Parent; p; p = p.Parent)
|
|
1183
|
+
if (p === root)
|
|
1184
|
+
return true; return false; }
|
|
1185
|
+
/** The scroll the current wheel gesture belongs to, and its last event time. */
|
|
1186
|
+
static wheelLatch;
|
|
1187
|
+
/** It scrolls with the wheel on this axis (a vertical scroll leaves the sideways part of a diagonal swipe to what is around it). */
|
|
1188
|
+
WheelUsable(horizontal) {
|
|
1189
|
+
return this.RespondsToGestures && this.Orientation !== "Neither" && !(horizontal && this.Orientation === "Vertical");
|
|
1190
|
+
}
|
|
1146
1191
|
ApplyWheelScroll(delta) {
|
|
1147
1192
|
const perNotch = this.Superview?.WheelDeltaPerNotch ?? 0;
|
|
1148
1193
|
const lines = perNotch > 0 ? delta / perNotch : Math.sign(delta);
|