@native-sdk/cli 0.9.1 → 0.9.2
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/build/app.zig +26 -9
- package/build.zig +55 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/skill-data/native-ui/SKILL.md +7 -7
- package/skill-data/ts-core/SKILL.md +1 -1
- package/src/app_runner/root.zig +93 -6
- package/src/app_runner/ts_core_main.zig +4 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +192 -40
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +154 -9
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ui_app.zig +9 -3
- package/src/runtime/ui_app_tests.zig +119 -19
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/web_engine.zig +1 -1
|
@@ -45,6 +45,7 @@ const widgetLineHeight = widget_metrics.widgetLineHeight;
|
|
|
45
45
|
const widgetDefaultRowHeight = widget_metrics.widgetDefaultRowHeight;
|
|
46
46
|
const widgetButtonInset = widget_metrics.widgetButtonInset;
|
|
47
47
|
const widgetControlInset = widget_metrics.widgetControlInset;
|
|
48
|
+
const widgetAlertInset = widget_metrics.widgetAlertInset;
|
|
48
49
|
const widgetSizedDensityValue = widget_metrics.widgetSizedDensityValue;
|
|
49
50
|
const densityValue = widget_metrics.densityValue;
|
|
50
51
|
const widgetControlHeight = widget_metrics.widgetControlHeight;
|
|
@@ -58,7 +59,7 @@ pub const max_widget_depth: usize = 32;
|
|
|
58
59
|
|
|
59
60
|
pub fn layoutWidgetDepth(
|
|
60
61
|
widget: Widget,
|
|
61
|
-
|
|
62
|
+
proposed_frame: geometry.RectF,
|
|
62
63
|
parent_index: ?usize,
|
|
63
64
|
depth: usize,
|
|
64
65
|
output: []WidgetLayoutNode,
|
|
@@ -69,15 +70,20 @@ pub fn layoutWidgetDepth(
|
|
|
69
70
|
if (len.* >= output.len) return error.WidgetLayoutListFull;
|
|
70
71
|
|
|
71
72
|
const index = len.*;
|
|
73
|
+
const root_bounds = if (index == 0) proposed_frame else output[0].frame;
|
|
74
|
+
const frame = rootRelativeModalFrame(widget, proposed_frame, root_bounds, tokens, depth);
|
|
72
75
|
output[index] = .{
|
|
73
76
|
.widget = widgetWithFrame(widget, frame),
|
|
74
|
-
|
|
77
|
+
// During the root's recursive layout its node frame carries the
|
|
78
|
+
// viewport so nested modals and anchors can resolve in window
|
|
79
|
+
// space. Restore the root's own resolved frame before returning.
|
|
80
|
+
.frame = if (index == 0) root_bounds else frame,
|
|
75
81
|
.depth = depth,
|
|
76
82
|
.parent_index = parent_index,
|
|
77
83
|
};
|
|
78
84
|
len.* += 1;
|
|
79
85
|
|
|
80
|
-
const layout_padding =
|
|
86
|
+
const layout_padding = widgetLayoutPadding(widget, tokens);
|
|
81
87
|
const content = windowControlsClearedContent(frame.inset(layout_padding), widget, tokens);
|
|
82
88
|
switch (widget.kind) {
|
|
83
89
|
.row, .breadcrumb, .pagination, .radio_group, .toggle_group => try layoutAxisChildren(widget.children, content, .horizontal, index, depth, output, len, widget.layout, tokens),
|
|
@@ -129,7 +135,7 @@ pub fn layoutWidgetDepth(
|
|
|
129
135
|
// (plus whatever stacks below it) moves.
|
|
130
136
|
const child_content = accordionContentFrame(widget, content, tokens, depth);
|
|
131
137
|
for (widget.children) |child| {
|
|
132
|
-
if (child
|
|
138
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
133
139
|
_ = try layoutWidgetDepth(child, stackChildFrame(child_content, child, tokens), index, depth + 1, output, len, tokens);
|
|
134
140
|
}
|
|
135
141
|
},
|
|
@@ -139,13 +145,23 @@ pub fn layoutWidgetDepth(
|
|
|
139
145
|
// title line — the standard callout grid.
|
|
140
146
|
const child_content = alertContentFrame(widget, content, tokens);
|
|
141
147
|
for (widget.children) |child| {
|
|
142
|
-
if (child
|
|
148
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
143
149
|
_ = try layoutWidgetDepth(child, stackChildFrame(child_content, child, tokens), index, depth + 1, output, len, tokens);
|
|
144
150
|
}
|
|
145
151
|
},
|
|
146
|
-
.stack, .bubble, .card, .
|
|
152
|
+
.stack, .bubble, .card, .resizable, .panel, .popover => {
|
|
153
|
+
for (widget.children) |child| {
|
|
154
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
155
|
+
_ = try layoutWidgetDepth(child, stackChildFrame(content, child, tokens), index, depth + 1, output, len, tokens);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
// Modal surfaces own root-relative geometry: the dialog centers,
|
|
159
|
+
// the drawer pins to the bottom edge, and the sheet pins right.
|
|
160
|
+
// Their content still uses the stacking-surface contract inside
|
|
161
|
+
// that resolved frame.
|
|
162
|
+
.dialog, .drawer, .sheet => {
|
|
147
163
|
for (widget.children) |child| {
|
|
148
|
-
if (child
|
|
164
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
149
165
|
_ = try layoutWidgetDepth(child, stackChildFrame(content, child, tokens), index, depth + 1, output, len, tokens);
|
|
150
166
|
}
|
|
151
167
|
},
|
|
@@ -160,9 +176,10 @@ pub fn layoutWidgetDepth(
|
|
|
160
176
|
.icon, .image, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .progress, .separator, .skeleton, .spinner, .chart, .split_divider, .media_surface, .terminal => {},
|
|
161
177
|
}
|
|
162
178
|
|
|
163
|
-
//
|
|
164
|
-
// consume no parent space) and positioned here
|
|
165
|
-
//
|
|
179
|
+
// Root-relative modals and anchored floating children are excluded from
|
|
180
|
+
// every flow above (they consume no parent space) and positioned here
|
|
181
|
+
// instead. Modal roots resolve against the window first; anchored roots
|
|
182
|
+
// then resolve against this widget's frame and the window.
|
|
166
183
|
// Leaf trigger kinds (select, button, ...) never lay out flow
|
|
167
184
|
// children, but their anchored children float all the same.
|
|
168
185
|
// A drag header's anchor base is trimmed clear of the stamped
|
|
@@ -170,11 +187,66 @@ pub fn layoutWidgetDepth(
|
|
|
170
187
|
// collision scan counts anchored descendants too, so the remedy must
|
|
171
188
|
// move them or the one retry is paid for nothing. Non-drag widgets
|
|
172
189
|
// pass through untouched (menus and popovers anchor everywhere).
|
|
173
|
-
try
|
|
190
|
+
try layoutRootRelativeModalChildren(widget.children, index, depth, output, len, root_bounds, tokens);
|
|
191
|
+
try layoutAnchoredChildren(widget.children, windowControlsClearedContent(frame, widget, tokens), index, depth, output, len, root_bounds, tokens);
|
|
192
|
+
|
|
193
|
+
if (index == 0) output[index].frame = frame;
|
|
174
194
|
|
|
175
195
|
return index;
|
|
176
196
|
}
|
|
177
197
|
|
|
198
|
+
fn rootRelativeModalFrame(widget: Widget, proposed: geometry.RectF, root: geometry.RectF, tokens: DesignTokens, depth: usize) geometry.RectF {
|
|
199
|
+
const kind: widget_model.BuiltinComponentKind = switch (widget.kind) {
|
|
200
|
+
.dialog => .dialog,
|
|
201
|
+
.drawer => .drawer,
|
|
202
|
+
.sheet => .sheet,
|
|
203
|
+
else => return proposed,
|
|
204
|
+
};
|
|
205
|
+
const intrinsic = intrinsicWidgetSizeDepth(widget, tokens, depth);
|
|
206
|
+
const preferred = geometry.SizeF.init(
|
|
207
|
+
clampIntrinsicAxis(if (widget.frame.width > 0) widget.frame.width else intrinsic.width, widget.layout.min_size.width, widget.layout.max_size.width),
|
|
208
|
+
clampIntrinsicAxis(if (widget.frame.height > 0) widget.frame.height else intrinsic.height, widget.layout.min_size.height, widget.layout.max_size.height),
|
|
209
|
+
);
|
|
210
|
+
return widget_model.builtinSurfaceFrame(kind, .{
|
|
211
|
+
.bounds = root,
|
|
212
|
+
.preferred_size = preferred,
|
|
213
|
+
}) orelse proposed;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fn widgetTakesFlowSlot(widget: Widget) bool {
|
|
217
|
+
return !widget_tree.widgetEscapesAncestorClips(widget);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
fn widgetFlowChildCount(children: []const Widget) usize {
|
|
221
|
+
var count: usize = 0;
|
|
222
|
+
for (children) |child| {
|
|
223
|
+
if (widgetTakesFlowSlot(child)) count += 1;
|
|
224
|
+
}
|
|
225
|
+
return count;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
fn firstWidgetFlowChild(children: []const Widget) ?Widget {
|
|
229
|
+
for (children) |child| {
|
|
230
|
+
if (widgetTakesFlowSlot(child)) return child;
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fn layoutRootRelativeModalChildren(
|
|
236
|
+
children: []const Widget,
|
|
237
|
+
parent_index: usize,
|
|
238
|
+
depth: usize,
|
|
239
|
+
output: []WidgetLayoutNode,
|
|
240
|
+
len: *usize,
|
|
241
|
+
root_bounds: geometry.RectF,
|
|
242
|
+
tokens: DesignTokens,
|
|
243
|
+
) Error!void {
|
|
244
|
+
for (children) |child| {
|
|
245
|
+
if (!widget_tree.widgetIsRootRelativeModal(child)) continue;
|
|
246
|
+
_ = try layoutWidgetDepth(child, root_bounds, parent_index, depth + 1, output, len, tokens);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
178
250
|
/// Lay a drag header's content out clear of the OS window-control
|
|
179
251
|
/// cluster. On hidden-titlebar windows the content extends under the
|
|
180
252
|
/// system's control band, and the cluster sits ON the content at one
|
|
@@ -317,15 +389,113 @@ fn layoutAnchoredChildren(
|
|
|
317
389
|
depth: usize,
|
|
318
390
|
output: []WidgetLayoutNode,
|
|
319
391
|
len: *usize,
|
|
392
|
+
root_bounds: geometry.RectF,
|
|
320
393
|
tokens: DesignTokens,
|
|
321
394
|
) Error!void {
|
|
322
395
|
for (children) |child| {
|
|
396
|
+
if (widget_tree.widgetIsRootRelativeModal(child)) continue;
|
|
323
397
|
const anchor = child.layout.anchor orelse continue;
|
|
324
|
-
const child_frame = anchoredWidgetFrame(child, anchor, anchor_rect,
|
|
398
|
+
const child_frame = anchoredWidgetFrame(child, anchor, anchor_rect, root_bounds, tokens);
|
|
325
399
|
_ = try layoutWidgetDepth(child, child_frame, parent_index, depth + 1, output, len, tokens);
|
|
326
400
|
}
|
|
327
401
|
}
|
|
328
402
|
|
|
403
|
+
/// Re-run every anchored-child pass IN PLACE after a runtime geometry
|
|
404
|
+
/// reconciliation moved laid frames (retained scroll restoration, an
|
|
405
|
+
/// engine clamp, or another post-layout adjustment). Each laid parent still
|
|
406
|
+
/// carries its source children until adoption, so this recovers the authored
|
|
407
|
+
/// surface size and re-applies flip/window clamping against the parent's
|
|
408
|
+
/// FINAL frame instead of translating a surface that was clamped against a
|
|
409
|
+
/// stale pre-reconcile anchor. The original layout already charged the node
|
|
410
|
+
/// and anchored-surface budgets; this pass rewrites the same pre-order slots
|
|
411
|
+
/// and allocates none.
|
|
412
|
+
pub fn anchoredNestingDepth(output: []const WidgetLayoutNode, node_index: usize) usize {
|
|
413
|
+
if (node_index >= output.len) return 0;
|
|
414
|
+
var count: usize = 0;
|
|
415
|
+
var current: ?usize = node_index;
|
|
416
|
+
while (current) |index| {
|
|
417
|
+
if (index >= output.len) break;
|
|
418
|
+
if (widget_tree.widgetIsAnchored(output[index].widget)) count += 1;
|
|
419
|
+
current = output[index].parent_index;
|
|
420
|
+
}
|
|
421
|
+
return count;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
pub fn maxAnchoredNestingDepth(output: []const WidgetLayoutNode) usize {
|
|
425
|
+
var max_depth: usize = 0;
|
|
426
|
+
for (output, 0..) |node, index| {
|
|
427
|
+
if (!widget_tree.widgetIsAnchored(node.widget)) continue;
|
|
428
|
+
max_depth = @max(max_depth, anchoredNestingDepth(output, index));
|
|
429
|
+
}
|
|
430
|
+
return max_depth;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/// Re-layout only the anchored roots whose authored parent lives in the
|
|
434
|
+
/// requested anchored-surface stratum. Runtime reconciliation uses this
|
|
435
|
+
/// top-down: finalize the outer geometry, replay its direct surfaces, then
|
|
436
|
+
/// restore state inside those surfaces before replaying their nested ones.
|
|
437
|
+
pub fn relayoutAnchoredChildrenAtDepth(output: []WidgetLayoutNode, root_bounds: geometry.RectF, tokens: DesignTokens, parent_anchored_depth: usize) Error!void {
|
|
438
|
+
if (output.len == 0) return;
|
|
439
|
+
// Partial re-layout enters below the already-resolved root. Mirror the
|
|
440
|
+
// full layout's construction-time root frame so recursive modal and
|
|
441
|
+
// nested-anchor layout still reads the viewport, then restore the live
|
|
442
|
+
// root surface frame before returning.
|
|
443
|
+
const root_frame = output[0].frame;
|
|
444
|
+
output[0].frame = root_bounds;
|
|
445
|
+
defer output[0].frame = root_frame;
|
|
446
|
+
// The layout sequence puts a parent's anchored children after every
|
|
447
|
+
// in-flow descendant. Walk directly to those anchored roots instead of
|
|
448
|
+
// searching every parent's subtree: rebuilds with no open surface stay
|
|
449
|
+
// O(nodes), and an open surface pays only for the bounded anchored
|
|
450
|
+
// subtrees that are actually replayed.
|
|
451
|
+
var anchored_start: usize = 1;
|
|
452
|
+
while (anchored_start < output.len) {
|
|
453
|
+
const anchored = output[anchored_start];
|
|
454
|
+
if (anchored.widget.layout.anchor == null) {
|
|
455
|
+
anchored_start += 1;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const parent_index = anchored.parent_index orelse {
|
|
459
|
+
anchored_start += 1;
|
|
460
|
+
continue;
|
|
461
|
+
};
|
|
462
|
+
if (anchoredNestingDepth(output, parent_index) != parent_anchored_depth) {
|
|
463
|
+
anchored_start += 1;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const parent = output[parent_index];
|
|
467
|
+
var len = anchored_start;
|
|
468
|
+
try layoutAnchoredChildren(
|
|
469
|
+
parent.widget.children,
|
|
470
|
+
windowControlsClearedContent(parent.frame, parent.widget, tokens),
|
|
471
|
+
parent_index,
|
|
472
|
+
parent.depth,
|
|
473
|
+
output,
|
|
474
|
+
&len,
|
|
475
|
+
root_bounds,
|
|
476
|
+
tokens,
|
|
477
|
+
);
|
|
478
|
+
// Replaying one anchored root lays every anchored sibling belonging
|
|
479
|
+
// to that parent, plus any nested anchored descendants. Resume at
|
|
480
|
+
// the first untouched node. A malformed retained tree whose source
|
|
481
|
+
// has no matching anchored child still makes forward progress.
|
|
482
|
+
anchored_start = if (len > anchored_start) len else anchored_start + 1;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
pub fn relayoutAnchoredChildren(output: []WidgetLayoutNode, tokens: DesignTokens) Error!void {
|
|
487
|
+
if (output.len == 0) return;
|
|
488
|
+
try relayoutAnchoredChildrenWithRootBounds(output, output[0].frame, tokens);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
pub fn relayoutAnchoredChildrenWithRootBounds(output: []WidgetLayoutNode, root_bounds: geometry.RectF, tokens: DesignTokens) Error!void {
|
|
492
|
+
const max_depth = maxAnchoredNestingDepth(output);
|
|
493
|
+
var parent_depth: usize = 0;
|
|
494
|
+
while (parent_depth < max_depth) : (parent_depth += 1) {
|
|
495
|
+
try relayoutAnchoredChildrenAtDepth(output, root_bounds, tokens, parent_depth);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
329
499
|
/// Resolved frame of an anchored floating widget: sized from its explicit
|
|
330
500
|
/// frame or intrinsic content (`stretch` widens to at least the anchor's
|
|
331
501
|
/// width), placed on the preferred side of the anchor rect — flipping to
|
|
@@ -505,6 +675,19 @@ fn tabsLayoutPadding(widget: Widget, tokens: DesignTokens) geometry.InsetsF {
|
|
|
505
675
|
return geometry.InsetsF.all(underlineTabsListInset(tokens));
|
|
506
676
|
}
|
|
507
677
|
|
|
678
|
+
fn alertLayoutPadding(widget: Widget, tokens: DesignTokens) geometry.InsetsF {
|
|
679
|
+
if (!widget.layout.padding_is_kind_default) return widget.layout.padding;
|
|
680
|
+
return geometry.InsetsF.all(widgetAlertInset(widget, tokens));
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
fn widgetLayoutPadding(widget: Widget, tokens: DesignTokens) geometry.InsetsF {
|
|
684
|
+
return switch (widget.kind) {
|
|
685
|
+
.tabs => tabsLayoutPadding(widget, tokens),
|
|
686
|
+
.alert => alertLayoutPadding(widget, tokens),
|
|
687
|
+
else => widget.layout.padding,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
|
|
508
691
|
fn layoutAxisChildren(
|
|
509
692
|
children: []const Widget,
|
|
510
693
|
content: geometry.RectF,
|
|
@@ -538,12 +721,12 @@ fn layoutAxisChildrenMode(
|
|
|
538
721
|
comptime fill_primary_tabs: bool,
|
|
539
722
|
comptime stretch_tab_triggers: bool,
|
|
540
723
|
) Error!void {
|
|
541
|
-
//
|
|
542
|
-
//
|
|
543
|
-
//
|
|
724
|
+
// Window-level surfaces take no flow slot: they are skipped in every
|
|
725
|
+
// pass here (measurement, gap counting, placement) and laid out by the
|
|
726
|
+
// window-surface passes against the parent/window instead.
|
|
544
727
|
var flow_count: usize = 0;
|
|
545
728
|
for (children) |child| {
|
|
546
|
-
if (child
|
|
729
|
+
if (widgetTakesFlowSlot(child)) flow_count += 1;
|
|
547
730
|
}
|
|
548
731
|
if (flow_count == 0) return;
|
|
549
732
|
|
|
@@ -561,7 +744,7 @@ fn layoutAxisChildrenMode(
|
|
|
561
744
|
var grow_total: f32 = 0;
|
|
562
745
|
var fill_width_count: usize = 0;
|
|
563
746
|
for (children) |child| {
|
|
564
|
-
if (child
|
|
747
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
565
748
|
const implicitly_fills = if (comptime fill_primary_tabs) axisChildImplicitlyFillsWidth(child) else false;
|
|
566
749
|
if (implicitly_fills) {
|
|
567
750
|
fill_width_count += 1;
|
|
@@ -588,7 +771,7 @@ fn layoutAxisChildrenMode(
|
|
|
588
771
|
if (comptime fill_primary_tabs) {
|
|
589
772
|
if (fill_width_count > 0) {
|
|
590
773
|
for (children) |child| {
|
|
591
|
-
if (child
|
|
774
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
592
775
|
if (!axisChildImplicitlyFillsWidth(child)) continue;
|
|
593
776
|
fill_width_extent += axisChildImplicitFillExtent(child, axis, fill_width_share, tokens);
|
|
594
777
|
}
|
|
@@ -611,7 +794,7 @@ fn layoutAxisChildrenMode(
|
|
|
611
794
|
} + mainAxisAlignmentOffset(style.main_alignment, free_extent);
|
|
612
795
|
|
|
613
796
|
for (children) |child| {
|
|
614
|
-
if (child
|
|
797
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
615
798
|
const grow = nonNegative(child.layout.grow);
|
|
616
799
|
const implicitly_fills = if (comptime fill_primary_tabs) axisChildImplicitlyFillsWidth(child) else false;
|
|
617
800
|
const main_extent = if (implicitly_fills)
|
|
@@ -666,16 +849,15 @@ pub var test_axis_overflow_diagnostics: usize = 0;
|
|
|
666
849
|
/// operating mode — the scroll exists precisely to reveal it — so the
|
|
667
850
|
/// vertical overflow diagnostic must stay quiet there. The walk is the
|
|
668
851
|
/// same rule the layout audit applies (`scopeScrollsVertically`), which
|
|
669
|
-
/// is why the audit was already clean on these shapes.
|
|
670
|
-
///
|
|
671
|
-
///
|
|
672
|
-
/// like the audit's clip-scope walk.
|
|
852
|
+
/// is why the audit was already clean on these shapes. Window-level
|
|
853
|
+
/// surfaces hoist out of every ancestor scope, so the walk stops at that
|
|
854
|
+
/// boundary just like the audit's clip-scope walk.
|
|
673
855
|
fn widgetInsideVerticalScrollScope(output: []const WidgetLayoutNode, parent_index: usize) bool {
|
|
674
856
|
var current: ?usize = parent_index;
|
|
675
857
|
while (current) |index| {
|
|
676
858
|
const widget = output[index].widget;
|
|
677
859
|
if ((widget.kind == .scroll_view and widget.scroll_axes.scrollsVertically()) or widget.layout.virtualized) return true;
|
|
678
|
-
if (widget
|
|
860
|
+
if (widget_tree.widgetEscapesAncestorClips(widget)) return false;
|
|
679
861
|
current = output[index].parent_index;
|
|
680
862
|
}
|
|
681
863
|
return false;
|
|
@@ -690,7 +872,7 @@ fn widgetInsideHorizontalScrollScope(output: []const WidgetLayoutNode, parent_in
|
|
|
690
872
|
while (current) |index| {
|
|
691
873
|
const widget = output[index].widget;
|
|
692
874
|
if (widget.kind == .scroll_view and widget.scroll_axes.scrollsHorizontally() and !widget.layout.virtualized) return true;
|
|
693
|
-
if (widget
|
|
875
|
+
if (widget_tree.widgetEscapesAncestorClips(widget)) return false;
|
|
694
876
|
current = output[index].parent_index;
|
|
695
877
|
}
|
|
696
878
|
return false;
|
|
@@ -826,7 +1008,7 @@ fn widgetSubtreeHasTextSpans(widget: Widget, depth: usize) bool {
|
|
|
826
1008
|
fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignTokens, depth: usize) f32 {
|
|
827
1009
|
if (depth >= max_widget_depth) return preferredMainExtent(widget, .vertical, tokens);
|
|
828
1010
|
if (widget.frame.height > 0) return clampMainExtent(widget, .vertical, widget.frame.height);
|
|
829
|
-
const padding = widget
|
|
1011
|
+
const padding = widgetLayoutPadding(widget, tokens);
|
|
830
1012
|
const inner_width = @max(0, width - padding.left - padding.right);
|
|
831
1013
|
const content_height: f32 = switch (widget.kind) {
|
|
832
1014
|
.text => if (widget.spans.len > 0)
|
|
@@ -838,7 +1020,7 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
838
1020
|
else if (widget.children.len > 0) blk: {
|
|
839
1021
|
var max_height: f32 = 0;
|
|
840
1022
|
for (widget.children, 0..) |child, index| {
|
|
841
|
-
if (child
|
|
1023
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
842
1024
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(
|
|
843
1025
|
child,
|
|
844
1026
|
rowChildWidth(widget, inner_width, index, tokens),
|
|
@@ -853,7 +1035,7 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
853
1035
|
var sum: f32 = 0;
|
|
854
1036
|
var flow_count: usize = 0;
|
|
855
1037
|
for (widget.children) |child| {
|
|
856
|
-
if (child
|
|
1038
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
857
1039
|
// A column-direct bubble hugs up to the thread fraction
|
|
858
1040
|
// (the cross-extent seam), so its wrapped height must
|
|
859
1041
|
// measure at that same capped width.
|
|
@@ -874,7 +1056,7 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
874
1056
|
.stack, .panel, .card, .bubble, .resizable, .popover => blk: {
|
|
875
1057
|
var max_height: f32 = 0;
|
|
876
1058
|
for (widget.children) |child| {
|
|
877
|
-
if (child
|
|
1059
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
878
1060
|
const child_width = if (child.frame.width > 0) child.frame.width else inner_width;
|
|
879
1061
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(child, child_width, tokens, depth + 1));
|
|
880
1062
|
}
|
|
@@ -885,19 +1067,19 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
885
1067
|
// measure at the indented width with the title's line reserved.
|
|
886
1068
|
.alert => blk: {
|
|
887
1069
|
const text_size = widgetBodyTextSize(widget, tokens);
|
|
888
|
-
const inset =
|
|
1070
|
+
const inset = widgetAlertInset(widget, tokens);
|
|
889
1071
|
const icon_size = widgetSizedDensityValue(widget, tokens, 16);
|
|
890
1072
|
const text_gap = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
891
1073
|
const indent = if (widget.text.len > 0) icon_size + text_gap else 0;
|
|
892
1074
|
var max_height: f32 = 0;
|
|
893
1075
|
for (widget.children) |child| {
|
|
894
|
-
if (child
|
|
1076
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
895
1077
|
const child_width = if (child.frame.width > 0) child.frame.width else @max(0, inner_width - indent);
|
|
896
1078
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(child, child_width, tokens, depth + 1));
|
|
897
1079
|
}
|
|
898
1080
|
var content = max_height;
|
|
899
1081
|
if (widget.text.len > 0) {
|
|
900
|
-
const title_gap =
|
|
1082
|
+
const title_gap = densityValue(tokens, tokens.spacing.xs);
|
|
901
1083
|
content = widgetLineHeight(text_size) + (if (max_height > 0) title_gap + max_height else 0);
|
|
902
1084
|
}
|
|
903
1085
|
// The same floor `intrinsicAlertWidgetSize` keeps, so wrapped
|
|
@@ -913,7 +1095,7 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
913
1095
|
if (!accordionChildrenVisible(widget)) break :blk header_height;
|
|
914
1096
|
var max_height: f32 = 0;
|
|
915
1097
|
for (widget.children) |child| {
|
|
916
|
-
if (child
|
|
1098
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
917
1099
|
const child_width = if (child.frame.width > 0) child.frame.width else inner_width;
|
|
918
1100
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(child, child_width, tokens, depth + 1));
|
|
919
1101
|
}
|
|
@@ -923,7 +1105,7 @@ fn wrappedVerticalExtentForWidth(widget: Widget, width: f32, tokens: DesignToken
|
|
|
923
1105
|
.row, .data_row, .breadcrumb, .button_group, .pagination, .radio_group, .tabs, .toggle_group => blk: {
|
|
924
1106
|
var max_height: f32 = 0;
|
|
925
1107
|
for (widget.children, 0..) |child, index| {
|
|
926
|
-
if (child
|
|
1108
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
927
1109
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(
|
|
928
1110
|
child,
|
|
929
1111
|
rowChildWidth(widget, inner_width, index, tokens),
|
|
@@ -957,7 +1139,7 @@ fn rowChildWidthMode(row: Widget, available_width: f32, index: usize, tokens: De
|
|
|
957
1139
|
var grow_total: f32 = 0;
|
|
958
1140
|
var fill_width_count: usize = 0;
|
|
959
1141
|
for (children) |child| {
|
|
960
|
-
if (child
|
|
1142
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
961
1143
|
flow_count += 1;
|
|
962
1144
|
const implicitly_fills = if (comptime fill_primary_tabs) axisChildImplicitlyFillsWidth(child) else false;
|
|
963
1145
|
if (implicitly_fills) {
|
|
@@ -990,7 +1172,7 @@ fn rowChildWidthMode(row: Widget, available_width: f32, index: usize, tokens: De
|
|
|
990
1172
|
if (comptime fill_primary_tabs) {
|
|
991
1173
|
if (fill_width_count > 0) {
|
|
992
1174
|
for (children) |candidate| {
|
|
993
|
-
if (candidate
|
|
1175
|
+
if (!widgetTakesFlowSlot(candidate)) continue;
|
|
994
1176
|
if (!axisChildImplicitlyFillsWidth(candidate)) continue;
|
|
995
1177
|
fill_width_extent += axisChildImplicitFillExtent(candidate, .horizontal, fill_width_share, tokens);
|
|
996
1178
|
}
|
|
@@ -1056,7 +1238,7 @@ fn layoutTextSpanLinkChildren(
|
|
|
1056
1238
|
if (child_index >= widget.children.len) break;
|
|
1057
1239
|
const child = widget.children[child_index];
|
|
1058
1240
|
child_index += 1;
|
|
1059
|
-
if (child
|
|
1241
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1060
1242
|
const frame = if (text_spans_model.textSpanBounds(layout, span_index)) |bounds|
|
|
1061
1243
|
geometry.RectF.init(content.x + bounds.x, content.y + bounds.y, bounds.width, bounds.height)
|
|
1062
1244
|
else
|
|
@@ -1064,7 +1246,7 @@ fn layoutTextSpanLinkChildren(
|
|
|
1064
1246
|
_ = try layoutWidgetDepth(child, frame, parent_index, depth + 1, output, len, tokens);
|
|
1065
1247
|
}
|
|
1066
1248
|
while (child_index < widget.children.len) : (child_index += 1) {
|
|
1067
|
-
if (widget.children[child_index]
|
|
1249
|
+
if (!widgetTakesFlowSlot(widget.children[child_index])) continue;
|
|
1068
1250
|
_ = try layoutWidgetDepth(widget.children[child_index], geometry.RectF.init(content.x, content.y, 0, 0), parent_index, depth + 1, output, len, tokens);
|
|
1069
1251
|
}
|
|
1070
1252
|
}
|
|
@@ -1073,7 +1255,7 @@ fn assignedAxisChildrenExtent(children: []const Widget, axis: LayoutAxis, fixed_
|
|
|
1073
1255
|
if (grow_total <= 0) return fixed_extent;
|
|
1074
1256
|
var assigned = fixed_extent;
|
|
1075
1257
|
for (children) |child| {
|
|
1076
|
-
if (child
|
|
1258
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1077
1259
|
const grow = nonNegative(child.layout.grow);
|
|
1078
1260
|
if (grow <= 0) continue;
|
|
1079
1261
|
assigned += clampMainExtent(child, axis, remaining * grow / grow_total);
|
|
@@ -1128,21 +1310,23 @@ fn layoutGridChildren(
|
|
|
1128
1310
|
requested_columns: usize,
|
|
1129
1311
|
tokens: DesignTokens,
|
|
1130
1312
|
) Error!void {
|
|
1131
|
-
|
|
1313
|
+
const flow_count = widgetFlowChildCount(children);
|
|
1314
|
+
if (flow_count == 0) return;
|
|
1132
1315
|
|
|
1133
|
-
const columns = gridColumnCount(
|
|
1134
|
-
const rows = gridRowCount(
|
|
1316
|
+
const columns = gridColumnCount(flow_count, requested_columns);
|
|
1317
|
+
const rows = gridRowCount(flow_count, columns);
|
|
1135
1318
|
const clamped_gap = nonNegative(gap);
|
|
1136
1319
|
const total_column_gap = clamped_gap * @as(f32, @floatFromInt(columns - 1));
|
|
1137
1320
|
const total_row_gap = clamped_gap * @as(f32, @floatFromInt(rows - 1));
|
|
1138
1321
|
const cell_width = if (columns > 0) @max(0, content.width - total_column_gap) / @as(f32, @floatFromInt(columns)) else 0;
|
|
1139
1322
|
const fallback_cell_height = if (rows > 0) @max(0, content.height - total_row_gap) / @as(f32, @floatFromInt(rows)) else 0;
|
|
1140
1323
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
if (child
|
|
1144
|
-
const column =
|
|
1145
|
-
const row =
|
|
1324
|
+
var flow_index: usize = 0;
|
|
1325
|
+
for (children) |child| {
|
|
1326
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1327
|
+
const column = flow_index % columns;
|
|
1328
|
+
const row = flow_index / columns;
|
|
1329
|
+
flow_index += 1;
|
|
1146
1330
|
const x = content.x + @as(f32, @floatFromInt(column)) * (cell_width + clamped_gap);
|
|
1147
1331
|
const y = content.y + @as(f32, @floatFromInt(row)) * (fallback_cell_height + clamped_gap);
|
|
1148
1332
|
const width = gridChildWidth(child, cell_width, tokens);
|
|
@@ -1168,10 +1352,11 @@ fn layoutVirtualGridChildren(
|
|
|
1168
1352
|
style: WidgetLayoutStyle,
|
|
1169
1353
|
tokens: DesignTokens,
|
|
1170
1354
|
) Error!void {
|
|
1171
|
-
|
|
1355
|
+
const flow_count = widgetFlowChildCount(children);
|
|
1356
|
+
if (flow_count == 0) return;
|
|
1172
1357
|
|
|
1173
|
-
const columns = gridColumnCount(
|
|
1174
|
-
const rows = gridRowCount(
|
|
1358
|
+
const columns = gridColumnCount(flow_count, style.columns);
|
|
1359
|
+
const rows = gridRowCount(flow_count, columns);
|
|
1175
1360
|
if (columns == 0 or rows == 0) return;
|
|
1176
1361
|
|
|
1177
1362
|
const clamped_gap = nonNegative(style.gap);
|
|
@@ -1194,29 +1379,28 @@ fn layoutVirtualGridChildren(
|
|
|
1194
1379
|
if (range.isEmpty()) return;
|
|
1195
1380
|
|
|
1196
1381
|
const stride = range.item_extent + range.item_gap;
|
|
1197
|
-
var
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
}
|
|
1382
|
+
var flow_index: usize = 0;
|
|
1383
|
+
for (children) |source| {
|
|
1384
|
+
if (!widgetTakesFlowSlot(source)) continue;
|
|
1385
|
+
defer flow_index += 1;
|
|
1386
|
+
const row = flow_index / columns;
|
|
1387
|
+
if (row < range.start_index or row >= range.end_index) continue;
|
|
1388
|
+
const column = flow_index % columns;
|
|
1389
|
+
|
|
1390
|
+
var child = source;
|
|
1391
|
+
child.semantics.list_item_index = saturatingU32(flow_index);
|
|
1392
|
+
child.semantics.list_item_count = saturatingU32(flow_count);
|
|
1393
|
+
const x = content.x + @as(f32, @floatFromInt(column)) * (cell_width + clamped_gap);
|
|
1394
|
+
const y = content.y + @as(f32, @floatFromInt(row)) * stride - range.layout_offset + child.frame.y;
|
|
1395
|
+
const width = gridChildWidth(child, cell_width, tokens);
|
|
1396
|
+
const height = clampIntrinsicAxis(if (child.frame.height > 0) child.frame.height else range.item_extent, child.layout.min_size.height, child.layout.max_size.height);
|
|
1397
|
+
const child_frame = geometry.RectF.init(
|
|
1398
|
+
x + child.frame.x,
|
|
1399
|
+
y,
|
|
1400
|
+
width,
|
|
1401
|
+
height,
|
|
1402
|
+
);
|
|
1403
|
+
_ = try layoutWidgetDepth(child, child_frame, parent_index, depth + 1, output, len, tokens);
|
|
1220
1404
|
}
|
|
1221
1405
|
}
|
|
1222
1406
|
|
|
@@ -1234,9 +1418,12 @@ fn gridChildWidth(child: Widget, cell_width: f32, tokens: DesignTokens) f32 {
|
|
|
1234
1418
|
fn preferredGridRowExtent(children: []const Widget, columns: usize, tokens: DesignTokens) f32 {
|
|
1235
1419
|
if (children.len == 0 or columns == 0) return 0;
|
|
1236
1420
|
var max_height: f32 = 0;
|
|
1237
|
-
var
|
|
1238
|
-
|
|
1239
|
-
|
|
1421
|
+
var flow_index: usize = 0;
|
|
1422
|
+
for (children) |child| {
|
|
1423
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1424
|
+
if (flow_index >= columns) break;
|
|
1425
|
+
max_height = @max(max_height, preferredMainExtent(child, .vertical, tokens));
|
|
1426
|
+
flow_index += 1;
|
|
1240
1427
|
}
|
|
1241
1428
|
return max_height;
|
|
1242
1429
|
}
|
|
@@ -1265,7 +1452,7 @@ fn layoutScrollChildren(
|
|
|
1265
1452
|
) Error!void {
|
|
1266
1453
|
const scrolled_content = content.translate(geometry.OffsetF.init(-scroll_offset.dx, -scroll_offset.dy));
|
|
1267
1454
|
for (children) |child| {
|
|
1268
|
-
if (child
|
|
1455
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1269
1456
|
var child_frame = stackChildFrame(scrolled_content, child, tokens);
|
|
1270
1457
|
// A `both` region must retain the same intrinsic width as a
|
|
1271
1458
|
// horizontal-only shelf; otherwise its horizontal axis has no
|
|
@@ -1289,7 +1476,8 @@ fn layoutVirtualVerticalChildren(
|
|
|
1289
1476
|
style: WidgetLayoutStyle,
|
|
1290
1477
|
tokens: DesignTokens,
|
|
1291
1478
|
) Error!void {
|
|
1292
|
-
|
|
1479
|
+
const flow_count = widgetFlowChildCount(children);
|
|
1480
|
+
if (flow_count == 0) return;
|
|
1293
1481
|
|
|
1294
1482
|
// A VARIABLE-extent windowed virtual list (`virtual_total_extent >
|
|
1295
1483
|
// 0`): the window's offset table already priced everything outside
|
|
@@ -1312,13 +1500,13 @@ fn layoutVirtualVerticalChildren(
|
|
|
1312
1500
|
// declared count: children are the full item set) is byte-identical.
|
|
1313
1501
|
const first_index = style.virtual_first_index;
|
|
1314
1502
|
const item_count = if (style.virtual_item_count > 0)
|
|
1315
|
-
@max(style.virtual_item_count, first_index +
|
|
1503
|
+
@max(style.virtual_item_count, first_index + flow_count)
|
|
1316
1504
|
else
|
|
1317
|
-
|
|
1505
|
+
flow_count;
|
|
1318
1506
|
const item_extent = if (style.virtual_item_extent > 0)
|
|
1319
1507
|
style.virtual_item_extent
|
|
1320
1508
|
else
|
|
1321
|
-
preferredMainExtent(children
|
|
1509
|
+
preferredMainExtent(firstWidgetFlowChild(children).?, .vertical, tokens);
|
|
1322
1510
|
const range = virtualListRange(.{
|
|
1323
1511
|
.item_count = item_count,
|
|
1324
1512
|
.item_extent = item_extent,
|
|
@@ -1332,11 +1520,13 @@ fn layoutVirtualVerticalChildren(
|
|
|
1332
1520
|
if (range.isEmpty()) return;
|
|
1333
1521
|
|
|
1334
1522
|
const stride = range.item_extent + range.item_gap;
|
|
1335
|
-
var
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1523
|
+
var flow_offset: usize = 0;
|
|
1524
|
+
for (children) |source| {
|
|
1525
|
+
if (!widgetTakesFlowSlot(source)) continue;
|
|
1526
|
+
defer flow_offset += 1;
|
|
1527
|
+
const index = first_index + flow_offset;
|
|
1528
|
+
if (index < range.start_index or index >= range.end_index) continue;
|
|
1529
|
+
var child = source;
|
|
1340
1530
|
child.semantics.list_item_index = saturatingU32(index);
|
|
1341
1531
|
child.semantics.list_item_count = saturatingU32(item_count);
|
|
1342
1532
|
const y = content.y + @as(f32, @floatFromInt(index)) * stride - range.layout_offset + child.frame.y;
|
|
@@ -1376,7 +1566,9 @@ fn layoutVariableVirtualChildren(
|
|
|
1376
1566
|
tokens: DesignTokens,
|
|
1377
1567
|
) Error!void {
|
|
1378
1568
|
const first_index = style.virtual_first_index;
|
|
1379
|
-
const
|
|
1569
|
+
const flow_count = widgetFlowChildCount(children);
|
|
1570
|
+
if (flow_count == 0) return;
|
|
1571
|
+
const item_count = @max(style.virtual_item_count, first_index + flow_count);
|
|
1380
1572
|
const gap = nonNegative(style.gap);
|
|
1381
1573
|
const total_extent = @max(0, style.virtual_total_extent);
|
|
1382
1574
|
const max_offset = @max(0, total_extent - content.height);
|
|
@@ -1385,7 +1577,7 @@ fn layoutVariableVirtualChildren(
|
|
|
1385
1577
|
|
|
1386
1578
|
output[parent_index].widget.semantics.list_item_count = saturatingU32(item_count);
|
|
1387
1579
|
|
|
1388
|
-
const anchor_child = std.math.clamp(style.virtual_anchor_index -| first_index, 0,
|
|
1580
|
+
const anchor_child = std.math.clamp(style.virtual_anchor_index -| first_index, 0, flow_count - 1);
|
|
1389
1581
|
const anchor_y = content.y + @max(0, style.virtual_anchor_extent) - layout_offset;
|
|
1390
1582
|
|
|
1391
1583
|
// Pre-pass: back the start edge out of the anchor position by the
|
|
@@ -1393,15 +1585,20 @@ fn layoutVariableVirtualChildren(
|
|
|
1393
1585
|
// emit every row in window order so layout-node order — which
|
|
1394
1586
|
// semantics and hit routing walk — matches the source order.
|
|
1395
1587
|
var y = anchor_y;
|
|
1396
|
-
|
|
1588
|
+
var flow_offset: usize = 0;
|
|
1589
|
+
for (children) |child| {
|
|
1590
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1591
|
+
if (flow_offset >= anchor_child) break;
|
|
1397
1592
|
y -= variableVirtualChildExtent(child, content.width, tokens, depth) + gap;
|
|
1593
|
+
flow_offset += 1;
|
|
1398
1594
|
}
|
|
1399
|
-
|
|
1595
|
+
flow_offset = 0;
|
|
1596
|
+
for (children) |child| {
|
|
1597
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1400
1598
|
const height = variableVirtualChildExtent(child, content.width, tokens, depth);
|
|
1401
|
-
|
|
1402
|
-
try layoutVariableVirtualChild(child, content, y, height, first_index + offset, item_count, parent_index, depth, output, len, tokens);
|
|
1403
|
-
}
|
|
1599
|
+
try layoutVariableVirtualChild(child, content, y, height, first_index + flow_offset, item_count, parent_index, depth, output, len, tokens);
|
|
1404
1600
|
y += height + gap;
|
|
1601
|
+
flow_offset += 1;
|
|
1405
1602
|
}
|
|
1406
1603
|
}
|
|
1407
1604
|
|
|
@@ -1454,7 +1651,7 @@ fn variableVirtualRowExtent(child: Widget, width: f32, tokens: DesignTokens, dep
|
|
|
1454
1651
|
const inner_width = @max(0, width - padding.left - padding.right);
|
|
1455
1652
|
var max_height: f32 = 0;
|
|
1456
1653
|
for (child.children, 0..) |grand, index| {
|
|
1457
|
-
if (grand
|
|
1654
|
+
if (!widgetTakesFlowSlot(grand)) continue;
|
|
1458
1655
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(
|
|
1459
1656
|
grand,
|
|
1460
1657
|
rowChildWidth(child, inner_width, index, tokens),
|
|
@@ -1522,7 +1719,7 @@ fn layoutSplitChildren(
|
|
|
1522
1719
|
var divider: ?Widget = null;
|
|
1523
1720
|
var extra_start: ?usize = null;
|
|
1524
1721
|
for (widget.children, 0..) |child, child_index| {
|
|
1525
|
-
if (child
|
|
1722
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1526
1723
|
if (child.kind == .split_divider) {
|
|
1527
1724
|
if (divider == null) divider = child;
|
|
1528
1725
|
continue;
|
|
@@ -1565,7 +1762,7 @@ fn layoutSplitChildren(
|
|
|
1565
1762
|
// frames so the node count still matches the source tree.
|
|
1566
1763
|
if (extra_start) |start| {
|
|
1567
1764
|
for (widget.children[start..]) |child| {
|
|
1568
|
-
if (child
|
|
1765
|
+
if (!widgetTakesFlowSlot(child) or child.kind == .split_divider) continue;
|
|
1569
1766
|
_ = try layoutWidgetDepth(child, geometry.RectF.init(content.maxX(), content.y, 0, 0), parent_index, depth + 1, output, len, tokens);
|
|
1570
1767
|
}
|
|
1571
1768
|
}
|
|
@@ -1584,12 +1781,18 @@ pub fn relayoutSplitChildren(
|
|
|
1584
1781
|
node_index: usize,
|
|
1585
1782
|
depth: usize,
|
|
1586
1783
|
output: []WidgetLayoutNode,
|
|
1784
|
+
root_bounds: geometry.RectF,
|
|
1587
1785
|
tokens: DesignTokens,
|
|
1588
1786
|
) Error!void {
|
|
1787
|
+
if (output.len == 0) return;
|
|
1788
|
+
const root_frame = output[0].frame;
|
|
1789
|
+
output[0].frame = root_bounds;
|
|
1790
|
+
defer output[0].frame = root_frame;
|
|
1589
1791
|
var len: usize = node_index + 1;
|
|
1590
1792
|
const content = frame.inset(widget.layout.padding);
|
|
1591
1793
|
try layoutSplitChildren(widget, content, node_index, depth, output, &len, tokens);
|
|
1592
|
-
try
|
|
1794
|
+
try layoutRootRelativeModalChildren(widget.children, node_index, depth, output, &len, root_bounds, tokens);
|
|
1795
|
+
try layoutAnchoredChildren(widget.children, frame, node_index, depth, output, &len, root_bounds, tokens);
|
|
1593
1796
|
}
|
|
1594
1797
|
|
|
1595
1798
|
/// Slide a laid split's pane boundary to `fraction` GEOMETRICALLY, over
|
|
@@ -1616,7 +1819,7 @@ pub fn slideSplitChildren(
|
|
|
1616
1819
|
var child = node_index + 1;
|
|
1617
1820
|
while (child < nodes.len and nodes[child].depth > split_depth) : (child += 1) {
|
|
1618
1821
|
if (nodes[child].parent_index != node_index) continue;
|
|
1619
|
-
if (nodes[child].widget
|
|
1822
|
+
if (!widgetTakesFlowSlot(nodes[child].widget)) continue;
|
|
1620
1823
|
if (nodes[child].widget.kind == .split_divider) {
|
|
1621
1824
|
if (divider_index == null) divider_index = child;
|
|
1622
1825
|
} else if (pane_indices[0] == null) {
|
|
@@ -1744,7 +1947,7 @@ fn accordionContentFrame(widget: Widget, content: geometry.RectF, tokens: Design
|
|
|
1744
1947
|
fn accordionOpenContentExtent(widget: Widget, width: f32, tokens: DesignTokens, depth: usize) f32 {
|
|
1745
1948
|
var max_height: f32 = 0;
|
|
1746
1949
|
for (widget.children) |child| {
|
|
1747
|
-
if (child
|
|
1950
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1748
1951
|
const child_width = if (child.frame.width > 0) child.frame.width else width;
|
|
1749
1952
|
max_height = @max(max_height, wrappedVerticalExtentForWidth(child, child_width, tokens, depth + 1));
|
|
1750
1953
|
}
|
|
@@ -1768,7 +1971,7 @@ fn alertContentFrame(widget: Widget, content: geometry.RectF, tokens: DesignToke
|
|
|
1768
1971
|
const text_size = widgetBodyTextSize(widget, tokens);
|
|
1769
1972
|
const icon_size = widgetSizedDensityValue(widget, tokens, 16);
|
|
1770
1973
|
const text_gap = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
1771
|
-
const title_gap =
|
|
1974
|
+
const title_gap = densityValue(tokens, tokens.spacing.xs);
|
|
1772
1975
|
const indent = @min(content.width, icon_size + text_gap);
|
|
1773
1976
|
const y = @min(content.maxY(), content.y + widgetLineHeight(text_size) + title_gap);
|
|
1774
1977
|
return geometry.RectF.init(
|
|
@@ -1926,8 +2129,8 @@ fn intrinsicAxisChildrenSize(widget: Widget, tokens: DesignTokens, axis: LayoutA
|
|
|
1926
2129
|
var main_sum: f32 = 0;
|
|
1927
2130
|
var cross_max: f32 = 0;
|
|
1928
2131
|
for (widget.children) |child| {
|
|
1929
|
-
//
|
|
1930
|
-
if (child
|
|
2132
|
+
// Window-level surfaces never grow their parent.
|
|
2133
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1931
2134
|
flow_count += 1;
|
|
1932
2135
|
const size = intrinsicChildSizeInAxis(child, tokens, depth + 1, axis);
|
|
1933
2136
|
switch (axis) {
|
|
@@ -1964,7 +2167,7 @@ fn intrinsicOverlayChildrenSize(widget: Widget, tokens: DesignTokens, depth: usi
|
|
|
1964
2167
|
var width_max: f32 = 0;
|
|
1965
2168
|
var height_max: f32 = 0;
|
|
1966
2169
|
for (widget.children) |child| {
|
|
1967
|
-
if (child
|
|
2170
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1968
2171
|
const size = intrinsicChildSize(child, tokens, depth + 1);
|
|
1969
2172
|
width_max = @max(width_max, size.width);
|
|
1970
2173
|
height_max = @max(height_max, size.height);
|
|
@@ -1982,7 +2185,7 @@ fn intrinsicHorizontalScrollSize(widget: Widget, tokens: DesignTokens, depth: us
|
|
|
1982
2185
|
}
|
|
1983
2186
|
var height_max: f32 = 0;
|
|
1984
2187
|
for (widget.children) |child| {
|
|
1985
|
-
if (child
|
|
2188
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
1986
2189
|
const intrinsic = intrinsicChildSize(child, tokens, depth + 1);
|
|
1987
2190
|
const child_width = if (child.frame.width > 0) child.frame.width else intrinsic.width;
|
|
1988
2191
|
height_max = @max(
|
|
@@ -1996,19 +2199,21 @@ fn intrinsicHorizontalScrollSize(widget: Widget, tokens: DesignTokens, depth: us
|
|
|
1996
2199
|
|
|
1997
2200
|
fn intrinsicGridChildrenSize(widget: Widget, tokens: DesignTokens, depth: usize) geometry.SizeF {
|
|
1998
2201
|
if (depth >= max_widget_depth or widget.children.len == 0) return intrinsicOwnMinSize(widget);
|
|
2202
|
+
const flow_count = widgetFlowChildCount(widget.children);
|
|
2203
|
+
if (flow_count == 0) return intrinsicOwnMinSize(widget);
|
|
1999
2204
|
var cell_width: f32 = 0;
|
|
2000
2205
|
var cell_height: f32 = 0;
|
|
2001
2206
|
for (widget.children) |child| {
|
|
2002
|
-
if (child
|
|
2207
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
2003
2208
|
const size = intrinsicChildSize(child, tokens, depth + 1);
|
|
2004
2209
|
cell_width = @max(cell_width, size.width);
|
|
2005
2210
|
cell_height = @max(cell_height, size.height);
|
|
2006
2211
|
}
|
|
2007
|
-
const columns = gridColumnCount(
|
|
2212
|
+
const columns = gridColumnCount(flow_count, widget.layout.columns);
|
|
2008
2213
|
// `gridRowCount`, not the additive ceil-div: declared columns are
|
|
2009
|
-
// engine input, and `
|
|
2214
|
+
// engine input, and `flow_count + columns` overflows in safe
|
|
2010
2215
|
// builds when a parent intrinsically measures a maxInt-columns grid.
|
|
2011
|
-
const rows = gridRowCount(
|
|
2216
|
+
const rows = gridRowCount(flow_count, columns);
|
|
2012
2217
|
const gap = nonNegative(widget.layout.gap);
|
|
2013
2218
|
return paddedIntrinsicSize(widget, geometry.SizeF.init(
|
|
2014
2219
|
cell_width * @as(f32, @floatFromInt(columns)) + gap * @as(f32, @floatFromInt(columns - 1)),
|
|
@@ -2067,25 +2272,25 @@ fn intrinsicStatusBarWidgetSize(widget: Widget, tokens: DesignTokens) geometry.S
|
|
|
2067
2272
|
|
|
2068
2273
|
fn intrinsicAlertWidgetSize(widget: Widget, tokens: DesignTokens, depth: usize) geometry.SizeF {
|
|
2069
2274
|
const text_size = widgetBodyTextSize(widget, tokens);
|
|
2070
|
-
const
|
|
2275
|
+
const padding = alertLayoutPadding(widget, tokens);
|
|
2071
2276
|
// The chrome's fixed 16px icon (`emitAlertWidgetChrome`).
|
|
2072
2277
|
const icon_size = widgetSizedDensityValue(widget, tokens, 16);
|
|
2073
2278
|
const text_gap = widgetControlInset(widget, tokens, tokens.spacing.md);
|
|
2074
2279
|
const text = intrinsicTextWidgetSize(widget, tokens, text_size);
|
|
2075
2280
|
var size = geometry.SizeF.init(
|
|
2076
|
-
@max(widgetSizedDensityValue(widget, tokens, 240), text.width +
|
|
2077
|
-
@max(widgetSizedDensityValue(widget, tokens, 52), widgetLineHeight(text_size) +
|
|
2281
|
+
@max(widgetSizedDensityValue(widget, tokens, 240), text.width + padding.left + padding.right + icon_size + text_gap),
|
|
2282
|
+
@max(widgetSizedDensityValue(widget, tokens, 52), widgetLineHeight(text_size) + padding.top + padding.bottom),
|
|
2078
2283
|
);
|
|
2079
2284
|
// A description column under the title (`alertContentFrame`) grows
|
|
2080
2285
|
// the alert instead of overflowing it.
|
|
2081
2286
|
const children = intrinsicStackedChildrenSize(widget, tokens, depth);
|
|
2082
2287
|
if (children.height > 0 and widget.text.len > 0) {
|
|
2083
|
-
const title_gap =
|
|
2084
|
-
size.height = @max(size.height, widgetLineHeight(text_size) + title_gap + children.height +
|
|
2085
|
-
size.width = @max(size.width, children.width + icon_size + text_gap +
|
|
2288
|
+
const title_gap = densityValue(tokens, tokens.spacing.xs);
|
|
2289
|
+
size.height = @max(size.height, widgetLineHeight(text_size) + title_gap + children.height + padding.top + padding.bottom);
|
|
2290
|
+
size.width = @max(size.width, children.width + icon_size + text_gap + padding.left + padding.right);
|
|
2086
2291
|
} else if (children.height > 0) {
|
|
2087
|
-
size.height = @max(size.height, children.height +
|
|
2088
|
-
size.width = @max(size.width, children.width +
|
|
2292
|
+
size.height = @max(size.height, children.height + padding.top + padding.bottom);
|
|
2293
|
+
size.width = @max(size.width, children.width + padding.left + padding.right);
|
|
2089
2294
|
}
|
|
2090
2295
|
return size;
|
|
2091
2296
|
}
|
|
@@ -2097,7 +2302,7 @@ fn intrinsicStackedChildrenSize(widget: Widget, tokens: DesignTokens, depth: usi
|
|
|
2097
2302
|
var width_max: f32 = 0;
|
|
2098
2303
|
var height_max: f32 = 0;
|
|
2099
2304
|
for (widget.children) |child| {
|
|
2100
|
-
if (child
|
|
2305
|
+
if (!widgetTakesFlowSlot(child)) continue;
|
|
2101
2306
|
const size = intrinsicChildSize(child, tokens, depth + 1);
|
|
2102
2307
|
width_max = @max(width_max, size.width);
|
|
2103
2308
|
height_max = @max(height_max, size.height);
|
|
@@ -2513,12 +2718,13 @@ pub fn virtualWidgetScrollContentExtentWithTokens(widget: Widget, viewport_exten
|
|
|
2513
2718
|
}
|
|
2514
2719
|
const item_count = virtualWidgetScrollItemCount(widget);
|
|
2515
2720
|
if (item_count == 0) return 0;
|
|
2721
|
+
const flow_count = widgetFlowChildCount(widget.children);
|
|
2516
2722
|
const item_extent = if (widget.layout.virtual_item_extent > 0)
|
|
2517
2723
|
widget.layout.virtual_item_extent
|
|
2518
|
-
else if (widget.kind == .grid and
|
|
2519
|
-
preferredGridRowExtent(widget.children, gridColumnCount(
|
|
2520
|
-
else if (widget.children
|
|
2521
|
-
preferredMainExtent(
|
|
2724
|
+
else if (widget.kind == .grid and flow_count > 0)
|
|
2725
|
+
preferredGridRowExtent(widget.children, gridColumnCount(flow_count, widget.layout.columns), tokens)
|
|
2726
|
+
else if (firstWidgetFlowChild(widget.children)) |child|
|
|
2727
|
+
preferredMainExtent(child, .vertical, tokens)
|
|
2522
2728
|
else
|
|
2523
2729
|
return 0;
|
|
2524
2730
|
return virtualListRange(.{
|
|
@@ -2535,14 +2741,15 @@ fn virtualWidgetScrollItemCount(widget: Widget) usize {
|
|
|
2535
2741
|
// children hold only the built window, so counting them would
|
|
2536
2742
|
// collapse the scrollbar (and the native driver's content size) to
|
|
2537
2743
|
// the window.
|
|
2744
|
+
const flow_count = widgetFlowChildCount(widget.children);
|
|
2538
2745
|
if (widget.layout.virtual_item_count > 0) {
|
|
2539
|
-
return @max(widget.layout.virtual_item_count, widget.layout.virtual_first_index +
|
|
2746
|
+
return @max(widget.layout.virtual_item_count, widget.layout.virtual_first_index + flow_count);
|
|
2540
2747
|
}
|
|
2541
|
-
if (widget.kind == .grid and
|
|
2542
|
-
const columns = gridColumnCount(
|
|
2543
|
-
return gridRowCount(
|
|
2748
|
+
if (widget.kind == .grid and flow_count > 0) {
|
|
2749
|
+
const columns = gridColumnCount(flow_count, widget.layout.columns);
|
|
2750
|
+
return gridRowCount(flow_count, columns);
|
|
2544
2751
|
}
|
|
2545
|
-
if (
|
|
2752
|
+
if (flow_count > 0) return flow_count;
|
|
2546
2753
|
if (widget.semantics.list_item_count) |count| return @intCast(count);
|
|
2547
2754
|
return 0;
|
|
2548
2755
|
}
|