@native-sdk/cli 0.4.1 → 0.4.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/assets/native-sdk.manifest +17 -1
- package/build/app.zig +40 -1
- package/build.zig +49 -3
- package/package.json +10 -9
- package/src/platform/macos/appkit_host.m +21 -6
- package/src/platform/windows/webview2_host.cpp +377 -72
- package/src/primitives/canvas/chart.zig +8 -7
- package/src/primitives/canvas/chart_tests.zig +2 -2
- package/src/primitives/canvas/commands.zig +27 -0
- package/src/primitives/canvas/gpu.zig +8 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -1
- package/src/primitives/canvas/reference.zig +82 -3
- package/src/primitives/canvas/reference_tests.zig +155 -1
- package/src/primitives/canvas/serialization.zig +16 -3
- package/src/primitives/canvas/themes/geist.zig +6 -0
- package/src/primitives/canvas/tokens.zig +7 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +191 -0
- package/src/primitives/canvas/widget_render.zig +29 -41
- package/src/primitives/canvas/widget_render_controls.zig +55 -42
- package/src/primitives/canvas/widget_render_style.zig +53 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
- package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
- package/src/runtime/canvas_frame_packet_tests.zig +9 -1
- package/src/runtime/canvas_frame_patch_tests.zig +39 -1
- package/src/runtime/canvas_widget_control_tests.zig +4 -4
- package/src/runtime/ui_app.zig +78 -10
- package/src/runtime/ui_app_tests.zig +109 -0
- package/src/runtime/ui_app_window_tests.zig +93 -0
- package/src/tooling/package.zig +45 -0
- package/src/tooling/templates.zig +42 -1
- package/third_party/webview2/LICENSE.txt +27 -0
- package/third_party/webview2/README.md +19 -0
- package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
- package/third_party/webview2/include/EventToken.h +12 -0
- package/third_party/webview2/include/WebView2.h +60636 -0
- package/third_party/webview2/x64/WebView2Loader.dll +0 -0
|
@@ -9,6 +9,7 @@ const widget_access = @import("widget_access.zig");
|
|
|
9
9
|
const widget_metrics = @import("widget_metrics.zig");
|
|
10
10
|
const widget_text_input = @import("widget_text_input.zig");
|
|
11
11
|
const widget_render_style = @import("widget_render_style.zig");
|
|
12
|
+
const widget_render = @import("widget_render.zig");
|
|
12
13
|
const icon_model = @import("icons.zig");
|
|
13
14
|
const svg_icon_model = @import("svg_icon.zig");
|
|
14
15
|
|
|
@@ -74,6 +75,7 @@ const controlRadius = widget_render_style.controlRadius;
|
|
|
74
75
|
const buttonControlRadius = widget_render_style.buttonControlRadius;
|
|
75
76
|
const widgetSizedRadiusValue = widget_render_style.widgetSizedRadiusValue;
|
|
76
77
|
const controlStrokeWidth = widget_render_style.controlStrokeWidth;
|
|
78
|
+
const snapHairlineStrokeRect = widget_render_style.snapHairlineStrokeRect;
|
|
77
79
|
const buttonFill = widget_render_style.buttonFill;
|
|
78
80
|
const buttonTextColorForWidget = widget_render_style.buttonTextColorForWidget;
|
|
79
81
|
const buttonBorderFill = widget_render_style.buttonBorderFill;
|
|
@@ -294,30 +296,35 @@ fn buttonGroupSegmentRadius(widget: Widget, visual: ControlVisualTokens, tokens:
|
|
|
294
296
|
/// freed by the retired button shadow.
|
|
295
297
|
fn emitButtonBorder(builder: *Builder, widget: Widget, tokens: DesignTokens, radius: Radius) Error!void {
|
|
296
298
|
const stroke_width = buttonStrokeWidth(widget, tokens);
|
|
299
|
+
const border = snapHairlineStrokeRect(tokens, .{
|
|
300
|
+
.id = widgetPartId(widget.id, 2),
|
|
301
|
+
.rect = widget.frame,
|
|
302
|
+
.radius = radius,
|
|
303
|
+
.stroke = .{
|
|
304
|
+
.fill = buttonBorderFill(widget, tokens),
|
|
305
|
+
.width = stroke_width,
|
|
306
|
+
},
|
|
307
|
+
});
|
|
297
308
|
// Seams exist only in the segmented register — a detached chip has
|
|
298
309
|
// no shared boundary to collapse.
|
|
299
310
|
const drop_left_border = !widget_render_style.buttonInDetachedGroup(widget, tokens) and
|
|
300
311
|
(widget.group_segment == .middle or widget.group_segment == .last);
|
|
301
312
|
if (drop_left_border) {
|
|
313
|
+
// The clip's left edge sits on the border band's INNER edge —
|
|
314
|
+
// computed from the (possibly snapped) emitted stroke, so the
|
|
315
|
+
// whole left band drops whether or not snapping moved it.
|
|
316
|
+
const band_inner_x = border.rect.x + border.stroke.width * 0.5;
|
|
302
317
|
try builder.pushClip(.{
|
|
303
318
|
.id = widgetPartId(widget.id, 0),
|
|
304
319
|
.rect = geometry.RectF.init(
|
|
305
|
-
|
|
320
|
+
band_inner_x,
|
|
306
321
|
widget.frame.y - stroke_width,
|
|
307
|
-
@max(0, widget.frame.
|
|
322
|
+
@max(0, widget.frame.maxX() + stroke_width - band_inner_x),
|
|
308
323
|
widget.frame.height + stroke_width * 2,
|
|
309
324
|
),
|
|
310
325
|
});
|
|
311
326
|
}
|
|
312
|
-
try builder.strokeRect(
|
|
313
|
-
.id = widgetPartId(widget.id, 2),
|
|
314
|
-
.rect = widget.frame,
|
|
315
|
-
.radius = radius,
|
|
316
|
-
.stroke = .{
|
|
317
|
-
.fill = buttonBorderFill(widget, tokens),
|
|
318
|
-
.width = stroke_width,
|
|
319
|
-
},
|
|
320
|
-
});
|
|
327
|
+
try builder.strokeRect(border);
|
|
321
328
|
if (drop_left_border) try builder.popClip();
|
|
322
329
|
}
|
|
323
330
|
|
|
@@ -404,7 +411,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
404
411
|
.radius = radius,
|
|
405
412
|
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed, washHovered(widget), tokens.colors.surface))),
|
|
406
413
|
});
|
|
407
|
-
try builder.strokeRect(.{
|
|
414
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
408
415
|
.id = widgetPartId(widget.id, 2),
|
|
409
416
|
.rect = widget.frame,
|
|
410
417
|
.radius = radius,
|
|
@@ -412,7 +419,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
412
419
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
413
420
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
414
421
|
},
|
|
415
|
-
});
|
|
422
|
+
}));
|
|
416
423
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 6, widget.frame, radius);
|
|
417
424
|
if (visible_text.len > 0) {
|
|
418
425
|
const text_color = if (is_placeholder)
|
|
@@ -467,7 +474,7 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
|
|
|
467
474
|
.radius = radius,
|
|
468
475
|
.fill = textInputFill(widget, tokens, visual),
|
|
469
476
|
});
|
|
470
|
-
try builder.strokeRect(.{
|
|
477
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
471
478
|
.id = widgetPartId(widget.id, 2),
|
|
472
479
|
.rect = widget.frame,
|
|
473
480
|
.radius = radius,
|
|
@@ -475,7 +482,7 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
|
|
|
475
482
|
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
476
483
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
477
484
|
},
|
|
478
|
-
});
|
|
485
|
+
}));
|
|
479
486
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 7, widget.frame, radius);
|
|
480
487
|
if (clips_text) try builder.pushClip(.{ .id = widgetPartId(widget.id, 16), .rect = clip_rect, .radius = radius });
|
|
481
488
|
if (selection_range) |range| {
|
|
@@ -529,7 +536,7 @@ pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTok
|
|
|
529
536
|
.radius = radius,
|
|
530
537
|
.fill = textInputFill(widget, tokens, visual),
|
|
531
538
|
});
|
|
532
|
-
try builder.strokeRect(.{
|
|
539
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
533
540
|
.id = widgetPartId(widget.id, 2),
|
|
534
541
|
.rect = widget.frame,
|
|
535
542
|
.radius = radius,
|
|
@@ -537,7 +544,7 @@ pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTok
|
|
|
537
544
|
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
538
545
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
539
546
|
},
|
|
540
|
-
});
|
|
547
|
+
}));
|
|
541
548
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, widget.frame, radius);
|
|
542
549
|
}
|
|
543
550
|
|
|
@@ -560,7 +567,7 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
560
567
|
.radius = radius,
|
|
561
568
|
.fill = textInputFill(widget, tokens, visual),
|
|
562
569
|
});
|
|
563
|
-
try builder.strokeRect(.{
|
|
570
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
564
571
|
.id = widgetPartId(widget.id, 2),
|
|
565
572
|
.rect = widget.frame,
|
|
566
573
|
.radius = radius,
|
|
@@ -568,7 +575,7 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
568
575
|
.fill = textInputBorderFill(widget, visual, tokens.colors.border),
|
|
569
576
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
570
577
|
},
|
|
571
|
-
});
|
|
578
|
+
}));
|
|
572
579
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 14, widget.frame, radius);
|
|
573
580
|
try emitSearchFieldIcon(builder, widget, tokens, icon_size);
|
|
574
581
|
if (selection_range) |range| {
|
|
@@ -871,14 +878,14 @@ pub fn emitDataCellWidgetChrome(builder: *Builder, widget: Widget, tokens: Desig
|
|
|
871
878
|
// border/stroke opts a cell back into an edge.
|
|
872
879
|
const wants_stroke = widget.style.border != null or visual.border != null or widget.style.stroke_width != null or visual.stroke_width != null;
|
|
873
880
|
if (wants_stroke) {
|
|
874
|
-
try builder.strokeRect(.{
|
|
881
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
875
882
|
.id = widgetPartId(widget.id, 2),
|
|
876
883
|
.rect = widget.frame,
|
|
877
884
|
.stroke = .{
|
|
878
885
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
879
886
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
880
887
|
},
|
|
881
|
-
});
|
|
888
|
+
}));
|
|
882
889
|
}
|
|
883
890
|
if (widget.state.focused) try emitWidgetFocusRing(builder, widget, tokens, 3);
|
|
884
891
|
return visual;
|
|
@@ -954,7 +961,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
|
|
|
954
961
|
});
|
|
955
962
|
}
|
|
956
963
|
if (selected) {
|
|
957
|
-
try builder.strokeRect(.{
|
|
964
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
958
965
|
.id = widgetPartId(widget.id, 2),
|
|
959
966
|
.rect = widget.frame,
|
|
960
967
|
.radius = radius,
|
|
@@ -962,7 +969,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
|
|
|
962
969
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
963
970
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
964
971
|
},
|
|
965
|
-
});
|
|
972
|
+
}));
|
|
966
973
|
}
|
|
967
974
|
},
|
|
968
975
|
// The underline treatment: triggers are bare text — no pill, no
|
|
@@ -1023,7 +1030,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
|
|
|
1023
1030
|
else
|
|
1024
1031
|
colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
|
|
1025
1032
|
});
|
|
1026
|
-
try builder.strokeRect(.{
|
|
1033
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
1027
1034
|
.id = widgetPartId(widget.id, 2),
|
|
1028
1035
|
.rect = box,
|
|
1029
1036
|
.radius = radius,
|
|
@@ -1031,7 +1038,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
|
|
|
1031
1038
|
.fill = colorFill(disabledWash(if (selected) widgetAccentColor(widget, visual.border orelse visual.active_background orelse tokens.colors.accent) else widgetBorderColor(widget, visual.border orelse tokens.colors.border), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1032
1039
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1033
1040
|
},
|
|
1034
|
-
});
|
|
1041
|
+
}));
|
|
1035
1042
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, box, radius);
|
|
1036
1043
|
if (selected) {
|
|
1037
1044
|
// The check keeps the accent-foreground tint even when disabled
|
|
@@ -1041,17 +1048,23 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
|
|
|
1041
1048
|
const left = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.26, box.y + box.height * 0.54));
|
|
1042
1049
|
const mid = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.43, box.y + box.height * 0.70));
|
|
1043
1050
|
const right = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.76, box.y + box.height * 0.32));
|
|
1044
|
-
|
|
1051
|
+
// ONE stroked polyline through the vector core, not a pair of
|
|
1052
|
+
// line commands: `draw_line` rasterizes as a hard-edged capsule
|
|
1053
|
+
// (exact for the axis-aligned hairlines it serves), which turns
|
|
1054
|
+
// this diagonal into staircase chunks at control sizes. The
|
|
1055
|
+
// stroke path gets the same anti-aliased coverage and round
|
|
1056
|
+
// caps/joins the built-in stroke icons get, so the mark reads
|
|
1057
|
+
// crisp and even at 1x — same three snapped vertices, so the
|
|
1058
|
+
// drawn shape is unchanged.
|
|
1059
|
+
const elements = try builder.allocPathElements(3);
|
|
1060
|
+
elements[0] = .{ .verb = .move_to, .points = .{ left, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1061
|
+
elements[1] = .{ .verb = .line_to, .points = .{ mid, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1062
|
+
elements[2] = .{ .verb = .line_to, .points = .{ right, geometry.PointF.zero(), geometry.PointF.zero() } };
|
|
1063
|
+
try builder.strokePath(.{
|
|
1045
1064
|
.id = widgetPartId(widget.id, 4),
|
|
1046
|
-
.
|
|
1047
|
-
.to = mid,
|
|
1048
|
-
.stroke = .{ .fill = colorFill(check_color), .width = 2 },
|
|
1049
|
-
});
|
|
1050
|
-
try builder.drawLine(.{
|
|
1051
|
-
.id = widgetPartId(widget.id, 5),
|
|
1052
|
-
.from = mid,
|
|
1053
|
-
.to = right,
|
|
1065
|
+
.elements = elements,
|
|
1054
1066
|
.stroke = .{ .fill = colorFill(check_color), .width = 2 },
|
|
1067
|
+
.cap = .round,
|
|
1055
1068
|
});
|
|
1056
1069
|
}
|
|
1057
1070
|
try emitControlLabelWithColor(builder, widget, tokens, box.x + box.width + widgetControlInset(widget, tokens, tokens.spacing.sm), 6, visual.foreground orelse tokens.colors.text);
|
|
@@ -1068,7 +1081,7 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1068
1081
|
.radius = radius,
|
|
1069
1082
|
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
|
|
1070
1083
|
});
|
|
1071
|
-
try builder.strokeRect(.{
|
|
1084
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
1072
1085
|
.id = widgetPartId(widget.id, 2),
|
|
1073
1086
|
.rect = circle,
|
|
1074
1087
|
.radius = radius,
|
|
@@ -1078,7 +1091,7 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1078
1091
|
.fill = colorFill(disabledWash(widgetBorderColor(widget, visual.border orelse tokens.colors.border), widget.state.disabled, tokens.states.disabled_alpha)),
|
|
1079
1092
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1080
1093
|
},
|
|
1081
|
-
});
|
|
1094
|
+
}));
|
|
1082
1095
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, circle, radius);
|
|
1083
1096
|
if (selected) {
|
|
1084
1097
|
const dot_size = @max(0, circle.height * 0.5);
|
|
@@ -1128,7 +1141,7 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1128
1141
|
const wants_track_stroke = widget.style.border != null or visual.border != null;
|
|
1129
1142
|
const track_stroke_width = controlStrokeWidth(widget, visual, if (wants_track_stroke) tokens.stroke.regular else 0);
|
|
1130
1143
|
if (track_stroke_width > 0) {
|
|
1131
|
-
try builder.strokeRect(.{
|
|
1144
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
1132
1145
|
.id = widgetPartId(widget.id, 2),
|
|
1133
1146
|
.rect = track,
|
|
1134
1147
|
.radius = track_radius,
|
|
@@ -1136,7 +1149,7 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1136
1149
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
1137
1150
|
.width = track_stroke_width,
|
|
1138
1151
|
},
|
|
1139
|
-
});
|
|
1152
|
+
}));
|
|
1140
1153
|
}
|
|
1141
1154
|
try builder.fillRoundedRect(.{
|
|
1142
1155
|
.id = widgetPartId(widget.id, 3),
|
|
@@ -1215,7 +1228,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1215
1228
|
// The thumb's resting hairline wears the focus-ring neutral (a mid
|
|
1216
1229
|
// gray in both schemes), so the ring on focus reads as a brighter
|
|
1217
1230
|
// echo of an edge the control already owns — not a recolor.
|
|
1218
|
-
try builder.strokeRect(.{
|
|
1231
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
1219
1232
|
.id = widgetPartId(widget.id, 4),
|
|
1220
1233
|
.rect = knob,
|
|
1221
1234
|
.radius = knob_radius,
|
|
@@ -1223,7 +1236,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
|
|
|
1223
1236
|
.fill = widgetBorderFill(widget, disabledWash(visual.border orelse tokens.colors.focus_ring, washed, tokens.states.disabled_alpha)),
|
|
1224
1237
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
|
|
1225
1238
|
},
|
|
1226
|
-
});
|
|
1239
|
+
}));
|
|
1227
1240
|
if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 5, knob, knob_radius);
|
|
1228
1241
|
}
|
|
1229
1242
|
|
|
@@ -1332,7 +1345,7 @@ fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens,
|
|
|
1332
1345
|
/// (`stroke.focus_offset`) outside it, so focus adds an outline instead
|
|
1333
1346
|
/// of recoloring the control's edge.
|
|
1334
1347
|
fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignTokens, slot: ObjectId, rect: geometry.RectF, radius: Radius) Error!void {
|
|
1335
|
-
try builder.strokeRect(.{
|
|
1348
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
1336
1349
|
.id = widgetPartId(widget.id, slot),
|
|
1337
1350
|
.rect = widget_render_style.focusRingRect(rect, tokens),
|
|
1338
1351
|
.radius = widget_render_style.focusRingRadius(radius, tokens),
|
|
@@ -1340,7 +1353,7 @@ fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignT
|
|
|
1340
1353
|
.fill = widgetFocusRingFill(widget, tokens),
|
|
1341
1354
|
.width = tokens.stroke.focus,
|
|
1342
1355
|
},
|
|
1343
|
-
});
|
|
1356
|
+
}));
|
|
1344
1357
|
}
|
|
1345
1358
|
|
|
1346
1359
|
fn emitControlLabelWithColor(builder: *Builder, widget: Widget, tokens: DesignTokens, x: f32, slot: ObjectId, color: Color) Error!void {
|
|
@@ -7,11 +7,64 @@ const widget_model = @import("widgets.zig");
|
|
|
7
7
|
const Color = drawing_model.Color;
|
|
8
8
|
const Fill = drawing_model.Fill;
|
|
9
9
|
const Radius = drawing_model.Radius;
|
|
10
|
+
const StrokeRect = drawing_model.StrokeRect;
|
|
10
11
|
const DesignTokens = token_model.DesignTokens;
|
|
11
12
|
const ControlVisualTokens = token_model.ControlVisualTokens;
|
|
12
13
|
const Widget = widget_model.Widget;
|
|
13
14
|
const WidgetState = widget_model.WidgetState;
|
|
14
15
|
|
|
16
|
+
/// Snap a hairline border to the device-pixel grid at emit time. A
|
|
17
|
+
/// stroke centered on its rect straddles the boundary by half its
|
|
18
|
+
/// width, so a 1-device-pixel border rasterizes as two half-covered
|
|
19
|
+
/// columns — geometrically faithful but visually soft. Eligibility is
|
|
20
|
+
/// judged on the ROUNDED device width: strokes rounding to one or two
|
|
21
|
+
/// device pixels snap, wider borders keep true geometry, and a width
|
|
22
|
+
/// that rounds to zero stays unsnapped rather than darkening a
|
|
23
|
+
/// sub-half-pixel stroke to a full column. An eligible stroke takes the
|
|
24
|
+
/// FLOOR of its exact device width, never below one pixel, so a
|
|
25
|
+
/// fractional width lands on the lighter whole-pixel neighbor — a 1px
|
|
26
|
+
/// logical border at a 1.5x scale covers one device column, not two.
|
|
27
|
+
/// A hairline is a boundary, not content: when the grid forces a
|
|
28
|
+
/// choice, crisp-and-light reads better than crisp-and-heavy. The snap
|
|
29
|
+
/// moves each frame edge to the grid and pulls the centerline INWARD
|
|
30
|
+
/// by half the snapped width, so the band covers exactly that many
|
|
31
|
+
/// whole device columns and rows with its outer silhouette on the
|
|
32
|
+
/// widget frame (never bleeding past layout bounds). Corner radii
|
|
33
|
+
/// shrink by the same inset so the outer arc keeps the frame's radius,
|
|
34
|
+
/// and the arcs stay smooth: the snapped geometry is still one rounded
|
|
35
|
+
/// rect, rasterized by one continuous coverage field. Inactive without
|
|
36
|
+
/// the pixel-snap geometry token or a usable scale, so fractional
|
|
37
|
+
/// device scales snap in DEVICE space and unsnapped surfaces render
|
|
38
|
+
/// untouched.
|
|
39
|
+
pub fn snapHairlineStrokeRect(tokens: DesignTokens, value: StrokeRect) StrokeRect {
|
|
40
|
+
if (!tokens.pixel_snap.geometry) return value;
|
|
41
|
+
const scale = tokens.pixel_snap.scale;
|
|
42
|
+
if (!std.math.isFinite(scale) or scale <= 0) return value;
|
|
43
|
+
const exact_device_width = nonNegative(value.stroke.width) * scale;
|
|
44
|
+
const rounded_device_width = @round(exact_device_width);
|
|
45
|
+
if (rounded_device_width < 1 or rounded_device_width > 2) return value;
|
|
46
|
+
const device_width = @max(1, @floor(exact_device_width));
|
|
47
|
+
const rect = value.rect.normalized();
|
|
48
|
+
if (rect.isEmpty()) return value;
|
|
49
|
+
const half_device = device_width * 0.5;
|
|
50
|
+
const x0 = (@round(rect.x * scale) + half_device) / scale;
|
|
51
|
+
const y0 = (@round(rect.y * scale) + half_device) / scale;
|
|
52
|
+
const x1 = (@round(rect.maxX() * scale) - half_device) / scale;
|
|
53
|
+
const y1 = (@round(rect.maxY() * scale) - half_device) / scale;
|
|
54
|
+
if (x1 <= x0 or y1 <= y0) return value;
|
|
55
|
+
const inset = half_device / scale;
|
|
56
|
+
var snapped = value;
|
|
57
|
+
snapped.rect = geometry.RectF.init(x0, y0, x1 - x0, y1 - y0);
|
|
58
|
+
snapped.radius = .{
|
|
59
|
+
.top_left = @max(0, value.radius.top_left - inset),
|
|
60
|
+
.top_right = @max(0, value.radius.top_right - inset),
|
|
61
|
+
.bottom_right = @max(0, value.radius.bottom_right - inset),
|
|
62
|
+
.bottom_left = @max(0, value.radius.bottom_left - inset),
|
|
63
|
+
};
|
|
64
|
+
snapped.stroke.width = device_width / scale;
|
|
65
|
+
return snapped;
|
|
66
|
+
}
|
|
67
|
+
|
|
15
68
|
/// The frame the focus ring strokes: the control rect pushed out by the
|
|
16
69
|
/// ring-offset token (`stroke.focus_offset`) — the control keeps its
|
|
17
70
|
/// own border and the ring floats that gap outside it, so focus never
|
|
@@ -40,6 +40,7 @@ const widgetForegroundColor = widget_render_style.widgetForegroundColor;
|
|
|
40
40
|
const widgetRadius = widget_render_style.widgetRadius;
|
|
41
41
|
const controlRadius = widget_render_style.controlRadius;
|
|
42
42
|
const controlStrokeWidth = widget_render_style.controlStrokeWidth;
|
|
43
|
+
const snapHairlineStrokeRect = widget_render_style.snapHairlineStrokeRect;
|
|
43
44
|
const buttonStateBackground = widget_render_style.buttonStateBackground;
|
|
44
45
|
const washHovered = widget_render_style.washHovered;
|
|
45
46
|
const alertControlVisualTokens = widget_render_style.alertControlVisualTokens;
|
|
@@ -58,7 +59,7 @@ pub fn emitAlertWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
58
59
|
.radius = radius,
|
|
59
60
|
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.surface))),
|
|
60
61
|
});
|
|
61
|
-
try builder.strokeRect(.{
|
|
62
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
62
63
|
.id = widgetPartId(widget.id, 2),
|
|
63
64
|
.rect = widget.frame,
|
|
64
65
|
.radius = radius,
|
|
@@ -66,7 +67,7 @@ pub fn emitAlertWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
66
67
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
67
68
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
68
69
|
},
|
|
69
|
-
});
|
|
70
|
+
}));
|
|
70
71
|
if (widget.text.len == 0) return;
|
|
71
72
|
|
|
72
73
|
// The house style alert geometry: a FIXED 16px icon centered on the first
|
|
@@ -144,7 +145,7 @@ pub fn emitCardWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTok
|
|
|
144
145
|
.radius = radius,
|
|
145
146
|
.fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.surface))),
|
|
146
147
|
});
|
|
147
|
-
try builder.strokeRect(.{
|
|
148
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
148
149
|
.id = widgetPartId(widget.id, 2),
|
|
149
150
|
.rect = widget.frame,
|
|
150
151
|
.radius = radius,
|
|
@@ -152,7 +153,7 @@ pub fn emitCardWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTok
|
|
|
152
153
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
153
154
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
154
155
|
},
|
|
155
|
-
});
|
|
156
|
+
}));
|
|
156
157
|
if (widget.text.len == 0) return;
|
|
157
158
|
|
|
158
159
|
const title_size = widgetTypographySize(widget, tokens.typography.body_size + 1);
|
|
@@ -207,7 +208,7 @@ pub fn emitModalSurfaceWidgetChrome(builder: *Builder, widget: Widget, tokens: D
|
|
|
207
208
|
.radius = radius,
|
|
208
209
|
.fill = widgetBackgroundFill(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.surface)),
|
|
209
210
|
});
|
|
210
|
-
try builder.strokeRect(.{
|
|
211
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
211
212
|
.id = widgetPartId(widget.id, 3),
|
|
212
213
|
.rect = widget.frame,
|
|
213
214
|
.radius = radius,
|
|
@@ -215,7 +216,7 @@ pub fn emitModalSurfaceWidgetChrome(builder: *Builder, widget: Widget, tokens: D
|
|
|
215
216
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
216
217
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
217
218
|
},
|
|
218
|
-
});
|
|
219
|
+
}));
|
|
219
220
|
if (widget.text.len == 0) return;
|
|
220
221
|
|
|
221
222
|
const title_size = widgetTypographySize(widget, tokens.typography.title_size);
|
|
@@ -264,7 +265,7 @@ pub fn emitPanelWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
264
265
|
.radius = radius,
|
|
265
266
|
.fill = colorFill(background),
|
|
266
267
|
});
|
|
267
|
-
try builder.strokeRect(.{
|
|
268
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
268
269
|
.id = widgetPartId(widget.id, 3),
|
|
269
270
|
.rect = widget.frame,
|
|
270
271
|
.radius = radius,
|
|
@@ -272,7 +273,7 @@ pub fn emitPanelWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTo
|
|
|
272
273
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
273
274
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
274
275
|
},
|
|
275
|
-
});
|
|
276
|
+
}));
|
|
276
277
|
if (widget.kind == .resizable) try emitResizableWidgetHandle(builder, widget, tokens, visual);
|
|
277
278
|
}
|
|
278
279
|
|
|
@@ -320,7 +321,7 @@ pub fn emitBubbleWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignT
|
|
|
320
321
|
});
|
|
321
322
|
}
|
|
322
323
|
if (bubbleBorderColor(widget, tokens)) |border| {
|
|
323
|
-
try builder.strokeRect(.{
|
|
324
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
324
325
|
.id = widgetPartId(widget.id, 3),
|
|
325
326
|
.rect = widget.frame,
|
|
326
327
|
.radius = radius,
|
|
@@ -328,7 +329,7 @@ pub fn emitBubbleWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignT
|
|
|
328
329
|
.fill = colorFill(border),
|
|
329
330
|
.width = controlStrokeWidth(widget, tokens.controls.bubble, tokens.stroke.hairline),
|
|
330
331
|
},
|
|
331
|
-
});
|
|
332
|
+
}));
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
335
|
|
|
@@ -599,7 +600,7 @@ pub fn emitTabsListWidgetChrome(builder: *Builder, widget: Widget, tokens: Desig
|
|
|
599
600
|
.fill = colorFill(widgetBackgroundColor(widget, visual.background orelse tokens.colors.surface_subtle)),
|
|
600
601
|
});
|
|
601
602
|
if (widget.style.border orelse visual.border) |border| {
|
|
602
|
-
try builder.strokeRect(.{
|
|
603
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
603
604
|
.id = widgetPartId(widget.id, 2),
|
|
604
605
|
.rect = frame,
|
|
605
606
|
.radius = radius,
|
|
@@ -607,7 +608,7 @@ pub fn emitTabsListWidgetChrome(builder: *Builder, widget: Widget, tokens: Desig
|
|
|
607
608
|
.fill = colorFill(border),
|
|
608
609
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
609
610
|
},
|
|
610
|
-
});
|
|
611
|
+
}));
|
|
611
612
|
}
|
|
612
613
|
},
|
|
613
614
|
.underline => {
|
|
@@ -691,7 +692,7 @@ pub fn emitPopoverWidgetChrome(builder: *Builder, widget: Widget, tokens: Design
|
|
|
691
692
|
.radius = radius,
|
|
692
693
|
.fill = widgetBackgroundFill(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.surface)),
|
|
693
694
|
});
|
|
694
|
-
try builder.strokeRect(.{
|
|
695
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
695
696
|
.id = widgetPartId(widget.id, 3),
|
|
696
697
|
.rect = widget.frame,
|
|
697
698
|
.radius = radius,
|
|
@@ -699,7 +700,7 @@ pub fn emitPopoverWidgetChrome(builder: *Builder, widget: Widget, tokens: Design
|
|
|
699
700
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
700
701
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
701
702
|
},
|
|
702
|
-
});
|
|
703
|
+
}));
|
|
703
704
|
}
|
|
704
705
|
|
|
705
706
|
pub fn emitMenuSurfaceWidgetChrome(builder: *Builder, widget: Widget, tokens: DesignTokens) Error!void {
|
|
@@ -724,7 +725,7 @@ pub fn emitMenuSurfaceWidgetChrome(builder: *Builder, widget: Widget, tokens: De
|
|
|
724
725
|
.radius = radius,
|
|
725
726
|
.fill = widgetBackgroundFill(widget, buttonStateBackground(visual, widget.state.pressed or widget.state.selected, washHovered(widget), tokens.colors.surface)),
|
|
726
727
|
});
|
|
727
|
-
try builder.strokeRect(.{
|
|
728
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
728
729
|
.id = widgetPartId(widget.id, 3),
|
|
729
730
|
.rect = widget.frame,
|
|
730
731
|
.radius = radius,
|
|
@@ -732,7 +733,7 @@ pub fn emitMenuSurfaceWidgetChrome(builder: *Builder, widget: Widget, tokens: De
|
|
|
732
733
|
.fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
|
|
733
734
|
.width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
|
|
734
735
|
},
|
|
735
|
-
});
|
|
736
|
+
}));
|
|
736
737
|
}
|
|
737
738
|
|
|
738
739
|
fn pixelSnapScale(tokens: DesignTokens) ?f32 {
|
|
@@ -782,7 +783,7 @@ fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens,
|
|
|
782
783
|
// The shared ring-offset treatment: a concentric ring the
|
|
783
784
|
// token-stated gap outside the widget's own border (see
|
|
784
785
|
// widget_render_style).
|
|
785
|
-
try builder.strokeRect(.{
|
|
786
|
+
try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
|
|
786
787
|
.id = widgetPartId(widget.id, slot),
|
|
787
788
|
.rect = widget_render_style.focusRingRect(widget.frame, tokens),
|
|
788
789
|
.radius = widget_render_style.focusRingRadius(widgetRadius(widget, tokens.radius.md), tokens),
|
|
@@ -790,5 +791,5 @@ fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens,
|
|
|
790
791
|
.fill = widgetFocusRingFill(widget, tokens),
|
|
791
792
|
.width = tokens.stroke.focus,
|
|
792
793
|
},
|
|
793
|
-
});
|
|
794
|
+
}));
|
|
794
795
|
}
|
|
@@ -1907,7 +1907,7 @@ test "widget emitter applies selection and range control tokens" {
|
|
|
1907
1907
|
try emitWidgetTree(&builder, .{ .id = 64, .kind = .progress, .frame = geometry.RectF.init(0, 172, 160, 8), .value = 0.5 }, tokens);
|
|
1908
1908
|
|
|
1909
1909
|
const display_list = builder.displayList();
|
|
1910
|
-
try std.testing.expectEqual(@as(usize,
|
|
1910
|
+
try std.testing.expectEqual(@as(usize, 17), display_list.commandCount());
|
|
1911
1911
|
switch (display_list.commands[0]) {
|
|
1912
1912
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(30, 50, 70), fill.fill),
|
|
1913
1913
|
else => return error.TestUnexpectedResult,
|
|
@@ -1925,34 +1925,34 @@ test "widget emitter applies selection and range control tokens" {
|
|
|
1925
1925
|
else => return error.TestUnexpectedResult,
|
|
1926
1926
|
}
|
|
1927
1927
|
switch (display_list.commands[5]) {
|
|
1928
|
-
.
|
|
1928
|
+
.stroke_path => |stroke| try expectFillColor(Color.rgb8(250, 252, 255), stroke.stroke.fill),
|
|
1929
1929
|
else => return error.TestUnexpectedResult,
|
|
1930
1930
|
}
|
|
1931
|
-
switch (display_list.commands[
|
|
1931
|
+
switch (display_list.commands[7]) {
|
|
1932
1932
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(34, 70, 108), fill.fill),
|
|
1933
1933
|
else => return error.TestUnexpectedResult,
|
|
1934
1934
|
}
|
|
1935
|
-
switch (display_list.commands[
|
|
1935
|
+
switch (display_list.commands[9]) {
|
|
1936
1936
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(248, 250, 252), fill.fill),
|
|
1937
1937
|
else => return error.TestUnexpectedResult,
|
|
1938
1938
|
}
|
|
1939
|
-
switch (display_list.commands[
|
|
1939
|
+
switch (display_list.commands[11]) {
|
|
1940
1940
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(50, 56, 64), fill.fill),
|
|
1941
1941
|
else => return error.TestUnexpectedResult,
|
|
1942
1942
|
}
|
|
1943
|
-
switch (display_list.commands[
|
|
1943
|
+
switch (display_list.commands[12]) {
|
|
1944
1944
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(38, 76, 114), fill.fill),
|
|
1945
1945
|
else => return error.TestUnexpectedResult,
|
|
1946
1946
|
}
|
|
1947
|
-
switch (display_list.commands[
|
|
1947
|
+
switch (display_list.commands[13]) {
|
|
1948
1948
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(246, 248, 250), fill.fill),
|
|
1949
1949
|
else => return error.TestUnexpectedResult,
|
|
1950
1950
|
}
|
|
1951
|
-
switch (display_list.commands[
|
|
1951
|
+
switch (display_list.commands[15]) {
|
|
1952
1952
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(52, 58, 66), fill.fill),
|
|
1953
1953
|
else => return error.TestUnexpectedResult,
|
|
1954
1954
|
}
|
|
1955
|
-
switch (display_list.commands[
|
|
1955
|
+
switch (display_list.commands[16]) {
|
|
1956
1956
|
.fill_rounded_rect => |fill| try expectFillColor(Color.rgb8(40, 80, 120), fill.fill),
|
|
1957
1957
|
else => return error.TestUnexpectedResult,
|
|
1958
1958
|
}
|
|
@@ -2642,57 +2642,56 @@ test "widget emitter renders checkbox radio switch and slider controls" {
|
|
|
2642
2642
|
}, tokens);
|
|
2643
2643
|
|
|
2644
2644
|
const display_list = builder.displayList();
|
|
2645
|
-
try std.testing.expectEqual(@as(usize,
|
|
2645
|
+
try std.testing.expectEqual(@as(usize, 18), display_list.commandCount());
|
|
2646
2646
|
switch (display_list.commands[0]) {
|
|
2647
2647
|
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
2648
2648
|
else => return error.TestUnexpectedResult,
|
|
2649
2649
|
}
|
|
2650
|
-
try std.testing.expect(display_list.commands[3] == .
|
|
2651
|
-
|
|
2652
|
-
switch (display_list.commands[5]) {
|
|
2650
|
+
try std.testing.expect(display_list.commands[3] == .stroke_path);
|
|
2651
|
+
switch (display_list.commands[4]) {
|
|
2653
2652
|
.draw_text => |text| try std.testing.expectEqualStrings("Live", text.text),
|
|
2654
2653
|
else => return error.TestUnexpectedResult,
|
|
2655
2654
|
}
|
|
2656
|
-
switch (display_list.commands[
|
|
2655
|
+
switch (display_list.commands[5]) {
|
|
2657
2656
|
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.surface, fill.fill),
|
|
2658
2657
|
else => return error.TestUnexpectedResult,
|
|
2659
2658
|
}
|
|
2660
|
-
switch (display_list.commands[
|
|
2659
|
+
switch (display_list.commands[8]) {
|
|
2661
2660
|
.fill_rounded_rect => |fill| {
|
|
2662
2661
|
try std.testing.expectEqual(@as(ObjectId, widgetPartId(11, 4)), fill.id);
|
|
2663
2662
|
try expectFillColor(tokens.colors.accent, fill.fill);
|
|
2664
2663
|
},
|
|
2665
2664
|
else => return error.TestUnexpectedResult,
|
|
2666
2665
|
}
|
|
2667
|
-
switch (display_list.commands[
|
|
2666
|
+
switch (display_list.commands[9]) {
|
|
2668
2667
|
.draw_text => |text| try std.testing.expectEqualStrings("Monthly", text.text),
|
|
2669
2668
|
else => return error.TestUnexpectedResult,
|
|
2670
2669
|
}
|
|
2671
|
-
switch (display_list.commands[
|
|
2670
|
+
switch (display_list.commands[10]) {
|
|
2672
2671
|
.fill_rounded_rect => |fill| try expectFillColor(tokens.colors.accent, fill.fill),
|
|
2673
2672
|
else => return error.TestUnexpectedResult,
|
|
2674
2673
|
}
|
|
2675
2674
|
// The switch track is borderless now, so the toggle's label follows
|
|
2676
2675
|
// its fill and knob directly.
|
|
2677
|
-
switch (display_list.commands[
|
|
2676
|
+
switch (display_list.commands[12]) {
|
|
2678
2677
|
.draw_text => |text| try std.testing.expectEqualStrings("Mode", text.text),
|
|
2679
2678
|
else => return error.TestUnexpectedResult,
|
|
2680
2679
|
}
|
|
2681
2680
|
// 4px slider rail centered in the 32px row: y = 124 + 14.
|
|
2682
|
-
switch (display_list.commands[
|
|
2681
|
+
switch (display_list.commands[14]) {
|
|
2683
2682
|
.fill_rounded_rect => |fill| try expectRect(geometry.RectF.init(0, 138, 40, 4), fill.rect),
|
|
2684
2683
|
else => return error.TestUnexpectedResult,
|
|
2685
2684
|
}
|
|
2686
2685
|
// The knob's resting hairline wears the focus-ring neutral; focus
|
|
2687
2686
|
// adds the offset ring in the same color outside it.
|
|
2688
|
-
switch (display_list.commands[
|
|
2687
|
+
switch (display_list.commands[16]) {
|
|
2689
2688
|
.stroke_rect => |stroke| {
|
|
2690
2689
|
try std.testing.expectEqual(@as(ObjectId, widgetPartId(13, 4)), stroke.id);
|
|
2691
2690
|
try expectFillColor(tokens.colors.focus_ring, stroke.stroke.fill);
|
|
2692
2691
|
},
|
|
2693
2692
|
else => return error.TestUnexpectedResult,
|
|
2694
2693
|
}
|
|
2695
|
-
switch (display_list.commands[
|
|
2694
|
+
switch (display_list.commands[17]) {
|
|
2696
2695
|
.stroke_rect => |stroke| {
|
|
2697
2696
|
try std.testing.expectEqual(@as(ObjectId, widgetPartId(13, 5)), stroke.id);
|
|
2698
2697
|
try std.testing.expectEqual(@as(f32, 3), stroke.stroke.width);
|
|
@@ -1317,7 +1317,7 @@ test "every display-list command kind is representable on the packet path" {
|
|
|
1317
1317
|
.{ .stroke_rect = .{ .id = 13, .rect = geometry.RectF.init(32, 32, 32, 32), .radius = canvas.Radius.all(4), .stroke = .{ .width = 2, .fill = .{ .color = canvas.Color.rgb8(0, 0, 255) } } } },
|
|
1318
1318
|
.{ .draw_line = .{ .id = 14, .from = geometry.PointF.init(0, 70), .to = geometry.PointF.init(64, 70), .stroke = .{ .width = 1, .fill = .{ .color = canvas.Color.rgb8(128, 128, 128) } } } },
|
|
1319
1319
|
.{ .fill_path = .{ .id = 15, .elements = &path_elements, .fill = .{ .color = canvas.Color.rgb8(200, 100, 50) } } },
|
|
1320
|
-
.{ .stroke_path = .{ .id = 16, .elements = &path_elements, .stroke = .{ .width = 1.5, .fill = .{ .color = canvas.Color.rgb8(50, 100, 200) } } } },
|
|
1320
|
+
.{ .stroke_path = .{ .id = 16, .elements = &path_elements, .stroke = .{ .width = 1.5, .fill = .{ .color = canvas.Color.rgb8(50, 100, 200) } }, .cap = .round } },
|
|
1321
1321
|
.{ .draw_image = .{ .id = 17, .image_id = 3, .dst = geometry.RectF.init(80, 80, 24, 24), .radius = canvas.Radius.all(12) } },
|
|
1322
1322
|
.{ .draw_text = .{ .id = 18, .font_id = 1, .size = 13, .origin = geometry.PointF.init(8, 120), .color = canvas.Color.rgb8(30, 30, 30), .text = "audit", .text_layout = .{ .max_width = 200, .line_height = 16, .wrap = .word } } },
|
|
1323
1323
|
.{ .shadow = .{ .id = 19, .rect = geometry.RectF.init(10, 140, 40, 20), .radius = canvas.Radius.all(4), .offset = .{ .dx = 0, .dy = 2 }, .blur = 6, .spread = 1, .color = canvas.Color.rgba8(0, 0, 0, 90) } },
|
|
@@ -1341,10 +1341,18 @@ test "every display-list command kind is representable on the packet path" {
|
|
|
1341
1341
|
// Structural commands never reach the packet: 11 draw commands.
|
|
1342
1342
|
try std.testing.expectEqual(@as(usize, 11), packet.commandCount());
|
|
1343
1343
|
|
|
1344
|
+
// The stroke path's cap channel survives into the packet command —
|
|
1345
|
+
// the field the host reads to shape open subpath ends.
|
|
1346
|
+
for (packet.commands) |packet_command| {
|
|
1347
|
+
const expected_cap: canvas.LineCap = if (packet_command.kind == .stroke_path) .round else .butt;
|
|
1348
|
+
try std.testing.expectEqual(expected_cap, packet_command.cap);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1344
1351
|
// Both encodings accept the full kind coverage.
|
|
1345
1352
|
var json_buffer: [64 * 1024]u8 = undefined;
|
|
1346
1353
|
var json_writer = std.Io.Writer.fixed(&json_buffer);
|
|
1347
1354
|
try packet.writeJson(&json_writer);
|
|
1355
|
+
try std.testing.expect(std.mem.indexOf(u8, json_writer.buffered(), "\"cap\":\"round\"") != null);
|
|
1348
1356
|
var binary_buffer: [64 * 1024]u8 = undefined;
|
|
1349
1357
|
var binary_writer = std.Io.Writer.fixed(&binary_buffer);
|
|
1350
1358
|
try packet.writeBinary(&binary_writer);
|