@native-sdk/cli 0.4.1 → 0.4.3

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.
Files changed (48) hide show
  1. package/assets/native-sdk.manifest +17 -1
  2. package/build/app.zig +40 -1
  3. package/build.zig +49 -3
  4. package/package.json +10 -9
  5. package/src/platform/macos/appkit_host.m +21 -6
  6. package/src/platform/windows/webview2_host.cpp +377 -72
  7. package/src/primitives/canvas/chart.zig +8 -7
  8. package/src/primitives/canvas/chart_tests.zig +2 -2
  9. package/src/primitives/canvas/commands.zig +27 -0
  10. package/src/primitives/canvas/gpu.zig +8 -0
  11. package/src/primitives/canvas/markdown_tests.zig +1 -1
  12. package/src/primitives/canvas/reference.zig +215 -7
  13. package/src/primitives/canvas/reference_tests.zig +326 -7
  14. package/src/primitives/canvas/root.zig +3 -0
  15. package/src/primitives/canvas/serialization.zig +16 -3
  16. package/src/primitives/canvas/test_support.zig +3 -0
  17. package/src/primitives/canvas/themes/geist.zig +6 -0
  18. package/src/primitives/canvas/tokens.zig +7 -0
  19. package/src/primitives/canvas/widget_builtin_tests.zig +439 -3
  20. package/src/primitives/canvas/widget_render.zig +29 -41
  21. package/src/primitives/canvas/widget_render_controls.zig +73 -43
  22. package/src/primitives/canvas/widget_render_style.zig +53 -0
  23. package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
  24. package/src/primitives/canvas/widget_runtime.zig +3 -0
  25. package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
  26. package/src/primitives/canvas/widget_text_input.zig +104 -1
  27. package/src/runtime/canvas_frame_packet_tests.zig +9 -1
  28. package/src/runtime/canvas_frame_patch_tests.zig +39 -1
  29. package/src/runtime/canvas_widget_control_tests.zig +4 -4
  30. package/src/runtime/canvas_widget_runtime.zig +23 -3
  31. package/src/runtime/canvas_widget_text_tests.zig +101 -0
  32. package/src/runtime/ui_app.zig +78 -10
  33. package/src/runtime/ui_app_tests.zig +109 -0
  34. package/src/runtime/ui_app_window_tests.zig +93 -0
  35. package/src/runtime/view.zig +1 -1
  36. package/src/runtime/view_widget_scroll.zig +12 -1
  37. package/src/runtime/view_widget_text.zig +6 -2
  38. package/src/tooling/buildgraph.zig +112 -2
  39. package/src/tooling/junction.zig +247 -0
  40. package/src/tooling/package.zig +45 -0
  41. package/src/tooling/root.zig +1 -0
  42. package/src/tooling/templates.zig +102 -2
  43. package/third_party/webview2/LICENSE.txt +27 -0
  44. package/third_party/webview2/README.md +19 -0
  45. package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
  46. package/third_party/webview2/include/EventToken.h +12 -0
  47. package/third_party/webview2/include/WebView2.h +60636 -0
  48. 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
 
@@ -40,6 +41,7 @@ const widgetTextInputOrigin = widget_text_input.widgetTextInputOrigin;
40
41
  const widgetTextInputClipRect = widget_text_input.widgetTextInputClipRect;
41
42
  const widgetTextInputDrawText = widget_text_input.widgetTextInputDrawText;
42
43
  const widgetTextInputInset = widget_text_input.widgetTextInputInset;
44
+ const widgetTextInputClipsText = widget_text_input.widgetTextInputClipsText;
43
45
  const textInputClearButtonRect = widget_text_input.textInputClearButtonRect;
44
46
  const widgetButtonTextSize = widget_metrics.widgetButtonTextSize;
45
47
  const widgetBodyTextSize = widget_metrics.widgetBodyTextSize;
@@ -74,6 +76,7 @@ const controlRadius = widget_render_style.controlRadius;
74
76
  const buttonControlRadius = widget_render_style.buttonControlRadius;
75
77
  const widgetSizedRadiusValue = widget_render_style.widgetSizedRadiusValue;
76
78
  const controlStrokeWidth = widget_render_style.controlStrokeWidth;
79
+ const snapHairlineStrokeRect = widget_render_style.snapHairlineStrokeRect;
77
80
  const buttonFill = widget_render_style.buttonFill;
78
81
  const buttonTextColorForWidget = widget_render_style.buttonTextColorForWidget;
79
82
  const buttonBorderFill = widget_render_style.buttonBorderFill;
@@ -294,30 +297,35 @@ fn buttonGroupSegmentRadius(widget: Widget, visual: ControlVisualTokens, tokens:
294
297
  /// freed by the retired button shadow.
295
298
  fn emitButtonBorder(builder: *Builder, widget: Widget, tokens: DesignTokens, radius: Radius) Error!void {
296
299
  const stroke_width = buttonStrokeWidth(widget, tokens);
300
+ const border = snapHairlineStrokeRect(tokens, .{
301
+ .id = widgetPartId(widget.id, 2),
302
+ .rect = widget.frame,
303
+ .radius = radius,
304
+ .stroke = .{
305
+ .fill = buttonBorderFill(widget, tokens),
306
+ .width = stroke_width,
307
+ },
308
+ });
297
309
  // Seams exist only in the segmented register — a detached chip has
298
310
  // no shared boundary to collapse.
299
311
  const drop_left_border = !widget_render_style.buttonInDetachedGroup(widget, tokens) and
300
312
  (widget.group_segment == .middle or widget.group_segment == .last);
301
313
  if (drop_left_border) {
314
+ // The clip's left edge sits on the border band's INNER edge —
315
+ // computed from the (possibly snapped) emitted stroke, so the
316
+ // whole left band drops whether or not snapping moved it.
317
+ const band_inner_x = border.rect.x + border.stroke.width * 0.5;
302
318
  try builder.pushClip(.{
303
319
  .id = widgetPartId(widget.id, 0),
304
320
  .rect = geometry.RectF.init(
305
- widget.frame.x + stroke_width * 0.5,
321
+ band_inner_x,
306
322
  widget.frame.y - stroke_width,
307
- @max(0, widget.frame.width + stroke_width * 0.5),
323
+ @max(0, widget.frame.maxX() + stroke_width - band_inner_x),
308
324
  widget.frame.height + stroke_width * 2,
309
325
  ),
310
326
  });
311
327
  }
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
- });
328
+ try builder.strokeRect(border);
321
329
  if (drop_left_border) try builder.popClip();
322
330
  }
323
331
 
@@ -404,7 +412,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
404
412
  .radius = radius,
405
413
  .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, widget.state.pressed, washHovered(widget), tokens.colors.surface))),
406
414
  });
407
- try builder.strokeRect(.{
415
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
408
416
  .id = widgetPartId(widget.id, 2),
409
417
  .rect = widget.frame,
410
418
  .radius = radius,
@@ -412,7 +420,7 @@ pub fn emitSelectWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
412
420
  .fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
413
421
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
414
422
  },
415
- });
423
+ }));
416
424
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 6, widget.frame, radius);
417
425
  if (visible_text.len > 0) {
418
426
  const text_color = if (is_placeholder)
@@ -459,7 +467,12 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
459
467
  const selection_range = widgetTextSelectionRange(widget);
460
468
  const composition_range = widgetTextCompositionRange(widget);
461
469
  const has_text_affordances = selection_range != null or composition_range != null;
462
- const clips_text = widget.kind == .textarea;
470
+ // Textareas always clip (their overflow scrolls vertically); a
471
+ // single-line field clips once its value overflows the content rect,
472
+ // so the horizontally scrolled text, selection rects, composition
473
+ // underline, and caret all cut at the field's border instead of
474
+ // painting past it. Short values emit no clip — unchanged emission.
475
+ const clips_text = widgetTextInputClipsText(widget, tokens, text_size, text_inset, layout_options);
463
476
 
464
477
  try builder.fillRoundedRect(.{
465
478
  .id = widgetPartId(widget.id, 1),
@@ -467,7 +480,7 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
467
480
  .radius = radius,
468
481
  .fill = textInputFill(widget, tokens, visual),
469
482
  });
470
- try builder.strokeRect(.{
483
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
471
484
  .id = widgetPartId(widget.id, 2),
472
485
  .rect = widget.frame,
473
486
  .radius = radius,
@@ -475,7 +488,7 @@ pub fn emitTextFieldWidget(builder: *Builder, widget: Widget, tokens: DesignToke
475
488
  .fill = textInputBorderFill(widget, visual, tokens.colors.border),
476
489
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
477
490
  },
478
- });
491
+ }));
479
492
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 7, widget.frame, radius);
480
493
  if (clips_text) try builder.pushClip(.{ .id = widgetPartId(widget.id, 16), .rect = clip_rect, .radius = radius });
481
494
  if (selection_range) |range| {
@@ -529,7 +542,7 @@ pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTok
529
542
  .radius = radius,
530
543
  .fill = textInputFill(widget, tokens, visual),
531
544
  });
532
- try builder.strokeRect(.{
545
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
533
546
  .id = widgetPartId(widget.id, 2),
534
547
  .rect = widget.frame,
535
548
  .radius = radius,
@@ -537,7 +550,7 @@ pub fn emitInputGroupWidget(builder: *Builder, widget: Widget, tokens: DesignTok
537
550
  .fill = textInputBorderFill(widget, visual, tokens.colors.border),
538
551
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
539
552
  },
540
- });
553
+ }));
541
554
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, widget.frame, radius);
542
555
  }
543
556
 
@@ -548,11 +561,20 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
548
561
  const icon_size = @max(8, text_size - 2);
549
562
  const text_inset = widgetTextInputInset(widget, tokens);
550
563
  const layout_options = widgetTextInputLayoutOptions(widget, tokens, text_size, text_inset);
564
+ const clip_rect = widgetTextInputClipRect(widget, tokens, text_size, text_inset, layout_options);
551
565
  const origin = widgetTextInputOrigin(widget, tokens, text_size, text_inset, layout_options);
552
566
  const selection_range = widgetTextSelectionRange(widget);
553
567
  const composition_range = widgetTextCompositionRange(widget);
554
568
  const text_color = widgetForegroundColor(widget, tokens, visual.foreground orelse tokens.colors.text);
555
569
  const draw_text = widgetTextInputDrawText(widget, tokens, text_size, origin, text_color, layout_options);
570
+ // Same overflow contract as the text-field emitter: clip only once
571
+ // the value (or placeholder) overflows the content rect, so the
572
+ // horizontally scrolled text and its affordances cut at the border.
573
+ // The leading glass, trailing chevron, and clear affordance draw
574
+ // outside the clip — they are chrome, not scrolling content. Slot 7
575
+ // is clear of the field chrome (1..6, 8..13), the focus ring (14),
576
+ // and the clear affordance's shape range (15..).
577
+ const clips_text = widgetTextInputClipsText(widget, tokens, text_size, text_inset, layout_options);
556
578
 
557
579
  try builder.fillRoundedRect(.{
558
580
  .id = widgetPartId(widget.id, 1),
@@ -560,7 +582,7 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
560
582
  .radius = radius,
561
583
  .fill = textInputFill(widget, tokens, visual),
562
584
  });
563
- try builder.strokeRect(.{
585
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
564
586
  .id = widgetPartId(widget.id, 2),
565
587
  .rect = widget.frame,
566
588
  .radius = radius,
@@ -568,9 +590,10 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
568
590
  .fill = textInputBorderFill(widget, visual, tokens.colors.border),
569
591
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
570
592
  },
571
- });
593
+ }));
572
594
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 14, widget.frame, radius);
573
595
  try emitSearchFieldIcon(builder, widget, tokens, icon_size);
596
+ if (clips_text) try builder.pushClip(.{ .id = widgetPartId(widget.id, 7), .rect = clip_rect, .radius = radius });
574
597
  if (selection_range) |range| {
575
598
  if (!range.isCollapsed(widget.text.len)) {
576
599
  try emitWidgetTextSelectionRects(builder, widget, draw_text, layout_options, range, 8, 0, 1, tokens);
@@ -602,6 +625,7 @@ pub fn emitSearchFieldWidget(builder: *Builder, widget: Widget, tokens: DesignTo
602
625
  }
603
626
  }
604
627
  }
628
+ if (clips_text) try builder.popClip();
605
629
  if (widget.kind == .combobox) {
606
630
  try emitComboboxChevron(builder, widget, tokens, visual);
607
631
  }
@@ -871,14 +895,14 @@ pub fn emitDataCellWidgetChrome(builder: *Builder, widget: Widget, tokens: Desig
871
895
  // border/stroke opts a cell back into an edge.
872
896
  const wants_stroke = widget.style.border != null or visual.border != null or widget.style.stroke_width != null or visual.stroke_width != null;
873
897
  if (wants_stroke) {
874
- try builder.strokeRect(.{
898
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
875
899
  .id = widgetPartId(widget.id, 2),
876
900
  .rect = widget.frame,
877
901
  .stroke = .{
878
902
  .fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
879
903
  .width = controlStrokeWidth(widget, visual, tokens.stroke.hairline),
880
904
  },
881
- });
905
+ }));
882
906
  }
883
907
  if (widget.state.focused) try emitWidgetFocusRing(builder, widget, tokens, 3);
884
908
  return visual;
@@ -954,7 +978,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
954
978
  });
955
979
  }
956
980
  if (selected) {
957
- try builder.strokeRect(.{
981
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
958
982
  .id = widgetPartId(widget.id, 2),
959
983
  .rect = widget.frame,
960
984
  .radius = radius,
@@ -962,7 +986,7 @@ pub fn emitSegmentedControlWidget(builder: *Builder, widget: Widget, tokens: Des
962
986
  .fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
963
987
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
964
988
  },
965
- });
989
+ }));
966
990
  }
967
991
  },
968
992
  // The underline treatment: triggers are bare text — no pill, no
@@ -1023,7 +1047,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1023
1047
  else
1024
1048
  colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
1025
1049
  });
1026
- try builder.strokeRect(.{
1050
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1027
1051
  .id = widgetPartId(widget.id, 2),
1028
1052
  .rect = box,
1029
1053
  .radius = radius,
@@ -1031,7 +1055,7 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1031
1055
  .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
1056
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
1033
1057
  },
1034
- });
1058
+ }));
1035
1059
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, box, radius);
1036
1060
  if (selected) {
1037
1061
  // The check keeps the accent-foreground tint even when disabled
@@ -1041,17 +1065,23 @@ pub fn emitCheckboxWidget(builder: *Builder, widget: Widget, tokens: DesignToken
1041
1065
  const left = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.26, box.y + box.height * 0.54));
1042
1066
  const mid = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.43, box.y + box.height * 0.70));
1043
1067
  const right = pixelSnapGeometryPoint(tokens, geometry.PointF.init(box.x + box.width * 0.76, box.y + box.height * 0.32));
1044
- try builder.drawLine(.{
1068
+ // ONE stroked polyline through the vector core, not a pair of
1069
+ // line commands: `draw_line` rasterizes as a hard-edged capsule
1070
+ // (exact for the axis-aligned hairlines it serves), which turns
1071
+ // this diagonal into staircase chunks at control sizes. The
1072
+ // stroke path gets the same anti-aliased coverage and round
1073
+ // caps/joins the built-in stroke icons get, so the mark reads
1074
+ // crisp and even at 1x — same three snapped vertices, so the
1075
+ // drawn shape is unchanged.
1076
+ const elements = try builder.allocPathElements(3);
1077
+ elements[0] = .{ .verb = .move_to, .points = .{ left, geometry.PointF.zero(), geometry.PointF.zero() } };
1078
+ elements[1] = .{ .verb = .line_to, .points = .{ mid, geometry.PointF.zero(), geometry.PointF.zero() } };
1079
+ elements[2] = .{ .verb = .line_to, .points = .{ right, geometry.PointF.zero(), geometry.PointF.zero() } };
1080
+ try builder.strokePath(.{
1045
1081
  .id = widgetPartId(widget.id, 4),
1046
- .from = left,
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,
1082
+ .elements = elements,
1054
1083
  .stroke = .{ .fill = colorFill(check_color), .width = 2 },
1084
+ .cap = .round,
1055
1085
  });
1056
1086
  }
1057
1087
  try emitControlLabelWithColor(builder, widget, tokens, box.x + box.width + widgetControlInset(widget, tokens, tokens.spacing.sm), 6, visual.foreground orelse tokens.colors.text);
@@ -1068,7 +1098,7 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1068
1098
  .radius = radius,
1069
1099
  .fill = colorFill(widgetBackgroundColor(widget, buttonStateBackground(visual, false, washHovered(widget), tokens.colors.surface))),
1070
1100
  });
1071
- try builder.strokeRect(.{
1101
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1072
1102
  .id = widgetPartId(widget.id, 2),
1073
1103
  .rect = circle,
1074
1104
  .radius = radius,
@@ -1078,7 +1108,7 @@ pub fn emitRadioWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1078
1108
  .fill = colorFill(disabledWash(widgetBorderColor(widget, visual.border orelse tokens.colors.border), widget.state.disabled, tokens.states.disabled_alpha)),
1079
1109
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
1080
1110
  },
1081
- });
1111
+ }));
1082
1112
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 3, circle, radius);
1083
1113
  if (selected) {
1084
1114
  const dot_size = @max(0, circle.height * 0.5);
@@ -1128,7 +1158,7 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1128
1158
  const wants_track_stroke = widget.style.border != null or visual.border != null;
1129
1159
  const track_stroke_width = controlStrokeWidth(widget, visual, if (wants_track_stroke) tokens.stroke.regular else 0);
1130
1160
  if (track_stroke_width > 0) {
1131
- try builder.strokeRect(.{
1161
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1132
1162
  .id = widgetPartId(widget.id, 2),
1133
1163
  .rect = track,
1134
1164
  .radius = track_radius,
@@ -1136,7 +1166,7 @@ pub fn emitToggleWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1136
1166
  .fill = widgetBorderFill(widget, visual.border orelse tokens.colors.border),
1137
1167
  .width = track_stroke_width,
1138
1168
  },
1139
- });
1169
+ }));
1140
1170
  }
1141
1171
  try builder.fillRoundedRect(.{
1142
1172
  .id = widgetPartId(widget.id, 3),
@@ -1215,7 +1245,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1215
1245
  // The thumb's resting hairline wears the focus-ring neutral (a mid
1216
1246
  // gray in both schemes), so the ring on focus reads as a brighter
1217
1247
  // echo of an edge the control already owns — not a recolor.
1218
- try builder.strokeRect(.{
1248
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1219
1249
  .id = widgetPartId(widget.id, 4),
1220
1250
  .rect = knob,
1221
1251
  .radius = knob_radius,
@@ -1223,7 +1253,7 @@ pub fn emitSliderWidget(builder: *Builder, widget: Widget, tokens: DesignTokens)
1223
1253
  .fill = widgetBorderFill(widget, disabledWash(visual.border orelse tokens.colors.focus_ring, washed, tokens.states.disabled_alpha)),
1224
1254
  .width = controlStrokeWidth(widget, visual, tokens.stroke.regular),
1225
1255
  },
1226
- });
1256
+ }));
1227
1257
  if (widget.state.focused) try emitWidgetFocusRingForRect(builder, widget, tokens, 5, knob, knob_radius);
1228
1258
  }
1229
1259
 
@@ -1332,7 +1362,7 @@ fn emitWidgetFocusRing(builder: *Builder, widget: Widget, tokens: DesignTokens,
1332
1362
  /// (`stroke.focus_offset`) outside it, so focus adds an outline instead
1333
1363
  /// of recoloring the control's edge.
1334
1364
  fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignTokens, slot: ObjectId, rect: geometry.RectF, radius: Radius) Error!void {
1335
- try builder.strokeRect(.{
1365
+ try builder.strokeRect(snapHairlineStrokeRect(tokens, .{
1336
1366
  .id = widgetPartId(widget.id, slot),
1337
1367
  .rect = widget_render_style.focusRingRect(rect, tokens),
1338
1368
  .radius = widget_render_style.focusRingRadius(radius, tokens),
@@ -1340,7 +1370,7 @@ fn emitWidgetFocusRingForRect(builder: *Builder, widget: Widget, tokens: DesignT
1340
1370
  .fill = widgetFocusRingFill(widget, tokens),
1341
1371
  .width = tokens.stroke.focus,
1342
1372
  },
1343
- });
1373
+ }));
1344
1374
  }
1345
1375
 
1346
1376
  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
  }
@@ -50,6 +50,9 @@ pub const textInputClearButtonHitRect = widget_text_input.textInputClearButtonHi
50
50
  pub const textInputContentExtentForWidget = widget_text_input.textInputContentExtentForWidget;
51
51
  pub const textInputMaxScrollOffsetForWidget = widget_text_input.textInputMaxScrollOffsetForWidget;
52
52
  pub const clampedTextInputScrollOffsetForWidget = widget_text_input.clampedTextInputScrollOffsetForWidget;
53
+ pub const textInputMaxHorizontalScrollOffsetForWidget = widget_text_input.textInputMaxHorizontalScrollOffsetForWidget;
54
+ pub const clampedTextInputHorizontalScrollOffsetForWidget = widget_text_input.clampedTextInputHorizontalScrollOffsetForWidget;
55
+ pub const textInputCaretVisibleScrollOffsetForWidget = widget_text_input.textInputCaretVisibleScrollOffsetForWidget;
53
56
  pub const textGeometryForWidget = widget_text_input.textGeometryForWidget;
54
57
 
55
58
  pub const WidgetLayoutTree = struct {