drawnui-react 0.1.0-preview.33 → 0.1.0-preview.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SKIPPED.md +1 -1
- package/dist/controls/SkiaLabel.d.ts +14 -1
- package/dist/controls/SkiaLabel.js +78 -17
- package/dist/controls/SkiaLayout.js +38 -1
- package/dist/core/SkiaControl.d.ts +14 -0
- package/dist/core/SkiaControl.js +22 -0
- package/package.json +4 -1
package/SKIPPED.md
CHANGED
|
@@ -62,7 +62,7 @@ DrawnUi name and semantics; nothing here is a redesign, only an omission.
|
|
|
62
62
|
|
|
63
63
|
| Control | Status | Notes |
|
|
64
64
|
|---|---|---|
|
|
65
|
-
| `SkiaLayout` Absolute / Column / Row (+ `SkiaStack`, `SkiaRow`, `SkiaLayer`) | ported | `Spacing`, `Padding`, `Children`/`Views`, `AddSubView`/`RemoveSubView`/`InsertSubView`, `ClearChildren`, `IsChildrenItem`. Children changes follow C# `ChildrenCollectionSync` (insert / move / reset in collection order inside the slots app children occupy); React has no `ObservableCollection`: JSX children diffs and a new `Children` list are the collection actions. |
|
|
65
|
+
| `SkiaLayout` Absolute / Column / Row (+ `SkiaStack`, `SkiaRow`, `SkiaLayer`) | ported | A Column / Row that sizes itself on its cross axis takes its widest / tallest child's fit-content size, Fill children included, and lays those Fill children out at that size (drawnui-cross 6an). `Spacing`, `Padding`, `Children`/`Views`, `AddSubView`/`RemoveSubView`/`InsertSubView`, `ClearChildren`, `IsChildrenItem`. Children changes follow C# `ChildrenCollectionSync` (insert / move / reset in collection order inside the slots app children occupy); React has no `ObservableCollection`: JSX children diffs and a new `Children` list are the collection actions. |
|
|
66
66
|
| `SkiaLayout` templated (Column only): `ItemsSource` (array), `ItemTemplate` (factory `() => SkiaControl`), `RecyclingTemplate` Enabled/Disabled, `MeasureItemsStrategy` `MeasureAll` (default, per-item size) / `MeasureFirst` (explicit uniform, O(1) for 100k items), `ChildrenFactory` (ViewsAdapter pool: `GetOrCreateViewForIndex`, `ReleaseViewAt`), `FirstVisibleIndex`/`LastVisibleIndex`, `DebugString`, `ApplyItemsSource`, `VirtualisationInflated`, `BindingContext`/`ContextIndex` on every control, `SkiaDynamicDrawnCell.SetContent` | ported | Cells realized/bound/arranged/drawn only for the visible viewport (+inflation) each frame. |
|
|
67
67
|
| `LoadMoreCommand` / `LoadMoreTopCommand` / `LoadMoreOffset` / `LoadMoreTopOffset` | ported | Callbacks instead of ICommand. Bottom fires once per content extent when within the offset of the end (or when the content underfills the viewport), re-arms when the content grows or the user moves away (>offset+100 pt, >2 s) — C# CheckNeedToLoadMore. Top arms only after the offset left the top edge, fires when it comes back. Not ported: opposite-direction cooldown (`IsOppositeLoadMoreBlocked`), `IInsideViewport.ShouldTriggerLoadMore`. |
|
|
68
68
|
| Structure-preserving `ItemsSource` updates | ported (array diff) | C# listens to `ObservableCollection` Add/Insert; React apps replace the array, so the setter detects **append** (old is a prefix: measured heights kept, tail measured lazily) and **prepend** (old is a suffix: view indices shifted without rebinding, new head measured synchronously up to 200 items, `ItemsInsertedAtStart(px)` lets the `SkiaScroll` move its offset so visible rows stay put — C# head-insert rebase). and **reorder** (same items permuted, the C# `ObservableCollection.Move` case: contexts rebound, the index-keyed measured heights permuted with their items, nothing re-measured, extent and scroll offset unchanged). Any other change rebuilds the structure (heights re-measured, offset kept). Not ported: removals in place, `Replace`. |
|
|
@@ -113,7 +113,11 @@ export declare class SkiaLabel extends SkiaControl {
|
|
|
113
113
|
private lines;
|
|
114
114
|
private mainFonts?;
|
|
115
115
|
private readonly fontsCache;
|
|
116
|
-
|
|
116
|
+
/** Runs of a text per style (Segment), and the same runs carrying a span; cleared when the glyph spacing changes. */
|
|
117
|
+
private runCache;
|
|
118
|
+
private spanRunCache;
|
|
119
|
+
/** Wrap tokens of the text, kept while the label has not changed (NeedMeasure) at the same scale. */
|
|
120
|
+
private tokens?;
|
|
117
121
|
/** CharacterSpacing in pixels at the measured scale: added after every glyph of a run (its Width includes them). */
|
|
118
122
|
private glyphSpacing;
|
|
119
123
|
private ResolveFonts;
|
|
@@ -170,6 +174,15 @@ export declare class SkiaLabel extends SkiaControl {
|
|
|
170
174
|
* and MaxLines, the last kept one ending with a tail ellipsis (C# / DrawnUi.Rust: a label in a box too short for its
|
|
171
175
|
* text cuts it, not only MaxLines).
|
|
172
176
|
*/
|
|
177
|
+
/** The last layout broke a line because the text did not fit: its max-content is wider than the constraint. */
|
|
178
|
+
private wrapped;
|
|
179
|
+
/** The last layout cut lines (MaxLines, height, an ellipsis): its lines depend on the room it had. */
|
|
180
|
+
private truncated;
|
|
181
|
+
/**
|
|
182
|
+
* Lines laid out without wrapping or cutting stay the same for any room that holds them: reused, while nothing in the
|
|
183
|
+
* label changed (NeedMeasure), for a later measure with at least that width and height (C# 5f24f577 label line reuse).
|
|
184
|
+
*/
|
|
185
|
+
private reusable?;
|
|
173
186
|
private LayoutLines;
|
|
174
187
|
/** A paragraph is right to left when its first strong letter is (DrawnUi.Rust split_bidi). */
|
|
175
188
|
static FirstStrongIsRtl(text: string): boolean;
|
|
@@ -127,7 +127,11 @@ export class SkiaLabel extends SkiaControl {
|
|
|
127
127
|
lines = [];
|
|
128
128
|
mainFonts;
|
|
129
129
|
fontsCache = new Map();
|
|
130
|
+
/** Runs of a text per style (Segment), and the same runs carrying a span; cleared when the glyph spacing changes. */
|
|
130
131
|
runCache = new Map();
|
|
132
|
+
spanRunCache = new WeakMap();
|
|
133
|
+
/** Wrap tokens of the text, kept while the label has not changed (NeedMeasure) at the same scale. */
|
|
134
|
+
tokens;
|
|
131
135
|
/** CharacterSpacing in pixels at the measured scale: added after every glyph of a run (its Width includes them). */
|
|
132
136
|
glyphSpacing = 0;
|
|
133
137
|
ResolveFonts(family, weight, italic, sizePx) {
|
|
@@ -192,15 +196,20 @@ export class SkiaLabel extends SkiaControl {
|
|
|
192
196
|
Segment(text, fonts, span) {
|
|
193
197
|
if (text.length === 0)
|
|
194
198
|
return [];
|
|
195
|
-
|
|
196
|
-
|
|
199
|
+
let byText = this.runCache.get(fonts);
|
|
200
|
+
if (!byText) {
|
|
201
|
+
byText = new Map();
|
|
202
|
+
this.runCache.set(fonts, byText);
|
|
203
|
+
}
|
|
204
|
+
let cached = byText.get(text);
|
|
205
|
+
const cacheKey = text;
|
|
197
206
|
if (!cached) {
|
|
198
207
|
const main = fonts.Main;
|
|
199
208
|
const fbs = fonts.Fallbacks;
|
|
200
209
|
cached = [];
|
|
201
210
|
text = SkiaLabel.DropIgnorables(text, main, fbs);
|
|
202
211
|
if (text.length === 0) {
|
|
203
|
-
|
|
212
|
+
byText.set(cacheKey, cached);
|
|
204
213
|
return cached;
|
|
205
214
|
}
|
|
206
215
|
if (fbs.length === 0) {
|
|
@@ -231,9 +240,27 @@ export class SkiaLabel extends SkiaControl {
|
|
|
231
240
|
const t = cps.slice(start).join("");
|
|
232
241
|
cached.push({ Text: t, Font: current, Width: this.Advance(current, t), Fonts: fonts });
|
|
233
242
|
}
|
|
234
|
-
|
|
243
|
+
byText.set(cacheKey, cached);
|
|
244
|
+
}
|
|
245
|
+
if (!span)
|
|
246
|
+
return cached;
|
|
247
|
+
// the same runs carrying the span, made once per span, style and text
|
|
248
|
+
let bySpan = this.spanRunCache.get(span);
|
|
249
|
+
if (!bySpan) {
|
|
250
|
+
bySpan = new Map();
|
|
251
|
+
this.spanRunCache.set(span, bySpan);
|
|
252
|
+
}
|
|
253
|
+
let spanByText = bySpan.get(fonts);
|
|
254
|
+
if (!spanByText) {
|
|
255
|
+
spanByText = new Map();
|
|
256
|
+
bySpan.set(fonts, spanByText);
|
|
257
|
+
}
|
|
258
|
+
let withSpan = spanByText.get(cacheKey);
|
|
259
|
+
if (!withSpan) {
|
|
260
|
+
withSpan = cached.map((r) => ({ ...r, Span: span }));
|
|
261
|
+
spanByText.set(cacheKey, withSpan);
|
|
235
262
|
}
|
|
236
|
-
return
|
|
263
|
+
return withSpan;
|
|
237
264
|
}
|
|
238
265
|
Width(runs) { let w = 0; for (const r of runs)
|
|
239
266
|
w += r.Width; return w; }
|
|
@@ -382,13 +409,27 @@ export class SkiaLabel extends SkiaControl {
|
|
|
382
409
|
* and MaxLines, the last kept one ending with a tail ellipsis (C# / DrawnUi.Rust: a label in a box too short for its
|
|
383
410
|
* text cuts it, not only MaxLines).
|
|
384
411
|
*/
|
|
412
|
+
/** The last layout broke a line because the text did not fit: its max-content is wider than the constraint. */
|
|
413
|
+
wrapped = false;
|
|
414
|
+
/** The last layout cut lines (MaxLines, height, an ellipsis): its lines depend on the room it had. */
|
|
415
|
+
truncated = false;
|
|
416
|
+
/**
|
|
417
|
+
* Lines laid out without wrapping or cutting stay the same for any room that holds them: reused, while nothing in the
|
|
418
|
+
* label changed (NeedMeasure), for a later measure with at least that width and height (C# 5f24f577 label line reuse).
|
|
419
|
+
*/
|
|
420
|
+
reusable;
|
|
385
421
|
LayoutLines(maxWidth, scale, maxHeight = Infinity) {
|
|
422
|
+
this.wrapped = false;
|
|
423
|
+
this.truncated = false;
|
|
386
424
|
const wrap = this.lineBreakMode !== "NoWrap" && isFinite(maxWidth);
|
|
387
425
|
// run widths carry the gap after every glyph; the one after a line's last glyph is not drawn
|
|
388
426
|
const sp = this.glyphSpacing;
|
|
389
427
|
const out = [];
|
|
390
428
|
const empty = (fonts) => { const l = this.NewLine(); l.Ascent = fonts.Ascent; l.Descent = fonts.Descent; return l; };
|
|
391
|
-
|
|
429
|
+
// the text's wrap tokens change only with the label (NeedMeasure) or the scale
|
|
430
|
+
if (this.NeedMeasure || !this.tokens || this.tokens.Scale !== scale)
|
|
431
|
+
this.tokens = { Scale: scale, Paragraphs: this.Tokenize(scale) };
|
|
432
|
+
for (const para of this.tokens.Paragraphs) {
|
|
392
433
|
let line = this.NewLine();
|
|
393
434
|
if (out.length > 0 && !para.LineBreak)
|
|
394
435
|
line.Para = true;
|
|
@@ -423,11 +464,13 @@ export class SkiaLabel extends SkiaControl {
|
|
|
423
464
|
out.push(line);
|
|
424
465
|
line = this.NewLine();
|
|
425
466
|
word = rest;
|
|
467
|
+
this.wrapped = true;
|
|
426
468
|
continue;
|
|
427
469
|
}
|
|
428
470
|
if (line.Runs.length > 0) {
|
|
429
471
|
out.push(line);
|
|
430
472
|
line = this.NewLine();
|
|
473
|
+
this.wrapped = true;
|
|
431
474
|
continue;
|
|
432
475
|
}
|
|
433
476
|
// word longer than the line: break by code points
|
|
@@ -438,6 +481,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
438
481
|
if (line.Runs.length > 0 && line.Width + chW - sp > maxWidth) {
|
|
439
482
|
out.push(line);
|
|
440
483
|
line = this.NewLine();
|
|
484
|
+
this.wrapped = true;
|
|
441
485
|
}
|
|
442
486
|
this.Append(line, run);
|
|
443
487
|
}
|
|
@@ -462,6 +506,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
462
506
|
kept = Math.min(kept, fit);
|
|
463
507
|
}
|
|
464
508
|
if (kept < out.length) {
|
|
509
|
+
this.truncated = true;
|
|
465
510
|
out.length = kept;
|
|
466
511
|
const truncates = this.lineBreakMode === "TailTruncation" || this.lineBreakMode === "HeadTruncation" || this.lineBreakMode === "MiddleTruncation";
|
|
467
512
|
if (truncates) {
|
|
@@ -638,7 +683,10 @@ export class SkiaLabel extends SkiaControl {
|
|
|
638
683
|
const b = r.Font.getGlyphBounds([g[0], g[n - 1]]);
|
|
639
684
|
return [x0 + r.Shaped.Positions[0] + b[0], x0 + r.Shaped.Positions[(n - 1) * 2] + b[6]];
|
|
640
685
|
}
|
|
641
|
-
|
|
686
|
+
// only the first and the last character matter
|
|
687
|
+
const first = String.fromCodePoint(r.Text.codePointAt(0));
|
|
688
|
+
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);
|
|
689
|
+
const ids = r.Font.getGlyphIDs(first + r.Text.slice(lastAt));
|
|
642
690
|
const n = ids.length;
|
|
643
691
|
const b = r.Font.getGlyphBounds([ids[0], ids[n - 1]]);
|
|
644
692
|
const lastAdvance = r.Font.getGlyphWidths([ids[n - 1]])[0];
|
|
@@ -668,25 +716,38 @@ export class SkiaLabel extends SkiaControl {
|
|
|
668
716
|
const glyphSpacing = scale * (this.characterSpacing - 1);
|
|
669
717
|
if (glyphSpacing !== this.glyphSpacing) {
|
|
670
718
|
this.glyphSpacing = glyphSpacing;
|
|
671
|
-
this.runCache
|
|
719
|
+
this.runCache = new Map();
|
|
720
|
+
this.spanRunCache = new WeakMap();
|
|
672
721
|
}
|
|
673
722
|
const px = this.padding.HorizontalThickness * scale, py = this.padding.VerticalThickness * scale;
|
|
674
723
|
const extraH = this.EffectsExtra(scale).H;
|
|
675
|
-
|
|
676
|
-
this.
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
this.
|
|
724
|
+
const roomW = widthConstraint - px, roomH = heightConstraint - py - extraH;
|
|
725
|
+
const r = this.reusable;
|
|
726
|
+
if (this.NeedMeasure || !r || r.Scale !== scale || r.Spacing !== glyphSpacing || roomW < r.Width - 0.01 || roomH < r.Height - 0.01) {
|
|
727
|
+
this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(roomW, scale, roomH) : [];
|
|
728
|
+
this.ShapeLines(this.lines);
|
|
729
|
+
// ink past the lines' ends (a "j" hook, an italic slant) is drawing room for caches; widths unchanged
|
|
730
|
+
const [inkLeft, inkRight] = this.MeasureInkOverhang();
|
|
731
|
+
if (inkLeft !== this.inkLeft || inkRight !== this.inkRight) {
|
|
732
|
+
this.inkLeft = inkLeft;
|
|
733
|
+
this.inkRight = inkRight;
|
|
734
|
+
this.InvalidateEffectsMargin();
|
|
735
|
+
}
|
|
736
|
+
let widest = 0;
|
|
737
|
+
for (const l of this.lines)
|
|
738
|
+
widest = Math.max(widest, l.Width);
|
|
739
|
+
this.reusable = this.wrapped || this.truncated ? undefined : { Scale: scale, Spacing: glyphSpacing, Width: widest, Height: this.BlockHeight() };
|
|
683
740
|
}
|
|
684
741
|
let width = 0;
|
|
685
742
|
for (const l of this.lines)
|
|
686
743
|
width = Math.max(width, l.Width);
|
|
687
744
|
const extra = this.EffectsExtra(scale);
|
|
688
745
|
this.LayoutVersion++;
|
|
689
|
-
|
|
746
|
+
const size = ScaledSize.FromPixels(Math.ceil(width + extra.W) + px, Math.ceil(this.BlockHeight() + extra.H) + py, scale);
|
|
747
|
+
// fit-content (drawnui-cross 6an): text that had to wrap needs the whole width it was given (min of max-content and it)
|
|
748
|
+
if (this.wrapped && isFinite(widthConstraint))
|
|
749
|
+
this.fitContentPixels = { Width: widthConstraint, Height: size.Pixels.Height };
|
|
750
|
+
return size;
|
|
690
751
|
}
|
|
691
752
|
/** C# GradientByLines: FillGradient spans each line's bounds (default) instead of the whole text block. */
|
|
692
753
|
GradientByLines = true;
|
|
@@ -26,6 +26,8 @@ class TemplatedSlot {
|
|
|
26
26
|
MinimumWidthRequest = -1;
|
|
27
27
|
MinimumHeightRequest = -1;
|
|
28
28
|
MeasuredSize = ScaledSize.Default;
|
|
29
|
+
/** The view's fit-content size from the same measure (SkiaControl.FitPixels). */
|
|
30
|
+
FitPixels = { Width: 0, Height: 0 };
|
|
29
31
|
WidthConstraint = Infinity;
|
|
30
32
|
HeightConstraint = Infinity;
|
|
31
33
|
/** The rect the layout arranged this slot in (pixels). */
|
|
@@ -45,9 +47,12 @@ class TemplatedSlot {
|
|
|
45
47
|
&& Object.is(widthConstraint, this.WidthConstraint) && Object.is(heightConstraint, this.HeightConstraint))
|
|
46
48
|
return this.MeasuredSize;
|
|
47
49
|
const view = shown ?? this.factory.GetOrCreateViewForIndex(this.Index, true);
|
|
48
|
-
if (!view)
|
|
50
|
+
if (!view) {
|
|
51
|
+
this.FitPixels = { Width: 0, Height: 0 };
|
|
49
52
|
return (this.MeasuredSize = ScaledSize.Default);
|
|
53
|
+
}
|
|
50
54
|
this.MeasuredSize = view.Measure(widthConstraint, heightConstraint, scale);
|
|
55
|
+
this.FitPixels = view.FitPixels;
|
|
51
56
|
this.measuredItem = item;
|
|
52
57
|
this.measuredScale = scale;
|
|
53
58
|
this.WidthConstraint = widthConstraint;
|
|
@@ -497,6 +502,9 @@ export class SkiaLayout extends SkiaControl {
|
|
|
497
502
|
const s = this.MeasureGrid(w, h, scale);
|
|
498
503
|
return ScaledSize.FromPixels(s.w + px, s.h + py, scale);
|
|
499
504
|
}
|
|
505
|
+
// fit-content of the children on the cross axis (Fill children included, drawnui-cross 6an)
|
|
506
|
+
let fitW = 0, fitH = 0;
|
|
507
|
+
const visible = [];
|
|
500
508
|
for (const v of this.LayoutViews()) {
|
|
501
509
|
if (!v.IsVisible)
|
|
502
510
|
continue;
|
|
@@ -516,13 +524,42 @@ export class SkiaLayout extends SkiaControl {
|
|
|
516
524
|
cw = Math.max(cw, s.Pixels.Width);
|
|
517
525
|
ch = Math.max(ch, s.Pixels.Height);
|
|
518
526
|
}
|
|
527
|
+
fitW = Math.max(fitW, v.FitPixels.Width);
|
|
528
|
+
fitH = Math.max(fitH, v.FitPixels.Height);
|
|
529
|
+
visible.push(v);
|
|
519
530
|
n++;
|
|
520
531
|
}
|
|
532
|
+
// a stack that sizes itself on its cross axis (no request, not Fill, or Fill on an unbounded axis) is as wide / tall
|
|
533
|
+
// as its widest / tallest child needs; its Fill children are measured again at that size, so their wrapped heights /
|
|
534
|
+
// widths are the drawn ones
|
|
535
|
+
if (this.Type === "Column" && (this.HorizontalOptions !== "Fill" || !isFinite(w)) && this.WidthRequest < 0 && this.LockRatio === 0) {
|
|
536
|
+
const size = isFinite(w) ? Math.min(fitW, w) : fitW;
|
|
537
|
+
if (size !== cw) {
|
|
538
|
+
cw = size;
|
|
539
|
+
ch = 0;
|
|
540
|
+
for (const v of visible)
|
|
541
|
+
ch += (v.HorizontalOptions === "Fill" && v.WidthRequest < 0 ? v.Measure(size, Infinity, scale) : v.MeasuredSize).Pixels.Height;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
else if (this.Type === "Row" && (this.VerticalOptions !== "Fill" || !isFinite(h)) && this.HeightRequest < 0 && this.LockRatio === 0) {
|
|
545
|
+
const size = isFinite(h) ? Math.min(fitH, h) : fitH;
|
|
546
|
+
if (size !== ch) {
|
|
547
|
+
ch = size;
|
|
548
|
+
cw = 0;
|
|
549
|
+
for (const v of visible)
|
|
550
|
+
cw += (v.VerticalOptions === "Fill" && v.HeightRequest < 0 ? v.Measure(Infinity, size, scale) : v.MeasuredSize).Pixels.Width;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
521
553
|
const gaps = Math.max(0, n - 1) * gap;
|
|
522
554
|
if (this.Type === "Column")
|
|
523
555
|
ch += gaps;
|
|
524
556
|
if (this.Type === "Row")
|
|
525
557
|
cw += gaps;
|
|
558
|
+
// what this layout's own content needs, for a stack around it (a Fill layout still returns the whole constraint)
|
|
559
|
+
this.fitContentPixels = {
|
|
560
|
+
Width: (this.Type === "Row" ? cw : Math.min(cw, fitW)) + px,
|
|
561
|
+
Height: (this.Type === "Column" ? ch : Math.min(ch, fitH)) + py,
|
|
562
|
+
};
|
|
526
563
|
return ScaledSize.FromPixels(cw + px, ch + py, scale);
|
|
527
564
|
}
|
|
528
565
|
/** Wrap rows computed by the last measure: [childIndex, x, y, w, h] in pixels relative to the padded box. */
|
|
@@ -311,6 +311,20 @@ export declare class SkiaControl {
|
|
|
311
311
|
_superview?: Canvas;
|
|
312
312
|
get Superview(): Canvas | undefined;
|
|
313
313
|
MeasuredSize: ScaledSize;
|
|
314
|
+
/**
|
|
315
|
+
* The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
|
|
316
|
+
* axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
|
|
317
|
+
* stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
|
|
318
|
+
*/
|
|
319
|
+
FitPixels: {
|
|
320
|
+
Width: number;
|
|
321
|
+
Height: number;
|
|
322
|
+
};
|
|
323
|
+
/** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
|
|
324
|
+
protected fitContentPixels?: {
|
|
325
|
+
Width: number;
|
|
326
|
+
Height: number;
|
|
327
|
+
};
|
|
314
328
|
DrawingRect: SKRect;
|
|
315
329
|
RenderingScale: number;
|
|
316
330
|
NeedMeasure: boolean;
|
package/dist/core/SkiaControl.js
CHANGED
|
@@ -444,6 +444,14 @@ export class SkiaControl {
|
|
|
444
444
|
}
|
|
445
445
|
// ---- state (pixels) ----
|
|
446
446
|
MeasuredSize = ScaledSize.Default;
|
|
447
|
+
/**
|
|
448
|
+
* The size the control's content needs, in pixels with its margins, after the last measure: as MeasuredSize but a Fill
|
|
449
|
+
* axis keeps the content's size instead of taking the whole constraint (fit-content: requests, min / max applied). A
|
|
450
|
+
* stack that sizes itself to its children on the cross axis reads it (drawnui-cross 6an).
|
|
451
|
+
*/
|
|
452
|
+
FitPixels = { Width: 0, Height: 0 };
|
|
453
|
+
/** Set by MeasureAbsolute when the content's fit size differs from the size it returns (a layout with Fill children). */
|
|
454
|
+
fitContentPixels;
|
|
447
455
|
DrawingRect = SKRect.Empty;
|
|
448
456
|
RenderingScale = 1;
|
|
449
457
|
NeedMeasure = true;
|
|
@@ -492,6 +500,7 @@ export class SkiaControl {
|
|
|
492
500
|
locked = true;
|
|
493
501
|
}
|
|
494
502
|
}
|
|
503
|
+
this.fitContentPixels = undefined;
|
|
495
504
|
const content = this.MeasureAbsolute(w, h, scale);
|
|
496
505
|
let rw = locked || reqW >= 0 ? w : this.HorizontalOptions === "Fill" && isFinite(w) ? w : content.Pixels.Width;
|
|
497
506
|
let rh = locked || reqH >= 0 ? h : this.VerticalOptions === "Fill" && isFinite(h) ? h : content.Pixels.Height;
|
|
@@ -504,6 +513,19 @@ export class SkiaControl {
|
|
|
504
513
|
if (this.MaximumHeightRequest >= 0 && reqH < 0)
|
|
505
514
|
rh = Math.min(rh, this.MaximumHeightRequest * scale);
|
|
506
515
|
this.MeasuredSize = ScaledSize.FromPixels(rw + mx, rh + my, scale);
|
|
516
|
+
// fit-content: what the content needs (never more than the constraint), with the requests and min / max
|
|
517
|
+
const fit = this.fitContentPixels ?? { Width: content.Pixels.Width, Height: content.Pixels.Height };
|
|
518
|
+
let fw = locked || reqW >= 0 ? w : Math.min(fit.Width, isFinite(w) ? w : fit.Width);
|
|
519
|
+
let fh = locked || reqH >= 0 ? h : Math.min(fit.Height, isFinite(h) ? h : fit.Height);
|
|
520
|
+
if (this.MinimumWidthRequest >= 0)
|
|
521
|
+
fw = Math.max(fw, this.MinimumWidthRequest * scale);
|
|
522
|
+
if (this.MinimumHeightRequest >= 0)
|
|
523
|
+
fh = Math.max(fh, this.MinimumHeightRequest * scale);
|
|
524
|
+
if (this.MaximumWidthRequest >= 0 && reqW < 0)
|
|
525
|
+
fw = Math.min(fw, this.MaximumWidthRequest * scale);
|
|
526
|
+
if (this.MaximumHeightRequest >= 0 && reqH < 0)
|
|
527
|
+
fh = Math.min(fh, this.MaximumHeightRequest * scale);
|
|
528
|
+
this.FitPixels = { Width: fw + mx, Height: fh + my };
|
|
507
529
|
this.NeedMeasure = false;
|
|
508
530
|
return this.MeasuredSize;
|
|
509
531
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drawnui-react",
|
|
3
|
-
"version": "0.1.0-preview.
|
|
3
|
+
"version": "0.1.0-preview.35",
|
|
4
4
|
"description": "DrawnUi for React: the DrawnUi (.NET) drawn-UI engine in TypeScript on CanvasKit (Skia WASM). Same controls, same PascalCase API as DrawnUi.Net.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Nick Kovalsky (AppoMobi)",
|
|
@@ -88,6 +88,9 @@
|
|
|
88
88
|
"check:shaping": "node dev/check.mjs dev/check-shaping.ts",
|
|
89
89
|
"check:editor-rtl": "node dev/check.mjs dev/check-editor-rtl.ts",
|
|
90
90
|
"check:label-direction": "node dev/check.mjs dev/check-label-direction.ts",
|
|
91
|
+
"check:stack-fit": "node dev/check.mjs dev/check-stack-fit.ts",
|
|
92
|
+
"check:label-reuse": "node dev/check.mjs dev/check-label-reuse.ts",
|
|
93
|
+
"bench:relayout": "node dev/check.mjs dev/bench-relayout.ts",
|
|
91
94
|
"site:extras": "node dev/site-extras.mjs dist/demo",
|
|
92
95
|
"build:lib": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
93
96
|
"prepublishOnly": "npm run build:lib",
|