@native-sdk/cli 0.5.0 → 0.5.1
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 +198 -13
- package/build/ts_run.mjs +58 -19
- package/build.zig +42 -0
- package/package.json +13 -9
- package/packages/core/package-lock.json +4 -3
- package/packages/core/package.json +3 -2
- package/packages/core/src/typed_ast.ts +11 -1
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/root.zig +5 -0
- package/src/primitives/canvas/tokens.zig +15 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
- package/src/primitives/canvas/widget_layout.zig +138 -2
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +1037 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/ui_app.zig +131 -38
- package/src/runtime/ui_app_tests.zig +221 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/tooling/package.zig +311 -8
- package/src/tooling/templates.zig +97 -9
- package/src/tooling/ts_core.zig +626 -13
- package/src/tooling/verbs.zig +88 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const support = @import("test_support.zig");
|
|
2
|
+
const widget_metrics = @import("widget_metrics.zig");
|
|
2
3
|
const std = support.std;
|
|
3
4
|
const geometry = support.geometry;
|
|
4
5
|
const canvas = support.canvas;
|
|
@@ -3116,10 +3117,11 @@ test "themed design tokens flow into widget display lists" {
|
|
|
3116
3117
|
}
|
|
3117
3118
|
|
|
3118
3119
|
test "widget text at intrinsic width does not wrap under geometry pixel snapping" {
|
|
3119
|
-
// Geometry snapping can shave up to
|
|
3120
|
-
// that intrinsic sizing measured
|
|
3121
|
-
//
|
|
3122
|
-
//
|
|
3120
|
+
// Geometry snapping can shave up to a full device pixel off the frame
|
|
3121
|
+
// that intrinsic sizing measured (each edge rounds independently by
|
|
3122
|
+
// up to half); the text emitter hands the snap quantum back to the
|
|
3123
|
+
// wrap budget so an exact-fit label ("Sort") never breaks into
|
|
3124
|
+
// "Sor"/"t". Regression for the snapped-frame wrap
|
|
3123
3125
|
// seam surfaced when the estimator became the bundled face's real
|
|
3124
3126
|
// advance table.
|
|
3125
3127
|
const scales = [_]f32{ 1, 2 };
|
|
@@ -3153,7 +3155,7 @@ test "widget text at intrinsic width does not wrap under geometry pixel snapping
|
|
|
3153
3155
|
test "label-exact controls at intrinsic width never elide under geometry pixel snapping" {
|
|
3154
3156
|
// The elision twin of the wrap seam above: a control sized exactly
|
|
3155
3157
|
// to its measured label sits at a fractional width, and render-time
|
|
3156
|
-
// geometry snapping can shave up to
|
|
3158
|
+
// geometry snapping can shave up to a full device pixel off that
|
|
3157
3159
|
// frame — past the elision slack, so real glyphs swap for an
|
|
3158
3160
|
// ellipsis (system monitor's "PID" sort chip painting "PI…").
|
|
3159
3161
|
// Intrinsic measured-label widths now ceil to the snap grid
|
|
@@ -3202,6 +3204,308 @@ test "label-exact controls at intrinsic width never elide under geometry pixel s
|
|
|
3202
3204
|
}
|
|
3203
3205
|
}
|
|
3204
3206
|
|
|
3207
|
+
test "a string never elides inside its own measured width under edge snapping" {
|
|
3208
|
+
// The measurement/ellipsize epsilon policy (see `textWrapMaxWidth`):
|
|
3209
|
+
// geometry snapping rounds each frame edge independently, so a frame
|
|
3210
|
+
// sized exactly to its measured text and sitting at a fractional
|
|
3211
|
+
// position can come back up to a FULL device pixel narrower — the
|
|
3212
|
+
// budget hands that whole quantum back, and the elision slack covers
|
|
3213
|
+
// the residual float dust. Sweep fractional origins across the snap
|
|
3214
|
+
// cell for every digit (the TS scaffold's counter, which painted "…"
|
|
3215
|
+
// instead of "2" on Windows at scale 1) plus longer labels, at every
|
|
3216
|
+
// real scale factor.
|
|
3217
|
+
const scales = [_]f32{ 1, 1.25, 1.5, 2 };
|
|
3218
|
+
const labels = [_][]const u8{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "ticks 7", "Sampling 60 s cadence" };
|
|
3219
|
+
const size: f32 = 14;
|
|
3220
|
+
for (scales) |scale| {
|
|
3221
|
+
const tokens = DesignTokens{ .pixel_snap = .{ .geometry = true, .text = true, .scale = scale } };
|
|
3222
|
+
for (labels) |label| {
|
|
3223
|
+
const measured = canvas.estimateTextWidthForFont(default_sans_font_id, label, size);
|
|
3224
|
+
var step: usize = 0;
|
|
3225
|
+
while (step < 32) : (step += 1) {
|
|
3226
|
+
const origin = 235 + @as(f32, @floatFromInt(step)) / 32.0;
|
|
3227
|
+
// Snap both edges exactly like the renderer's
|
|
3228
|
+
// `pixelSnapGeometryRect` does.
|
|
3229
|
+
const left = @round(origin * scale) / scale;
|
|
3230
|
+
const right = @round((origin + measured) * scale) / scale;
|
|
3231
|
+
const snapped_width = @max(0, right - left);
|
|
3232
|
+
var lines: [2]TextLine = undefined;
|
|
3233
|
+
const layout = try canvas.layoutTextRun(.{
|
|
3234
|
+
.id = 1,
|
|
3235
|
+
.font_id = default_sans_font_id,
|
|
3236
|
+
.size = size,
|
|
3237
|
+
.origin = geometry.PointF.init(left, 20),
|
|
3238
|
+
.color = Color.rgb8(0, 0, 0),
|
|
3239
|
+
.text = label,
|
|
3240
|
+
}, .{
|
|
3241
|
+
.max_width = widget_metrics.textWrapMaxWidth(tokens, snapped_width),
|
|
3242
|
+
.wrap = .none,
|
|
3243
|
+
.overflow = .ellipsis,
|
|
3244
|
+
}, &lines);
|
|
3245
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lineCount());
|
|
3246
|
+
for (layout.lines) |line| try std.testing.expect(!line.isElided());
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
test "hug-sized centered text leaf never elides under geometry pixel snapping" {
|
|
3253
|
+
// The widget-level twin of the sweep above, in the exact scaffold
|
|
3254
|
+
// shape that surfaced it: `<row main="center">` centers a hug-sized
|
|
3255
|
+
// digit between two buttons, landing BOTH its frame edges on
|
|
3256
|
+
// fractional thirds — the left edge snaps up, the right edge snaps
|
|
3257
|
+
// down, and the frame loses more than the old half-pixel hand-back.
|
|
3258
|
+
const digits = [_][]const u8{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
|
3259
|
+
const scales = [_]f32{ 1, 1.25, 1.5, 2 };
|
|
3260
|
+
for (scales) |scale| {
|
|
3261
|
+
const tokens = DesignTokens{ .pixel_snap = .{ .geometry = true, .text = true, .scale = scale } };
|
|
3262
|
+
for (digits) |digit| {
|
|
3263
|
+
const minus = Widget{ .id = 2, .kind = .button, .text = "-" };
|
|
3264
|
+
const count = Widget{ .id = 3, .kind = .text, .text = digit };
|
|
3265
|
+
const plus = Widget{ .id = 4, .kind = .button, .text = "+" };
|
|
3266
|
+
const children = [_]Widget{ minus, count, plus };
|
|
3267
|
+
const row = Widget{ .id = 1, .kind = .row, .layout = .{
|
|
3268
|
+
.gap = 8,
|
|
3269
|
+
.main_alignment = .center,
|
|
3270
|
+
.cross_alignment = .center,
|
|
3271
|
+
}, .children = &children };
|
|
3272
|
+
|
|
3273
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
3274
|
+
const layout = try canvas.layoutWidgetTreeWithTokens(row, geometry.RectF.init(16, 56, 448, 164), tokens, &nodes);
|
|
3275
|
+
|
|
3276
|
+
var commands: [16]CanvasCommand = undefined;
|
|
3277
|
+
var builder = Builder.init(&commands);
|
|
3278
|
+
try canvas.emitWidgetLayout(&builder, layout, tokens);
|
|
3279
|
+
var seen = false;
|
|
3280
|
+
for (builder.displayList().commands) |command| switch (command) {
|
|
3281
|
+
.draw_text => |text| {
|
|
3282
|
+
if (!std.mem.eql(u8, text.text, digit)) continue;
|
|
3283
|
+
seen = true;
|
|
3284
|
+
var lines: [2]TextLine = undefined;
|
|
3285
|
+
const text_layout = try canvas.layoutTextRun(text, text.text_layout.?, &lines);
|
|
3286
|
+
for (text_layout.lines) |line| try std.testing.expect(!line.isElided());
|
|
3287
|
+
},
|
|
3288
|
+
else => {},
|
|
3289
|
+
};
|
|
3290
|
+
try std.testing.expect(seen);
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
|
|
3295
|
+
test "window-control clearance trims drag-header content on the cluster's side" {
|
|
3296
|
+
// The engine half of the hidden-titlebar caption fix: when the
|
|
3297
|
+
// runtime stamps the OS window-control cluster into the tokens, a
|
|
3298
|
+
// `window_drag` row lays its content out clear of it — trailing
|
|
3299
|
+
// cluster (Windows caption buttons) trims the content box's end,
|
|
3300
|
+
// leading cluster (macOS traffic lights) its start. Non-drag rows
|
|
3301
|
+
// never move.
|
|
3302
|
+
const spacer = Widget{ .id = 2, .kind = .stack, .layout = .{ .grow = 1 } };
|
|
3303
|
+
const status = Widget{ .id = 3, .kind = .text, .text = "sampling" };
|
|
3304
|
+
const children = [_]Widget{ spacer, status };
|
|
3305
|
+
var row = Widget{ .id = 1, .kind = .row, .layout = .{ .cross_alignment = .center }, .children = &children };
|
|
3306
|
+
row.window_drag = true;
|
|
3307
|
+
const bounds = geometry.RectF.init(0, 0, 400, 40);
|
|
3308
|
+
|
|
3309
|
+
// Trailing cluster: content ends at its leading edge.
|
|
3310
|
+
const trailing_tokens = DesignTokens{ .window_controls = geometry.RectF.init(262, 0, 138, 32) };
|
|
3311
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
3312
|
+
var layout = try canvas.layoutWidgetTreeWithTokens(row, bounds, trailing_tokens, &nodes);
|
|
3313
|
+
try std.testing.expect(layout.findById(3).?.frame.maxX() <= 262 + 0.01);
|
|
3314
|
+
|
|
3315
|
+
// Leading cluster (the macOS mirror): content starts past it.
|
|
3316
|
+
const leading_tokens = DesignTokens{ .window_controls = geometry.RectF.init(0, 0, 78, 32) };
|
|
3317
|
+
const lead_children = [_]Widget{ status, spacer };
|
|
3318
|
+
var lead_row = row;
|
|
3319
|
+
lead_row.children = &lead_children;
|
|
3320
|
+
layout = try canvas.layoutWidgetTreeWithTokens(lead_row, bounds, leading_tokens, &nodes);
|
|
3321
|
+
try std.testing.expect(layout.findById(3).?.frame.x >= 78 - 0.01);
|
|
3322
|
+
|
|
3323
|
+
// Unstamped tokens: byte-identical to a plain row.
|
|
3324
|
+
layout = try canvas.layoutWidgetTreeWithTokens(row, bounds, DesignTokens{}, &nodes);
|
|
3325
|
+
try std.testing.expectEqual(@as(f32, 400), layout.findById(3).?.frame.maxX());
|
|
3326
|
+
|
|
3327
|
+
// A non-drag row ignores the stamp entirely.
|
|
3328
|
+
var plain = row;
|
|
3329
|
+
plain.window_drag = false;
|
|
3330
|
+
layout = try canvas.layoutWidgetTreeWithTokens(plain, bounds, trailing_tokens, &nodes);
|
|
3331
|
+
try std.testing.expectEqual(@as(f32, 400), layout.findById(3).?.frame.maxX());
|
|
3332
|
+
}
|
|
3333
|
+
|
|
3334
|
+
test "window-control collision scan flags readable content only" {
|
|
3335
|
+
// The reservation trigger: text under the cluster inside a drag
|
|
3336
|
+
// header counts; the row itself (its background paints under the
|
|
3337
|
+
// buttons like it does under traffic lights), spacers, and
|
|
3338
|
+
// full-bleed separators never do — and content outside any drag
|
|
3339
|
+
// region is not the header's to fix.
|
|
3340
|
+
const cluster = geometry.RectF.init(262, 0, 138, 32);
|
|
3341
|
+
const bounds = geometry.RectF.init(0, 0, 400, 40);
|
|
3342
|
+
|
|
3343
|
+
const spacer = Widget{ .id = 2, .kind = .stack, .layout = .{ .grow = 1 } };
|
|
3344
|
+
const status = Widget{ .id = 3, .kind = .text, .text = "sampling" };
|
|
3345
|
+
const colliding_children = [_]Widget{ spacer, status };
|
|
3346
|
+
var drag_row = Widget{ .id = 1, .kind = .row, .children = &colliding_children };
|
|
3347
|
+
drag_row.window_drag = true;
|
|
3348
|
+
|
|
3349
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
3350
|
+
var layout = try canvas.layoutWidgetTreeWithTokens(drag_row, bounds, DesignTokens{}, &nodes);
|
|
3351
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3352
|
+
|
|
3353
|
+
// The same content already clear of the cluster: no trigger.
|
|
3354
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, geometry.RectF.init(262, 200, 138, 32), DesignTokens{}));
|
|
3355
|
+
|
|
3356
|
+
// Decoration under the cluster: a full-width separator never
|
|
3357
|
+
// triggers (it is expected to run under the band).
|
|
3358
|
+
const separator = Widget{ .id = 4, .kind = .separator };
|
|
3359
|
+
const decor_children = [_]Widget{ spacer, separator };
|
|
3360
|
+
var decor_row = drag_row;
|
|
3361
|
+
decor_row.children = &decor_children;
|
|
3362
|
+
layout = try canvas.layoutWidgetTreeWithTokens(decor_row, bounds, DesignTokens{}, &nodes);
|
|
3363
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3364
|
+
|
|
3365
|
+
// Content under the cluster OUTSIDE any drag region: not the
|
|
3366
|
+
// header's collision to fix, so no trigger.
|
|
3367
|
+
var plain_row = drag_row;
|
|
3368
|
+
plain_row.window_drag = false;
|
|
3369
|
+
layout = try canvas.layoutWidgetTreeWithTokens(plain_row, bounds, DesignTokens{}, &nodes);
|
|
3370
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3371
|
+
}
|
|
3372
|
+
|
|
3373
|
+
test "window-control collision scan judges text by its aligned painted bounds" {
|
|
3374
|
+
// The centered-title pattern: a grow text spanning the header row
|
|
3375
|
+
// has a FRAME under the trailing cluster while its inked glyphs sit
|
|
3376
|
+
// well clear of it. Judging the frame would pay the clearance retry,
|
|
3377
|
+
// and the trimmed content box would visibly shift the centered title
|
|
3378
|
+
// — so the scan measures the aligned painted line instead. A
|
|
3379
|
+
// trailing-aligned grow text whose painted END sits under the
|
|
3380
|
+
// cluster still collides (the system-monitor case), the macOS
|
|
3381
|
+
// leading mirror agrees, and multi-line text keeps the conservative
|
|
3382
|
+
// frame test.
|
|
3383
|
+
const cluster = geometry.RectF.init(262, 0, 138, 32);
|
|
3384
|
+
const bounds = geometry.RectF.init(0, 0, 400, 40);
|
|
3385
|
+
|
|
3386
|
+
var title = Widget{ .id = 2, .kind = .text, .text = "Monitor", .layout = .{ .grow = 1 } };
|
|
3387
|
+
title.text_alignment = .center;
|
|
3388
|
+
const centered_children = [_]Widget{title};
|
|
3389
|
+
var drag_row = Widget{ .id = 1, .kind = .row, .children = ¢ered_children };
|
|
3390
|
+
drag_row.window_drag = true;
|
|
3391
|
+
|
|
3392
|
+
var nodes: [4]WidgetLayoutNode = undefined;
|
|
3393
|
+
var layout = try canvas.layoutWidgetTreeWithTokens(drag_row, bounds, DesignTokens{}, &nodes);
|
|
3394
|
+
// The grow frame really does span the cluster; the painted glyphs
|
|
3395
|
+
// do not — no trigger, so the runtime never retries and the
|
|
3396
|
+
// centered title never moves.
|
|
3397
|
+
try std.testing.expect(layout.findById(2).?.frame.maxX() > cluster.x);
|
|
3398
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3399
|
+
|
|
3400
|
+
// Trailing-aligned grow text: same frame, painted end under the
|
|
3401
|
+
// cluster — still a collision, and the remedy still converges (the
|
|
3402
|
+
// re-laid text ends at the cluster's leading edge, so the re-scan
|
|
3403
|
+
// of the remedied layout stays quiet).
|
|
3404
|
+
var status = title;
|
|
3405
|
+
status.text_alignment = .end;
|
|
3406
|
+
const trailing_children = [_]Widget{status};
|
|
3407
|
+
var trailing_row = drag_row;
|
|
3408
|
+
trailing_row.children = &trailing_children;
|
|
3409
|
+
layout = try canvas.layoutWidgetTreeWithTokens(trailing_row, bounds, DesignTokens{}, &nodes);
|
|
3410
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3411
|
+
const trailing_tokens = DesignTokens{ .window_controls = cluster };
|
|
3412
|
+
layout = try canvas.layoutWidgetTreeWithTokens(trailing_row, bounds, trailing_tokens, &nodes);
|
|
3413
|
+
try std.testing.expect(layout.findById(2).?.frame.maxX() <= cluster.x + 0.01);
|
|
3414
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, trailing_tokens));
|
|
3415
|
+
|
|
3416
|
+
// The macOS mirror: a leading cluster collides with leading-aligned
|
|
3417
|
+
// glyphs but not with the same centered title.
|
|
3418
|
+
const leading_cluster = geometry.RectF.init(0, 0, 78, 32);
|
|
3419
|
+
var lead = title;
|
|
3420
|
+
lead.text_alignment = .start;
|
|
3421
|
+
const lead_children = [_]Widget{lead};
|
|
3422
|
+
var lead_row = drag_row;
|
|
3423
|
+
lead_row.children = &lead_children;
|
|
3424
|
+
layout = try canvas.layoutWidgetTreeWithTokens(lead_row, bounds, DesignTokens{}, &nodes);
|
|
3425
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, leading_cluster, DesignTokens{}));
|
|
3426
|
+
layout = try canvas.layoutWidgetTreeWithTokens(drag_row, bounds, DesignTokens{}, &nodes);
|
|
3427
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, leading_cluster, DesignTokens{}));
|
|
3428
|
+
|
|
3429
|
+
// Multi-line text (an explicit newline) stacks lines with per-line
|
|
3430
|
+
// extents, so the scan keeps the conservative frame test: the same
|
|
3431
|
+
// centered grow leaf triggers once it can break.
|
|
3432
|
+
var wrapped = title;
|
|
3433
|
+
wrapped.text = "Mon\nitor";
|
|
3434
|
+
const wrapped_children = [_]Widget{wrapped};
|
|
3435
|
+
var wrapped_row = drag_row;
|
|
3436
|
+
wrapped_row.children = &wrapped_children;
|
|
3437
|
+
layout = try canvas.layoutWidgetTreeWithTokens(wrapped_row, bounds, DesignTokens{}, &nodes);
|
|
3438
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
test "window-control clearance moves a drag header's anchored children too" {
|
|
3442
|
+
// The collision scan counts every content descendant of the drag
|
|
3443
|
+
// header — anchored floaters included — so the remedy must move
|
|
3444
|
+
// them: a drag header's anchored children resolve against the
|
|
3445
|
+
// cleared anchor rect, not the full frame, or the runtime pays its
|
|
3446
|
+
// one retry and the child stays under the caption buttons. Non-drag
|
|
3447
|
+
// widgets' anchored children never move (menus/popovers anchor
|
|
3448
|
+
// everywhere), stamped tokens or not.
|
|
3449
|
+
const cluster = geometry.RectF.init(262, 0, 138, 32);
|
|
3450
|
+
const bounds = geometry.RectF.init(0, 0, 400, 300);
|
|
3451
|
+
const trailing_tokens = DesignTokens{ .window_controls = cluster };
|
|
3452
|
+
|
|
3453
|
+
// A 24pt-tall header (shorter than the 32pt cluster band) whose ONLY
|
|
3454
|
+
// content is an end-aligned floater dropping just below the header —
|
|
3455
|
+
// still inside the cluster band, and under its buttons.
|
|
3456
|
+
const badge = Widget{ .id = 3, .kind = .text, .text = "recording", .layout = .{ .anchor = .{ .placement = .below, .alignment = .end, .offset = 0 } } };
|
|
3457
|
+
const header_children = [_]Widget{badge};
|
|
3458
|
+
var header = Widget{ .id = 2, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 24), .children = &header_children };
|
|
3459
|
+
header.window_drag = true;
|
|
3460
|
+
const root_children = [_]Widget{header};
|
|
3461
|
+
const root = Widget{ .id = 1, .kind = .column, .children = &root_children };
|
|
3462
|
+
|
|
3463
|
+
// Unstamped: the floater ends at the header's trailing edge, under
|
|
3464
|
+
// the cluster — and the scan fires on it (anchored-only content is
|
|
3465
|
+
// still a collision).
|
|
3466
|
+
var nodes: [6]WidgetLayoutNode = undefined;
|
|
3467
|
+
var layout = try canvas.layoutWidgetTreeWithTokens(root, bounds, DesignTokens{}, &nodes);
|
|
3468
|
+
const naive = layout.findById(3).?.frame;
|
|
3469
|
+
try std.testing.expect(naive.maxX() > cluster.x);
|
|
3470
|
+
try std.testing.expect(!geometry.RectF.intersection(naive.normalized(), cluster).isEmpty());
|
|
3471
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, DesignTokens{}));
|
|
3472
|
+
|
|
3473
|
+
// Stamped: the anchor base is trimmed, the floater lands clear of
|
|
3474
|
+
// the cluster, and re-scanning the remedied layout stays quiet —
|
|
3475
|
+
// scan and remedy agree, so the runtime's single retry converges.
|
|
3476
|
+
layout = try canvas.layoutWidgetTreeWithTokens(root, bounds, trailing_tokens, &nodes);
|
|
3477
|
+
try std.testing.expect(layout.findById(3).?.frame.maxX() <= cluster.x + 0.01);
|
|
3478
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, cluster, trailing_tokens));
|
|
3479
|
+
|
|
3480
|
+
// The macOS mirror: a leading cluster pushes a start-aligned floater
|
|
3481
|
+
// past its trailing edge.
|
|
3482
|
+
const leading_cluster = geometry.RectF.init(0, 0, 78, 32);
|
|
3483
|
+
const lead_badge = Widget{ .id = 3, .kind = .text, .text = "recording", .layout = .{ .anchor = .{ .placement = .below, .alignment = .start, .offset = 0 } } };
|
|
3484
|
+
const lead_children = [_]Widget{lead_badge};
|
|
3485
|
+
var lead_header = header;
|
|
3486
|
+
lead_header.children = &lead_children;
|
|
3487
|
+
const lead_root_children = [_]Widget{lead_header};
|
|
3488
|
+
var lead_root = root;
|
|
3489
|
+
lead_root.children = &lead_root_children;
|
|
3490
|
+
layout = try canvas.layoutWidgetTreeWithTokens(lead_root, bounds, DesignTokens{}, &nodes);
|
|
3491
|
+
try std.testing.expect(canvas.windowDragContentUnderWindowControls(layout.nodes, leading_cluster, DesignTokens{}));
|
|
3492
|
+
layout = try canvas.layoutWidgetTreeWithTokens(lead_root, bounds, DesignTokens{ .window_controls = leading_cluster }, &nodes);
|
|
3493
|
+
try std.testing.expect(layout.findById(3).?.frame.x >= leading_cluster.maxX() - 0.01);
|
|
3494
|
+
try std.testing.expect(!canvas.windowDragContentUnderWindowControls(layout.nodes, leading_cluster, DesignTokens{ .window_controls = leading_cluster }));
|
|
3495
|
+
|
|
3496
|
+
// A non-drag row's anchored child is byte-identical with the stamp:
|
|
3497
|
+
// anchoring semantics outside declared titlebars never change.
|
|
3498
|
+
var plain_header = header;
|
|
3499
|
+
plain_header.window_drag = false;
|
|
3500
|
+
const plain_root_children = [_]Widget{plain_header};
|
|
3501
|
+
var plain_root = root;
|
|
3502
|
+
plain_root.children = &plain_root_children;
|
|
3503
|
+
layout = try canvas.layoutWidgetTreeWithTokens(plain_root, bounds, DesignTokens{}, &nodes);
|
|
3504
|
+
const unstamped = layout.findById(3).?.frame;
|
|
3505
|
+
layout = try canvas.layoutWidgetTreeWithTokens(plain_root, bounds, trailing_tokens, &nodes);
|
|
3506
|
+
try std.testing.expectEqual(unstamped, layout.findById(3).?.frame);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3205
3509
|
test "geometry pixel snapping off keeps label-exact intrinsic widths bit-identical" {
|
|
3206
3510
|
// The ceil-to-grid rule is gated on `pixel_snap.geometry`: themes
|
|
3207
3511
|
// without geometry snapping have no snap shave to defend against,
|
|
@@ -70,7 +70,7 @@ pub fn layoutWidgetDepth(
|
|
|
70
70
|
};
|
|
71
71
|
len.* += 1;
|
|
72
72
|
|
|
73
|
-
const content = frame.inset(widget.layout.padding);
|
|
73
|
+
const content = windowControlsClearedContent(frame.inset(widget.layout.padding), widget, tokens);
|
|
74
74
|
switch (widget.kind) {
|
|
75
75
|
.row, .breadcrumb, .pagination, .radio_group, .toggle_group => try layoutAxisChildren(widget.children, content, .horizontal, index, depth, output, len, widget.layout, tokens),
|
|
76
76
|
// Button groups flow like rows but at their register's effective
|
|
@@ -152,11 +152,147 @@ pub fn layoutWidgetDepth(
|
|
|
152
152
|
// widget's resolved frame and the window (the layout root's frame).
|
|
153
153
|
// Leaf trigger kinds (select, button, ...) never lay out flow
|
|
154
154
|
// children, but their anchored children float all the same.
|
|
155
|
-
|
|
155
|
+
// A drag header's anchor base is trimmed clear of the stamped
|
|
156
|
+
// window-control cluster exactly like its flow content box: the
|
|
157
|
+
// collision scan counts anchored descendants too, so the remedy must
|
|
158
|
+
// move them or the one retry is paid for nothing. Non-drag widgets
|
|
159
|
+
// pass through untouched (menus and popovers anchor everywhere).
|
|
160
|
+
try layoutAnchoredChildren(widget.children, windowControlsClearedContent(frame, widget, tokens), index, depth, output, len, tokens);
|
|
156
161
|
|
|
157
162
|
return index;
|
|
158
163
|
}
|
|
159
164
|
|
|
165
|
+
/// Lay a drag header's content out clear of the OS window-control
|
|
166
|
+
/// cluster. On hidden-titlebar windows the content extends under the
|
|
167
|
+
/// system's control band, and the cluster sits ON the content at one
|
|
168
|
+
/// end — macOS's traffic lights lead, Windows' min/max/close cluster
|
|
169
|
+
/// trails. A `window_drag` widget declares "this row IS the titlebar",
|
|
170
|
+
/// so when the runtime has stamped the cluster's frame into the tokens
|
|
171
|
+
/// (`DesignTokens.window_controls` — only after a build proved content
|
|
172
|
+
/// actually collided; see `windowDragContentUnderWindowControls`), the
|
|
173
|
+
/// row's content box is trimmed on the cluster's side: trailing content
|
|
174
|
+
/// (a right-aligned status line) stops at the cluster's leading edge
|
|
175
|
+
/// instead of rendering under the buttons. Rows whose own padding (or
|
|
176
|
+
/// an app-authored chrome spacer) already clears the cluster never
|
|
177
|
+
/// reach the stamping step, so they lay out byte-identically.
|
|
178
|
+
fn windowControlsClearedContent(content: geometry.RectF, widget: Widget, tokens: DesignTokens) geometry.RectF {
|
|
179
|
+
if (!widget.window_drag) return content;
|
|
180
|
+
const controls = (tokens.window_controls orelse return content).normalized();
|
|
181
|
+
if (controls.width <= 0 or controls.height <= 0) return content;
|
|
182
|
+
if (geometry.RectF.intersection(content, controls).isEmpty()) return content;
|
|
183
|
+
var cleared = content;
|
|
184
|
+
if (controls.x + controls.width / 2 >= content.x + content.width / 2) {
|
|
185
|
+
// Trailing cluster (Windows caption buttons): the content box
|
|
186
|
+
// ends where the cluster begins.
|
|
187
|
+
cleared.width = @max(0, @min(content.maxX(), controls.x) - content.x);
|
|
188
|
+
} else {
|
|
189
|
+
// Leading cluster (macOS traffic lights): the content box
|
|
190
|
+
// starts past the cluster.
|
|
191
|
+
const start = @min(content.maxX(), @max(content.x, controls.maxX()));
|
|
192
|
+
cleared.width = @max(0, content.maxX() - start);
|
|
193
|
+
cleared.x = start;
|
|
194
|
+
}
|
|
195
|
+
return cleared;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/// True when a laid-out tree left CONTENT of a drag header under the
|
|
199
|
+
/// window-control cluster (`controls`, canvas-local): the trigger for
|
|
200
|
+
/// the runtime's window-control reservation. Only nodes INSIDE a
|
|
201
|
+
/// visible `window_drag` region count — the drag row is the declared
|
|
202
|
+
/// titlebar, the one place the reservation can honestly re-flow — and
|
|
203
|
+
/// only content-bearing leaves count: text you must read, controls you
|
|
204
|
+
/// must see and press. Containers and full-bleed decoration (the row's
|
|
205
|
+
/// own background, separators, skeletons, progress strips, cover
|
|
206
|
+
/// images) are EXPECTED to run under the cluster, exactly like they do
|
|
207
|
+
/// under macOS traffic lights, so they never trigger. Text leaves are
|
|
208
|
+
/// judged by their PAINTED bounds, not their frame (`tokens` carries
|
|
209
|
+
/// the measurement seam the layout ran with), so a grow/stretch title
|
|
210
|
+
/// whose glyphs sit clear never pays a retry that would visibly shift
|
|
211
|
+
/// it — see `windowControlContentBounds`.
|
|
212
|
+
pub fn windowDragContentUnderWindowControls(nodes: []const WidgetLayoutNode, controls: geometry.RectF, tokens: DesignTokens) bool {
|
|
213
|
+
const cluster = controls.normalized();
|
|
214
|
+
if (cluster.width <= 0 or cluster.height <= 0) return false;
|
|
215
|
+
const layout = LayoutNodesView{ .nodes = nodes };
|
|
216
|
+
for (nodes, 0..) |node, index| {
|
|
217
|
+
if (!widget_access.isWindowDragRegion(node.widget)) continue;
|
|
218
|
+
if (widget_tree.isWidgetHiddenInAncestors(layout, index)) continue;
|
|
219
|
+
for (nodes, 0..) |candidate, candidate_index| {
|
|
220
|
+
if (candidate_index == index) continue;
|
|
221
|
+
if (!widgetIsWindowControlContent(candidate.widget)) continue;
|
|
222
|
+
const painted = windowControlContentBounds(candidate.widget, candidate.frame.normalized(), tokens);
|
|
223
|
+
if (geometry.RectF.intersection(painted, cluster).isEmpty()) continue;
|
|
224
|
+
if (widget_tree.isWidgetHiddenInAncestors(layout, candidate_index)) continue;
|
|
225
|
+
if (!layoutNodeHasAncestor(nodes, candidate_index, index)) continue;
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// The rect the cluster test judges for one content candidate. Controls
|
|
233
|
+
/// (buttons, inputs, ...) are judged by their full frame — the hit
|
|
234
|
+
/// surface is the control, glyphs or not. Single-line text leaves are
|
|
235
|
+
/// judged by their ALIGNED PAINTED BOUNDS instead: the measured line
|
|
236
|
+
/// width (capped at the frame — elision and clipping both keep painted
|
|
237
|
+
/// glyphs inside it), placed per the widget's text alignment, at the
|
|
238
|
+
/// frame's full height. A grow/stretch title spanning the header row
|
|
239
|
+
/// (the centered-title pattern) has a FRAME under the cluster while its
|
|
240
|
+
/// inked glyphs sit well clear; judging the frame would trigger the
|
|
241
|
+
/// clearance retry, and the remedy's trimmed content box would then
|
|
242
|
+
/// visibly shift the very title it exists to protect. Span paragraphs
|
|
243
|
+
/// wrap and explicit newlines stack lines with per-line extents; drag
|
|
244
|
+
/// headers are practically single-line, so anything that can break
|
|
245
|
+
/// keeps the conservative frame test.
|
|
246
|
+
fn windowControlContentBounds(widget: Widget, frame: geometry.RectF, tokens: DesignTokens) geometry.RectF {
|
|
247
|
+
if (widget.kind != .text) return frame;
|
|
248
|
+
if (widget.spans.len > 0) return frame;
|
|
249
|
+
if (std.mem.indexOfScalar(u8, widget.text, '\n') != null) return frame;
|
|
250
|
+
const measured = measuredTextWidth(tokens, widget.text, widgetBodyTextSize(widget, tokens));
|
|
251
|
+
const width = @min(measured, frame.width);
|
|
252
|
+
const dx: f32 = switch (widget.text_alignment) {
|
|
253
|
+
.start => 0,
|
|
254
|
+
.center => (frame.width - width) * 0.5,
|
|
255
|
+
.end => frame.width - width,
|
|
256
|
+
};
|
|
257
|
+
return geometry.RectF.init(frame.x + dx, frame.y, width, frame.height);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// Adapter so the shared ancestor-hidden walk (which reads
|
|
261
|
+
/// `layout.nodes`) runs over a bare node slice.
|
|
262
|
+
const LayoutNodesView = struct {
|
|
263
|
+
nodes: []const WidgetLayoutNode,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
fn layoutNodeHasAncestor(nodes: []const WidgetLayoutNode, node_index: usize, ancestor_index: usize) bool {
|
|
267
|
+
var current: ?usize = nodes[node_index].parent_index;
|
|
268
|
+
while (current) |index| {
|
|
269
|
+
if (index >= nodes.len) return false;
|
|
270
|
+
if (index == ancestor_index) return true;
|
|
271
|
+
current = nodes[index].parent_index;
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// Content the window-control cluster must never cover: readable leaves
|
|
277
|
+
/// and interactive controls. Deliberately exhaustive so a new widget
|
|
278
|
+
/// kind forces the honesty call here. Containers are transparent (their
|
|
279
|
+
/// CHILDREN are judged, not their frames), and decorative full-bleed
|
|
280
|
+
/// leaves — separators, skeletons, progress strips, images (header
|
|
281
|
+
/// cover art composites under the OS controls on every platform) — are
|
|
282
|
+
/// allowed under the cluster.
|
|
283
|
+
fn widgetIsWindowControlContent(widget: Widget) bool {
|
|
284
|
+
return switch (widget.kind) {
|
|
285
|
+
// Layout and surface containers: judged through their children.
|
|
286
|
+
.stack, .row, .column, .grid, .data_grid, .table, .scroll_view, .list, .breadcrumb, .button_group, .pagination, .radio_group, .tabs, .toggle_group, .accordion, .bubble, .resizable, .alert, .card, .dialog, .drawer, .sheet, .panel, .popover, .menu_surface, .dropdown_menu, .list_item, .data_row, .split, .tree, .input_group => false,
|
|
287
|
+
// Full-bleed decoration: expected under the cluster.
|
|
288
|
+
.separator, .skeleton, .progress, .image, .split_divider => false,
|
|
289
|
+
// A text leaf with no bytes and no spans is a hit/semantics
|
|
290
|
+
// overlay, not readable content.
|
|
291
|
+
.text => widget.text.len > 0 or widget.spans.len > 0,
|
|
292
|
+
.data_cell, .icon, .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, .spinner, .chart => true,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
160
296
|
fn layoutAnchoredChildren(
|
|
161
297
|
children: []const Widget,
|
|
162
298
|
anchor_rect: geometry.RectF,
|
|
@@ -70,18 +70,26 @@ pub fn widgetLineHeight(text_size: f32) f32 {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/// Wrap budget for text painted inside a pixel-snapped frame. Geometry
|
|
73
|
-
/// snapping
|
|
74
|
-
///
|
|
75
|
-
/// to
|
|
76
|
-
///
|
|
77
|
-
///
|
|
78
|
-
///
|
|
79
|
-
///
|
|
73
|
+
/// snapping rounds each frame EDGE to the device grid independently
|
|
74
|
+
/// (`pixelSnapGeometryRect`), so a frame at a fractional position can
|
|
75
|
+
/// lose up to a FULL device pixel of width — the left edge rounds up by
|
|
76
|
+
/// as much as half a pixel while the right edge rounds down by as much
|
|
77
|
+
/// as half — off the layout frame that intrinsic sizing measured with
|
|
78
|
+
/// the exact same metrics. That shave is enough to word-wrap an
|
|
79
|
+
/// exact-fit line mid-word ("Sort" painting as "Sor"/"t") or to elide a
|
|
80
|
+
/// hug-sized digit into "…" (the TS scaffold's centered counter on
|
|
81
|
+
/// Windows at scale 1, where the shave is coarsest). Hand the whole
|
|
82
|
+
/// snap quantum back to the budget so snapping never changes line
|
|
83
|
+
/// breaks or elision; glyph origins still snap independently. Epsilon
|
|
84
|
+
/// policy: a run's painted width may exceed its snapped frame by less
|
|
85
|
+
/// than `1/scale + text_elision_slack` before eliding — always below
|
|
86
|
+
/// the smallest real overflow (a glyph), so genuinely overflowing text
|
|
87
|
+
/// still elides and any admitted overhang stays sub-pixel-scale.
|
|
80
88
|
pub fn textWrapMaxWidth(tokens: DesignTokens, width: f32) f32 {
|
|
81
89
|
if (!tokens.pixel_snap.geometry) return width;
|
|
82
90
|
const scale = tokens.pixel_snap.scale;
|
|
83
91
|
if (!std.math.isFinite(scale) or scale <= 0) return width;
|
|
84
|
-
return width + 0
|
|
92
|
+
return width + 1.0 / scale;
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
/// The single source of truth for how a span paragraph (`.text` widget
|
package/src/runtime/core.zig
CHANGED
|
@@ -645,6 +645,22 @@ pub const Runtime = struct {
|
|
|
645
645
|
return self.surface.safe_area_insets;
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
+
/// The OS window-control cluster's frame in a canvas view's LOCAL
|
|
649
|
+
/// coordinates (Windows: the DWM min/max/close buttons; macOS: the
|
|
650
|
+
/// traffic lights), from the platform's live chrome report. Zero-sized
|
|
651
|
+
/// when no controls overlay the content — standard-chrome windows,
|
|
652
|
+
/// fullscreen, platforms without the concept — and translated by the
|
|
653
|
+
/// view's window-content frame so a docked canvas judges the overlap
|
|
654
|
+
/// in its own space. This is the geometry `UiApp` consults to keep a
|
|
655
|
+
/// drag header's content out from under the cluster.
|
|
656
|
+
pub fn windowControlsForView(self: *const Runtime, window_id: platform.WindowId, label: []const u8) geometry.RectF {
|
|
657
|
+
const zero = geometry.RectF.init(0, 0, 0, 0);
|
|
658
|
+
const buttons = self.options.platform.services.windowChrome(window_id).buttons.normalized();
|
|
659
|
+
if (buttons.width <= 0 or buttons.height <= 0) return zero;
|
|
660
|
+
const view_frame = (self.absoluteViewFrame(window_id, label, 0) catch return buttons).normalized();
|
|
661
|
+
return geometry.RectF.init(buttons.x - view_frame.x, buttons.y - view_frame.y, buttons.width, buttons.height);
|
|
662
|
+
}
|
|
663
|
+
|
|
648
664
|
pub fn listCommands(self: *const Runtime, output: []Command) []const Command {
|
|
649
665
|
const count = @min(output.len, self.options.commands.len);
|
|
650
666
|
for (self.options.commands[0..count], 0..) |command, index| {
|