@native-sdk/cli 0.5.1 → 0.5.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.
- package/build.zig +41 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +118 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
|
@@ -120,7 +120,12 @@ pub fn semanticRole(widget: Widget) WidgetRole {
|
|
|
120
120
|
.menu_surface, .dropdown_menu => .menu,
|
|
121
121
|
.list => .list,
|
|
122
122
|
.text, .status_bar => .text,
|
|
123
|
-
|
|
123
|
+
// Media surfaces announce as images: pictorial content whose
|
|
124
|
+
// TEXTURE is presentation chrome — the semantic node carries only
|
|
125
|
+
// role, label, and bounds, never frame-varying producer state, so
|
|
126
|
+
// session fingerprints (hashed over the a11y tree) stay identical
|
|
127
|
+
// whether or not a producer is attached.
|
|
128
|
+
.icon, .image, .avatar, .media_surface => .image,
|
|
124
129
|
.badge => .text,
|
|
125
130
|
.button, .toggle_button, .toggle => .button,
|
|
126
131
|
.icon_button, .select => .button,
|
|
@@ -872,6 +872,174 @@ test "widget image emits draw image and exposes image semantics" {
|
|
|
872
872
|
try std.testing.expect(display_list.commands[2] == .pop_clip);
|
|
873
873
|
}
|
|
874
874
|
|
|
875
|
+
test "widget media surface cover fit emits the image widget's rectangular clip" {
|
|
876
|
+
// Cover fit expands the drawn texture past the widget frame on one
|
|
877
|
+
// axis; emitImageWidget crops the overflow with a rectangular clip.
|
|
878
|
+
// The media surface draws through the same image pipeline and must
|
|
879
|
+
// carry the SAME clip: its draw-level radius mask is nothing at
|
|
880
|
+
// radius zero, so hosts that only mask radii (the AppKit packet
|
|
881
|
+
// draw) painted a zero-radius cover surface outside its bounds,
|
|
882
|
+
// over its siblings.
|
|
883
|
+
const surface_id: u64 = 5;
|
|
884
|
+
const row_children = [_]Widget{
|
|
885
|
+
.{
|
|
886
|
+
.id = 21,
|
|
887
|
+
.kind = .media_surface,
|
|
888
|
+
.frame = geometry.RectF.init(0, 0, 80, 48),
|
|
889
|
+
.image_id = surface_id,
|
|
890
|
+
.image_fit = .cover,
|
|
891
|
+
},
|
|
892
|
+
.{
|
|
893
|
+
.id = 22,
|
|
894
|
+
.kind = .image,
|
|
895
|
+
.frame = geometry.RectF.init(0, 0, 40, 48),
|
|
896
|
+
.image_id = 42,
|
|
897
|
+
},
|
|
898
|
+
};
|
|
899
|
+
const root = Widget{ .id = 20, .kind = .row, .children = &row_children };
|
|
900
|
+
|
|
901
|
+
var nodes: [3]WidgetLayoutNode = undefined;
|
|
902
|
+
const layout = try layoutWidgetTree(root, geometry.RectF.init(0, 0, 160, 48), &nodes);
|
|
903
|
+
var commands: [8]CanvasCommand = undefined;
|
|
904
|
+
var builder = Builder.init(&commands);
|
|
905
|
+
try layout.emitDisplayList(&builder, .{});
|
|
906
|
+
const display_list = builder.displayList();
|
|
907
|
+
try std.testing.expectEqual(@as(usize, 5), display_list.commandCount());
|
|
908
|
+
const media_frame = geometry.RectF.init(0, 0, 80, 48);
|
|
909
|
+
switch (display_list.commands[0]) {
|
|
910
|
+
.fill_rounded_rect => |fill| {
|
|
911
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(21, 1)), fill.id);
|
|
912
|
+
try expectRect(media_frame, fill.rect);
|
|
913
|
+
},
|
|
914
|
+
else => return error.TestUnexpectedResult,
|
|
915
|
+
}
|
|
916
|
+
switch (display_list.commands[1]) {
|
|
917
|
+
.push_clip => |clip| {
|
|
918
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(21, 3)), clip.id);
|
|
919
|
+
try expectRect(media_frame, clip.rect);
|
|
920
|
+
// A rectangular bounds crop, exactly like the image
|
|
921
|
+
// widget's — rounding stays on the draw's own mask.
|
|
922
|
+
try std.testing.expectEqual(@as(f32, 0), clip.radius.top_left);
|
|
923
|
+
},
|
|
924
|
+
else => return error.TestUnexpectedResult,
|
|
925
|
+
}
|
|
926
|
+
switch (display_list.commands[2]) {
|
|
927
|
+
.draw_image => |draw| {
|
|
928
|
+
try std.testing.expectEqual(@as(ObjectId, widgetPartId(21, 2)), draw.id);
|
|
929
|
+
try std.testing.expectEqual(canvas.mediaSurfaceTextureImageId(surface_id), draw.image_id);
|
|
930
|
+
try std.testing.expectEqual(ImageFit.cover, draw.fit);
|
|
931
|
+
},
|
|
932
|
+
else => return error.TestUnexpectedResult,
|
|
933
|
+
}
|
|
934
|
+
// The clip closes BEFORE the sibling paints: the sibling's own draw
|
|
935
|
+
// is never cropped by the media surface's frame.
|
|
936
|
+
try std.testing.expect(display_list.commands[3] == .pop_clip);
|
|
937
|
+
switch (display_list.commands[4]) {
|
|
938
|
+
.draw_image => |draw| try std.testing.expectEqual(@as(ObjectId, widgetPartId(22, 1)), draw.id),
|
|
939
|
+
else => return error.TestUnexpectedResult,
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// Non-cover fits expand nothing and emit no clip — unchanged.
|
|
943
|
+
const contained = Widget{
|
|
944
|
+
.id = 21,
|
|
945
|
+
.kind = .media_surface,
|
|
946
|
+
.frame = media_frame,
|
|
947
|
+
.image_id = surface_id,
|
|
948
|
+
.image_fit = .stretch,
|
|
949
|
+
};
|
|
950
|
+
var contained_nodes: [1]WidgetLayoutNode = undefined;
|
|
951
|
+
const contained_layout = try layoutWidgetTree(contained, media_frame, &contained_nodes);
|
|
952
|
+
var contained_commands: [4]CanvasCommand = undefined;
|
|
953
|
+
var contained_builder = Builder.init(&contained_commands);
|
|
954
|
+
try contained_layout.emitDisplayList(&contained_builder, .{});
|
|
955
|
+
try std.testing.expectEqual(@as(usize, 2), contained_builder.displayList().commandCount());
|
|
956
|
+
|
|
957
|
+
// The rounded cover case keeps its draw-level radius mask AND gains
|
|
958
|
+
// the same bounds crop (the mask lies inside the rect, so pixels
|
|
959
|
+
// are unchanged where the radius already masked).
|
|
960
|
+
const rounded = Widget{
|
|
961
|
+
.id = 21,
|
|
962
|
+
.kind = .media_surface,
|
|
963
|
+
.frame = media_frame,
|
|
964
|
+
.image_id = surface_id,
|
|
965
|
+
.image_fit = .cover,
|
|
966
|
+
.style = .{ .radius = 12 },
|
|
967
|
+
};
|
|
968
|
+
var rounded_nodes: [1]WidgetLayoutNode = undefined;
|
|
969
|
+
const rounded_layout = try layoutWidgetTree(rounded, media_frame, &rounded_nodes);
|
|
970
|
+
var rounded_commands: [4]CanvasCommand = undefined;
|
|
971
|
+
var rounded_builder = Builder.init(&rounded_commands);
|
|
972
|
+
try rounded_layout.emitDisplayList(&rounded_builder, .{});
|
|
973
|
+
const rounded_list = rounded_builder.displayList();
|
|
974
|
+
try std.testing.expectEqual(@as(usize, 4), rounded_list.commandCount());
|
|
975
|
+
try std.testing.expect(rounded_list.commands[1] == .push_clip);
|
|
976
|
+
switch (rounded_list.commands[2]) {
|
|
977
|
+
.draw_image => |draw| try std.testing.expectEqual(@as(f32, 12), draw.radius.top_left),
|
|
978
|
+
else => return error.TestUnexpectedResult,
|
|
979
|
+
}
|
|
980
|
+
try std.testing.expect(rounded_list.commands[3] == .pop_clip);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
test "a composited cover media texture is byte-contained in the reference render" {
|
|
984
|
+
// Containment pin for the deterministic path: the render planner
|
|
985
|
+
// already crops every draw to its requested `dst` (command bounds),
|
|
986
|
+
// so reference renders — goldens, screenshots — were contained
|
|
987
|
+
// before the cover clip and must stay byte-identical with it. The
|
|
988
|
+
// clip COMMAND itself (pinned in the test above) is what protects
|
|
989
|
+
// packet hosts, which replay the display list and expand cover at
|
|
990
|
+
// draw time without the planner's bounds. The reference renderer
|
|
991
|
+
// skips presentation-only media textures by policy; feeding the
|
|
992
|
+
// texture in as an ordinary resource under the media-derived id
|
|
993
|
+
// exercises the draw geometry itself.
|
|
994
|
+
const surface_id: u64 = 5;
|
|
995
|
+
const media_frame = geometry.RectF.init(8, 4, 8, 16);
|
|
996
|
+
const widget = Widget{
|
|
997
|
+
.id = 9,
|
|
998
|
+
.kind = .media_surface,
|
|
999
|
+
.frame = media_frame,
|
|
1000
|
+
.image_id = surface_id,
|
|
1001
|
+
.image_fit = .cover,
|
|
1002
|
+
};
|
|
1003
|
+
var nodes: [1]WidgetLayoutNode = undefined;
|
|
1004
|
+
const layout = try layoutWidgetTree(widget, media_frame, &nodes);
|
|
1005
|
+
var commands: [4]CanvasCommand = undefined;
|
|
1006
|
+
var builder = Builder.init(&commands);
|
|
1007
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1008
|
+
|
|
1009
|
+
// A square texture in a 1:2 frame: cover expands the draw to
|
|
1010
|
+
// (4,4,16,16) — four columns past BOTH vertical edges of the frame,
|
|
1011
|
+
// where a sibling would sit.
|
|
1012
|
+
const texture_pixels = [_]u8{
|
|
1013
|
+
255, 255, 255, 255, 255, 255, 255, 255,
|
|
1014
|
+
255, 255, 255, 255, 255, 255, 255, 255,
|
|
1015
|
+
};
|
|
1016
|
+
const images = [_]ReferenceImage{.{
|
|
1017
|
+
.id = canvas.mediaSurfaceTextureImageId(surface_id),
|
|
1018
|
+
.width = 2,
|
|
1019
|
+
.height = 2,
|
|
1020
|
+
.pixels = &texture_pixels,
|
|
1021
|
+
}};
|
|
1022
|
+
|
|
1023
|
+
var render_commands: [8]RenderCommand = undefined;
|
|
1024
|
+
const plan = try builder.displayList().renderPlan(&render_commands);
|
|
1025
|
+
var pixels: [32 * 24 * 4]u8 = undefined;
|
|
1026
|
+
@memset(&pixels, 0);
|
|
1027
|
+
const surface = (try ReferenceRenderSurface.init(32, 24, &pixels)).withImages(&images);
|
|
1028
|
+
try surface.renderPass(.{
|
|
1029
|
+
.commands = plan.commands,
|
|
1030
|
+
.surface_size = geometry.SizeF.init(32, 24),
|
|
1031
|
+
.full_repaint = true,
|
|
1032
|
+
}, Color.rgb8(0, 0, 0));
|
|
1033
|
+
|
|
1034
|
+
// Inside the frame: the texture (cover fills the whole frame).
|
|
1035
|
+
try support.expectPixelRgba8(.{ 255, 255, 255, 255 }, surface, 12, 12);
|
|
1036
|
+
// The fit-expanded bleed columns — left (x in [4,8)) and right
|
|
1037
|
+
// (x in [16,20)) of the frame — stay background: the emitted clip
|
|
1038
|
+
// contains the draw to the widget's bytes.
|
|
1039
|
+
try support.expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 5, 12);
|
|
1040
|
+
try support.expectPixelRgba8(.{ 0, 0, 0, 255 }, surface, 18, 12);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
875
1043
|
test "widget text fields expose textbox semantics and render focused chrome" {
|
|
876
1044
|
const text_field = Widget{
|
|
877
1045
|
.id = 8,
|
|
@@ -8,6 +8,7 @@ const widget_access = @import("widget_access.zig");
|
|
|
8
8
|
const widget_metrics = @import("widget_metrics.zig");
|
|
9
9
|
|
|
10
10
|
const FontId = @import("root.zig").FontId;
|
|
11
|
+
const Builder = @import("commands.zig").Builder;
|
|
11
12
|
const Color = drawing_model.Color;
|
|
12
13
|
const DrawText = text_model.DrawText;
|
|
13
14
|
const TextWrap = text_model.TextWrap;
|
|
@@ -36,6 +37,96 @@ pub fn widgetPlaceholder(widget: Widget) []const u8 {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Single-line presentation: a single-line field NEVER paints a second line.
|
|
42
|
+
//
|
|
43
|
+
// Edits into single-line kinds are sanitized at the runtime's derivation
|
|
44
|
+
// seam (`sanitizedSingleLineTextInputEvent`), but the retained VALUE can
|
|
45
|
+
// still legitimately hold a line break — a model-set value, an old journal,
|
|
46
|
+
// a host API write. The honest presentation for such a value is the one
|
|
47
|
+
// the paint layers already give whitespace: `\n`/`\r` lay out and measure
|
|
48
|
+
// as a SPACE (nothing inked, one space advance) instead of breaking the
|
|
49
|
+
// line. The substitution is byte-for-byte (1 → 1), so every caret,
|
|
50
|
+
// selection, composition, and hit-test offset computed against the
|
|
51
|
+
// presented bytes addresses the raw value unchanged — and because the
|
|
52
|
+
// presented bytes contain no `\n`, the single-line layout (`wrap = .none`)
|
|
53
|
+
// produces exactly one line on every renderer: the GPU engine, the
|
|
54
|
+
// reference renderer, and packet hosts that draw engine-broken lines
|
|
55
|
+
// verbatim. Copy, semantics, and automation still read the RAW value.
|
|
56
|
+
//
|
|
57
|
+
// The clip is the independent second guard: `widgetTextInputClipsText`
|
|
58
|
+
// forces the content-rect clip whenever the raw value holds a break, so
|
|
59
|
+
// even a path that somehow lays out raw bytes (presentation scratch
|
|
60
|
+
// exhausted) stays inside the field's border.
|
|
61
|
+
|
|
62
|
+
/// The editable kinds that present single-line: every text-input kind but
|
|
63
|
+
/// the textarea (the one genuinely multi-line editor). Deliberately
|
|
64
|
+
/// includes the tall wrapping `text_field` variant — its kind contract is
|
|
65
|
+
/// single-line entry, and `\n`-as-space is consistent under word wrap too.
|
|
66
|
+
fn widgetTextInputPresentsSingleLine(kind: widget_model.WidgetKind) bool {
|
|
67
|
+
return kind != .textarea and widget_access.widgetTextInputKind(kind);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fn textContainsLineBreakByte(text: []const u8) bool {
|
|
71
|
+
return std.mem.indexOfAny(u8, text, "\r\n") != null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Whether this widget's PAINTED text differs from its raw value (a
|
|
75
|
+
/// single-line kind whose value holds a line break). Render emitters use
|
|
76
|
+
/// it to persist the presented bytes for the display list's lifetime.
|
|
77
|
+
pub fn widgetTextInputTextNeedsPresentation(widget: Widget) bool {
|
|
78
|
+
return widgetTextInputPresentsSingleLine(widget.kind) and textContainsLineBreakByte(widget.text);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Presentation scratch, lazily heap-allocated per thread (the
|
|
82
|
+
/// `lazy_tls` pattern all canvas scratch uses; the event loop is
|
|
83
|
+
/// single-threaded): `slot` holds ONE presented text at a time — the
|
|
84
|
+
/// transient buffer the geometry seams (caret, selection, hit-test,
|
|
85
|
+
/// scroll measures) substitute into. Every entry point re-derives it,
|
|
86
|
+
/// and within one widget's computation repeated derivations write
|
|
87
|
+
/// identical bytes, so the aliasing is harmless. Sized to the runtime's
|
|
88
|
+
/// per-view widget-text budget (65536). Nothing EMITTED may retain a
|
|
89
|
+
/// slice into it: render emitters persist presented bytes into the
|
|
90
|
+
/// display-list builder via `persistWidgetTextInputPresentedText`, whose
|
|
91
|
+
/// storage lives exactly as long as the emitted commands do.
|
|
92
|
+
const WidgetTextPresentationScratch = struct {
|
|
93
|
+
slot: [65536]u8,
|
|
94
|
+
};
|
|
95
|
+
const widget_text_presentation_scratch = @import("lazy_tls.zig").LazyTls(WidgetTextPresentationScratch);
|
|
96
|
+
|
|
97
|
+
/// The text a single-line field lays out, measures, and paints: the raw
|
|
98
|
+
/// value with `\n`/`\r` presented as spaces (same byte length). Returns
|
|
99
|
+
/// the raw slice untouched when nothing needs presenting — the
|
|
100
|
+
/// overwhelmingly common case costs one byte scan.
|
|
101
|
+
pub fn widgetTextInputPresentedText(widget: Widget) []const u8 {
|
|
102
|
+
if (!widgetTextInputPresentsSingleLine(widget.kind)) return widget.text;
|
|
103
|
+
return presentedSingleLineText(widget.text);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn presentedSingleLineText(text: []const u8) []const u8 {
|
|
107
|
+
if (!textContainsLineBreakByte(text)) return text;
|
|
108
|
+
const scratch = widget_text_presentation_scratch.get();
|
|
109
|
+
if (text.len > scratch.slot.len) return text;
|
|
110
|
+
for (text, 0..) |byte, index| {
|
|
111
|
+
scratch.slot[index] = if (byte == '\n' or byte == '\r') ' ' else byte;
|
|
112
|
+
}
|
|
113
|
+
return scratch.slot[0..text.len];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// Persist presented bytes into the display-list BUILDER so an emitted
|
|
117
|
+
/// command outlives the shared slot (a later widget's presentation
|
|
118
|
+
/// overwrites it) — builder-owned storage, because the builder contract
|
|
119
|
+
/// lets a display list accumulate across several emit calls or be held
|
|
120
|
+
/// while another builder emits, and the emitted `draw_text` must stay
|
|
121
|
+
/// intact through both. Falls back to the RAW value — stable,
|
|
122
|
+
/// view-owned storage — when the builder's text store is full (only
|
|
123
|
+
/// possible on a frame already over the per-view draw-text budget); the
|
|
124
|
+
/// forced clip contains that fallback inside the field's border.
|
|
125
|
+
pub fn persistWidgetTextInputPresentedText(builder: *Builder, raw: []const u8, presented: []const u8) []const u8 {
|
|
126
|
+
if (presented.ptr == raw.ptr) return raw;
|
|
127
|
+
return builder.allocTextBytes(presented) catch raw;
|
|
128
|
+
}
|
|
129
|
+
|
|
39
130
|
pub fn textSelectionForWidgetPoint(widget: Widget, point: geometry.PointF, anchor: ?usize, tokens: DesignTokens) ?TextSelection {
|
|
40
131
|
const offset = textOffsetForWidgetPoint(widget, point, tokens) orelse return null;
|
|
41
132
|
const selection = if (anchor) |anchor_offset|
|
|
@@ -115,7 +206,10 @@ fn widgetTextInputMaxHorizontalScrollOffset(widget: Widget, tokens: DesignTokens
|
|
|
115
206
|
if (options.wrap != .none or widget.text.len == 0) return 0;
|
|
116
207
|
const viewport = widgetTextInputClipRect(widget, tokens, text_size, text_inset, options);
|
|
117
208
|
if (viewport.width <= 0) return 0;
|
|
118
|
-
|
|
209
|
+
// Measure the PRESENTED bytes — the ones the field lays out and
|
|
210
|
+
// paints — so a value holding a line break scrolls by the same
|
|
211
|
+
// single-line extent it draws.
|
|
212
|
+
const text_width = measureTextWidthForFont(options.measure, tokens.typography.font_id, widgetTextInputPresentedText(widget), text_size);
|
|
119
213
|
return @max(0, text_width + text_input_caret_reserve - viewport.width);
|
|
120
214
|
}
|
|
121
215
|
|
|
@@ -220,9 +314,10 @@ pub fn textInputCaretVisibleScrollOffsetForWidget(widget: Widget, tokens: Design
|
|
|
220
314
|
|
|
221
315
|
// Caret x in content (unscrolled) coordinates: the width of the value
|
|
222
316
|
// up to the caret byte, measured on the same seam the line layout and
|
|
223
|
-
// selection rects measure with
|
|
317
|
+
// selection rects measure with — the PRESENTED bytes (byte offsets
|
|
318
|
+
// are interchangeable: the presentation substitutes 1:1).
|
|
224
319
|
const caret_offset = snapTextOffset(widget.text, selection.focus);
|
|
225
|
-
const caret_x = measureTextWidthForFont(options.measure, tokens.typography.font_id, widget
|
|
320
|
+
const caret_x = measureTextWidthForFont(options.measure, tokens.typography.font_id, widgetTextInputPresentedText(widget)[0..caret_offset], text_size);
|
|
226
321
|
const margin = textInputCaretVisibleMargin(viewport.width);
|
|
227
322
|
var next = clamped;
|
|
228
323
|
const scrolled_in = caret_x + text_input_caret_reserve + margin - viewport.width;
|
|
@@ -239,6 +334,11 @@ pub fn textInputCaretVisibleScrollOffsetForWidget(widget: Widget, tokens: Design
|
|
|
239
334
|
/// exactly as before fields scrolled.
|
|
240
335
|
pub fn widgetTextInputClipsText(widget: Widget, tokens: DesignTokens, text_size: f32, text_inset: f32, options: TextLayoutOptions) bool {
|
|
241
336
|
if (widget.kind == .textarea) return true;
|
|
337
|
+
// A raw value holding a line break ALWAYS clips: presentation lays it
|
|
338
|
+
// out as one line, but the clip is the independent guard that keeps
|
|
339
|
+
// even a raw-bytes fallback (presentation scratch exhausted) from
|
|
340
|
+
// painting a second line outside the field's border.
|
|
341
|
+
if (widgetTextInputTextNeedsPresentation(widget)) return true;
|
|
242
342
|
if (options.wrap != .none) return false;
|
|
243
343
|
if (widgetTextInputMaxHorizontalScrollOffset(widget, tokens, text_size, text_inset, options) > 0) return true;
|
|
244
344
|
if (widget.text.len == 0) {
|
|
@@ -260,16 +360,19 @@ fn textInputContentExtentForWidgetWithOptions(widget: Widget, font_id: FontId, t
|
|
|
260
360
|
}
|
|
261
361
|
|
|
262
362
|
fn widgetTextInputLineCount(widget: Widget, font_id: FontId, text_size: f32, options: TextLayoutOptions) usize {
|
|
263
|
-
|
|
363
|
+
// Count lines over the PRESENTED bytes: a single-line field's value
|
|
364
|
+
// holding a `\n` still lays out (and therefore extends) as one line.
|
|
365
|
+
const text = widgetTextInputPresentedText(widget);
|
|
366
|
+
if (text.len == 0) return 1;
|
|
264
367
|
var count: usize = 0;
|
|
265
368
|
var start: usize = 0;
|
|
266
|
-
while (start <=
|
|
267
|
-
const end = nextTextLineEnd(
|
|
369
|
+
while (start <= text.len) {
|
|
370
|
+
const end = nextTextLineEnd(text, start, font_id, text_size, options);
|
|
268
371
|
count += 1;
|
|
269
|
-
if (end >=
|
|
372
|
+
if (end >= text.len) break;
|
|
270
373
|
start = end;
|
|
271
|
-
if (start <
|
|
272
|
-
while (options.wrap == .word and start <
|
|
374
|
+
if (start < text.len and text[start] == '\n') start += 1;
|
|
375
|
+
while (options.wrap == .word and start < text.len and isTextBreakByte(text[start])) start += 1;
|
|
273
376
|
}
|
|
274
377
|
return @max(1, count);
|
|
275
378
|
}
|
|
@@ -287,7 +390,12 @@ pub fn widgetTextInputDrawText(
|
|
|
287
390
|
.size = text_size,
|
|
288
391
|
.origin = pixelSnapTextPoint(tokens, origin),
|
|
289
392
|
.color = color,
|
|
290
|
-
|
|
393
|
+
// The presented bytes: identical to `widget.text` unless a
|
|
394
|
+
// single-line field's value holds a line break (then `\n`/`\r`
|
|
395
|
+
// present as spaces — one line, same byte offsets). Geometry
|
|
396
|
+
// consumers (caret, selection, hit-test) and the paint emitters
|
|
397
|
+
// both build from this seam, so they can never disagree.
|
|
398
|
+
.text = widgetTextInputPresentedText(widget),
|
|
291
399
|
.text_layout = options,
|
|
292
400
|
};
|
|
293
401
|
}
|
|
@@ -217,14 +217,26 @@ pub fn isWidgetConcealedByDisclosure(layout: anytype, node_index: usize) bool {
|
|
|
217
217
|
return false;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
/// The column count a grid lays out, measures, and reports: the DECLARED
|
|
221
|
+
/// count when one is set — even when fewer children remain (a filtered
|
|
222
|
+
/// grid keeps its column-slot geometry; children fill the leading slots
|
|
223
|
+
/// and the trailing slots stay empty, they never stretch to fill missing
|
|
224
|
+
/// columns) — and one column per child when unset (the single-row grid).
|
|
220
225
|
pub fn gridColumnCount(child_count: usize, requested_columns: usize) usize {
|
|
221
226
|
if (child_count == 0) return 0;
|
|
222
|
-
return if (requested_columns > 0)
|
|
227
|
+
return if (requested_columns > 0) requested_columns else child_count;
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/// The row count those columns yield: ceil-division stated as
|
|
231
|
+
/// `1 + (count - 1) / columns` rather than the additive
|
|
232
|
+
/// `(count + columns - 1) / columns` — a declared column count is
|
|
233
|
+
/// engine input (never validator-bounded), so `columns` may be any
|
|
234
|
+
/// usize, including values where the additive form's sum overflows in
|
|
235
|
+
/// safe builds. Both the layout and intrinsic-size paths share this
|
|
236
|
+
/// helper.
|
|
225
237
|
pub fn gridRowCount(child_count: usize, columns: usize) usize {
|
|
226
238
|
if (child_count == 0 or columns == 0) return 0;
|
|
227
|
-
return
|
|
239
|
+
return 1 + (child_count - 1) / columns;
|
|
228
240
|
}
|
|
229
241
|
|
|
230
242
|
pub fn saturatingU32(value: usize) u32 {
|
|
@@ -133,6 +133,21 @@ pub const WidgetKind = enum {
|
|
|
133
133
|
/// never double-draw. Not a hit target itself: the textarea fills the
|
|
134
134
|
/// group's body, so a click "in the field" IS a click in the textarea.
|
|
135
135
|
input_group,
|
|
136
|
+
/// The media surface leaf: composites a texture PRODUCED OUTSIDE the
|
|
137
|
+
/// widget tree (a video decoder, a camera pipeline, an external
|
|
138
|
+
/// renderer) into the layout like any widget — clipped, z-ordered,
|
|
139
|
+
/// transformed. `image_id` carries the SURFACE id the producer
|
|
140
|
+
/// targets (`Runtime.acquireMediaSurfaceProducer`), a model-owned
|
|
141
|
+
/// u64 in the ImageId value space; 0 is the unbound sentinel, and
|
|
142
|
+
/// usable ids are nonzero values below the reserved namespace bit
|
|
143
|
+
/// (`media_surface_image_id_bit`, refused at acquire).
|
|
144
|
+
/// Display-only like `image` and `chart`: not a hit target, presses
|
|
145
|
+
/// fall through to the nearest pressable ancestor. Texture CONTENTS
|
|
146
|
+
/// are presentation chrome — the deterministic reference renderer
|
|
147
|
+
/// draws the surface's id-derived placeholder instead (see
|
|
148
|
+
/// `ReferenceImage.presentation_only`), so goldens and session
|
|
149
|
+
/// fingerprints never depend on producer output.
|
|
150
|
+
media_surface,
|
|
136
151
|
};
|
|
137
152
|
|
|
138
153
|
/// STABLE code for a widget kind: assigned at birth, never reused or
|
|
@@ -210,6 +225,7 @@ pub fn widgetKindCode(kind: WidgetKind) u16 {
|
|
|
210
225
|
.split_divider => 58,
|
|
211
226
|
.tree => 59,
|
|
212
227
|
.input_group => 60,
|
|
228
|
+
.media_surface => 61,
|
|
213
229
|
};
|
|
214
230
|
}
|
|
215
231
|
|
|
@@ -841,6 +857,18 @@ pub const Widget = struct {
|
|
|
841
857
|
/// origin: mounts land at their value, exactly as before. Ignored
|
|
842
858
|
/// on splits that already have a retained fraction.
|
|
843
859
|
resize_origin: f32 = -1,
|
|
860
|
+
/// Hover-intent show delay for an ANCHORED `.tooltip` widget
|
|
861
|
+
/// (`tooltip_delay:` in the builder, `tooltip-delay=` in markup),
|
|
862
|
+
/// in milliseconds. An anchored tooltip is runtime-owned hover
|
|
863
|
+
/// chrome: it stays hidden until its trigger (the anchor parent's
|
|
864
|
+
/// subtree) has been hovered this long on the recorded frame
|
|
865
|
+
/// clock, shows while the hover holds, and hides when the pointer
|
|
866
|
+
/// leaves — the model never hears hover. 0 shows the instant the
|
|
867
|
+
/// trigger is hovered. Negative (the default) follows the token
|
|
868
|
+
/// default (`ControlMetricTokens.tooltip_show_delay_ms`). Ignored
|
|
869
|
+
/// on every other kind, and on tooltips without an anchor (those
|
|
870
|
+
/// stay static leaves that paint whenever the view renders them).
|
|
871
|
+
tooltip_delay_ms: i32 = -1,
|
|
844
872
|
/// Window-drag surface (`window-drag="true"` / `.window_drag`): a
|
|
845
873
|
/// pointer press that lands here — or falls through plain text /
|
|
846
874
|
/// icons / decorations onto it — moves the WINDOW instead of
|
package/src/root.zig
CHANGED
|
@@ -93,6 +93,9 @@ pub const setFreestandingMonotonicNanoseconds = runtime.setFreestandingMonotonic
|
|
|
93
93
|
pub const RegisteredImage = runtime.RegisteredImage;
|
|
94
94
|
pub const max_registered_canvas_images = runtime.max_registered_canvas_images;
|
|
95
95
|
pub const max_registered_canvas_image_pixel_bytes = runtime.max_registered_canvas_image_pixel_bytes;
|
|
96
|
+
pub const MediaSurfaceProducer = runtime.MediaSurfaceProducer;
|
|
97
|
+
pub const max_media_surface_channels = runtime.max_media_surface_channels;
|
|
98
|
+
pub const max_media_surface_pixel_bytes = runtime.max_media_surface_pixel_bytes;
|
|
96
99
|
pub const ShellConfig = app_manifest.ShellConfig;
|
|
97
100
|
pub const ShellWindow = app_manifest.ShellWindow;
|
|
98
101
|
pub const ShellView = app_manifest.ShellView;
|
|
@@ -147,6 +150,8 @@ pub const GpuSurfaceFrameEvent = platform.GpuSurfaceFrameEvent;
|
|
|
147
150
|
pub const GpuSurfaceResizeEvent = platform.GpuSurfaceResizeEvent;
|
|
148
151
|
pub const GpuSurfaceInputKind = platform.GpuSurfaceInputKind;
|
|
149
152
|
pub const GpuSurfaceInputEvent = platform.GpuSurfaceInputEvent;
|
|
153
|
+
pub const PinchPhase = platform.PinchPhase;
|
|
154
|
+
pub const PinchEvent = platform.PinchEvent;
|
|
150
155
|
pub const FileFilter = platform.FileFilter;
|
|
151
156
|
pub const OpenDialogOptions = platform.OpenDialogOptions;
|
|
152
157
|
pub const OpenDialogResult = platform.OpenDialogResult;
|
package/src/runtime/api.zig
CHANGED
|
@@ -384,6 +384,19 @@ pub fn App(comptime Runtime: type) type {
|
|
|
384
384
|
|
|
385
385
|
pub const Options = struct {
|
|
386
386
|
platform: platform.Platform,
|
|
387
|
+
/// Allocator for the runtime's on-demand storage (registered
|
|
388
|
+
/// canvas font bytes, sized per file at registration, and adopted
|
|
389
|
+
/// media-surface texture buffers, one frame-budget buffer per
|
|
390
|
+
/// texture entry allocated at first adoption — a runtime with no
|
|
391
|
+
/// registered fonts and no media producers allocates nothing; the
|
|
392
|
+
/// fixed-capacity per-view storage stays embedded in the Runtime
|
|
393
|
+
/// struct). The default suits process-lifetime runtimes; embedders
|
|
394
|
+
/// that create and destroy runtimes in one process (tests, the docs
|
|
395
|
+
/// wasm preview host) pass their own and call `Runtime.deinit`. The
|
|
396
|
+
/// runtime captures this into its `owned_allocator` at init:
|
|
397
|
+
/// mutating `options.allocator` on a live runtime retargets
|
|
398
|
+
/// nothing — pick the owning allocator here, before init.
|
|
399
|
+
allocator: std.mem.Allocator = std.heap.page_allocator,
|
|
387
400
|
trace_sink: ?trace.Sink = null,
|
|
388
401
|
log_path: ?[]const u8 = null,
|
|
389
402
|
extensions: ?extensions.ModuleRegistry = null,
|
|
@@ -58,6 +58,21 @@ pub const AutomationWidgetKey = struct {
|
|
|
58
58
|
modifiers: AutomationKeyModifiers = .{},
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
/// `widget-pinch <view-label> <scale> [<x> <y>]`: a trackpad pinch
|
|
62
|
+
/// gesture against a gpu-surface view. `scale` is the FINAL
|
|
63
|
+
/// multiplicative zoom for the gesture (1.5 zooms in 50%, 0.5 zooms out
|
|
64
|
+
/// to half) — the dispatch synthesizes begin, one change carrying
|
|
65
|
+
/// `scale - 1`, and end, so the product of `(1 + delta)` lands exactly
|
|
66
|
+
/// on `scale`. The optional
|
|
67
|
+
/// anchor point is view-local canvas points (where the zoom anchors,
|
|
68
|
+
/// like the pointer position under a real pinch); omitted, it defaults
|
|
69
|
+
/// to the view center.
|
|
70
|
+
pub const AutomationWidgetPinch = struct {
|
|
71
|
+
view_label: []const u8,
|
|
72
|
+
scale: f32,
|
|
73
|
+
point: ?geometry.PointF = null,
|
|
74
|
+
};
|
|
75
|
+
|
|
61
76
|
/// Modifier chord for automation key dispatch, mirroring
|
|
62
77
|
/// `platform.ShortcutModifiers` field-for-field (automation stays
|
|
63
78
|
/// platform-agnostic; the dispatch layer copies these across).
|
|
@@ -261,6 +276,24 @@ pub fn parseAutomationWidgetKey(value: []const u8) !AutomationWidgetKey {
|
|
|
261
276
|
return .{ .view_label = view.token, .key = chord.key, .text = text, .modifiers = chord.modifiers };
|
|
262
277
|
}
|
|
263
278
|
|
|
279
|
+
pub fn parseAutomationWidgetPinch(value: []const u8) !AutomationWidgetPinch {
|
|
280
|
+
const view = takeAutomationToken(value) orelse return error.InvalidCommand;
|
|
281
|
+
const scale_part = takeAutomationToken(view.rest) orelse return error.InvalidCommand;
|
|
282
|
+
const scale = std.fmt.parseFloat(f32, scale_part.token) catch return error.InvalidCommand;
|
|
283
|
+
// A non-positive cumulative scale is not a gesture two fingers can
|
|
284
|
+
// perform (the product of 1 + delta stays positive); refuse loudly.
|
|
285
|
+
if (!std.math.isFinite(scale) or scale <= 0) return error.InvalidCommand;
|
|
286
|
+
const x_part = takeAutomationToken(scale_part.rest) orelse {
|
|
287
|
+
return .{ .view_label = view.token, .scale = scale };
|
|
288
|
+
};
|
|
289
|
+
const y_part = takeAutomationToken(x_part.rest) orelse return error.InvalidCommand;
|
|
290
|
+
if (takeAutomationToken(y_part.rest) != null) return error.InvalidCommand;
|
|
291
|
+
const x = std.fmt.parseFloat(f32, x_part.token) catch return error.InvalidCommand;
|
|
292
|
+
const y = std.fmt.parseFloat(f32, y_part.token) catch return error.InvalidCommand;
|
|
293
|
+
if (!std.math.isFinite(x) or !std.math.isFinite(y)) return error.InvalidCommand;
|
|
294
|
+
return .{ .view_label = view.token, .scale = scale, .point = geometry.PointF.init(x, y) };
|
|
295
|
+
}
|
|
296
|
+
|
|
264
297
|
pub fn parseAutomationWidgetPointerDrag(value: []const u8) !AutomationWidgetPointerDrag {
|
|
265
298
|
const view = takeAutomationToken(value) orelse return error.InvalidCommand;
|
|
266
299
|
const id_part = takeAutomationToken(view.rest) orelse return error.InvalidCommand;
|