@native-sdk/cli 0.9.4 → 0.9.5
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/README.md +3 -3
- package/build/app.zig +68 -57
- package/build.zig +12 -1
- package/package.json +10 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +435 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +41 -2
- package/src/platform/macos/appkit_host.m +198 -9
- package/src/platform/macos/cef_host.mm +191 -9
- package/src/platform/macos/root.zig +110 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +58 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/canvas/reference.zig +37 -15
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +7 -2
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +4 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/flow.zig +1 -1
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +120 -33
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +165 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
|
@@ -1731,6 +1731,69 @@ test "reference renderer bilinear-filters scaled images" {
|
|
|
1731
1731
|
try expectPixelRgba8(.{ 255, 255, 255, 255 }, surface, 3, 3);
|
|
1732
1732
|
}
|
|
1733
1733
|
|
|
1734
|
+
test "reference renderer keeps linear atlas crops inside their source rectangle" {
|
|
1735
|
+
const commands = [_]CanvasCommand{.{ .draw_image = .{
|
|
1736
|
+
.id = 1,
|
|
1737
|
+
.image_id = 42,
|
|
1738
|
+
.src = geometry.RectF.init(1, 1, 2, 2),
|
|
1739
|
+
.dst = geometry.RectF.init(0, 0, 4, 4),
|
|
1740
|
+
} }};
|
|
1741
|
+
|
|
1742
|
+
// A green 2x2 tile surrounded by red atlas neighbors. Scaling the
|
|
1743
|
+
// crop 2x must stay green through its edge pixels; full-image clamp
|
|
1744
|
+
// would blend red into every side through the bilinear taps.
|
|
1745
|
+
var image_pixels: [4 * 4 * 4]u8 = undefined;
|
|
1746
|
+
for (0..16) |index| {
|
|
1747
|
+
image_pixels[index * 4 + 0] = 255;
|
|
1748
|
+
image_pixels[index * 4 + 1] = 0;
|
|
1749
|
+
image_pixels[index * 4 + 2] = 0;
|
|
1750
|
+
image_pixels[index * 4 + 3] = 255;
|
|
1751
|
+
}
|
|
1752
|
+
for (1..3) |y| {
|
|
1753
|
+
for (1..3) |x| {
|
|
1754
|
+
const index = (y * 4 + x) * 4;
|
|
1755
|
+
image_pixels[index + 0] = 0;
|
|
1756
|
+
image_pixels[index + 1] = 255;
|
|
1757
|
+
image_pixels[index + 2] = 0;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
const images = [_]ReferenceImage{.{
|
|
1761
|
+
.id = 42,
|
|
1762
|
+
.width = 4,
|
|
1763
|
+
.height = 4,
|
|
1764
|
+
.pixels = &image_pixels,
|
|
1765
|
+
}};
|
|
1766
|
+
|
|
1767
|
+
var render_commands: [1]RenderCommand = undefined;
|
|
1768
|
+
var render_batches: [1]RenderBatch = undefined;
|
|
1769
|
+
var resources: [1]RenderResource = undefined;
|
|
1770
|
+
var resource_cache_entries: [1]RenderResourceCacheEntry = undefined;
|
|
1771
|
+
var resource_cache_actions: [1]RenderResourceCacheAction = undefined;
|
|
1772
|
+
var glyphs: [0]GlyphAtlasEntry = .{};
|
|
1773
|
+
var changes: [0]DiffChange = .{};
|
|
1774
|
+
const frame = try (DisplayList{ .commands = &commands }).framePlan(null, .{
|
|
1775
|
+
.surface_size = geometry.SizeF.init(4, 4),
|
|
1776
|
+
}, .{
|
|
1777
|
+
.render_commands = &render_commands,
|
|
1778
|
+
.render_batches = &render_batches,
|
|
1779
|
+
.resources = &resources,
|
|
1780
|
+
.resource_cache_entries = &resource_cache_entries,
|
|
1781
|
+
.resource_cache_actions = &resource_cache_actions,
|
|
1782
|
+
.glyph_atlas_entries = &glyphs,
|
|
1783
|
+
.changes = &changes,
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1786
|
+
var pixels: [4 * 4 * 4]u8 = undefined;
|
|
1787
|
+
const surface = (try ReferenceRenderSurface.init(4, 4, &pixels)).withImages(&images);
|
|
1788
|
+
try surface.renderPass(frame.renderPass(), Color.rgb8(0, 0, 0));
|
|
1789
|
+
|
|
1790
|
+
for (0..4) |y| {
|
|
1791
|
+
for (0..4) |x| {
|
|
1792
|
+
try expectPixelRgba8(.{ 0, 255, 0, 255 }, surface, x, y);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1734
1797
|
test "reference renderer nearest-filters scaled images" {
|
|
1735
1798
|
const commands = [_]CanvasCommand{.{ .draw_image = .{
|
|
1736
1799
|
.id = 1,
|
|
@@ -579,6 +579,14 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
579
579
|
/// shape, one bit of the id space apart (see
|
|
580
580
|
/// `canvas.media_surface_image_id_bit`).
|
|
581
581
|
image: canvas.ImageId = 0,
|
|
582
|
+
/// Optional source rectangle in image pixel coordinates for
|
|
583
|
+
/// image-bearing widgets. Null draws the whole registered
|
|
584
|
+
/// image; a rectangle draws only that sub-region, clipped to
|
|
585
|
+
/// the registered image bounds — the texture-atlas path.
|
|
586
|
+
/// Crops use nearest sampling so filtering cannot bleed an
|
|
587
|
+
/// adjacent atlas region. The destination remains the
|
|
588
|
+
/// widget's resolved frame.
|
|
589
|
+
image_src: ?geometry.RectF = null,
|
|
582
590
|
/// Vector icon name drawn inside icon-bearing controls
|
|
583
591
|
/// (`button`, `toggle_button`, `icon_button`, `list_item`,
|
|
584
592
|
/// `menu_item`): a built-in registry name
|
|
@@ -3759,6 +3767,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3759
3767
|
.autofocus = options.autofocus,
|
|
3760
3768
|
.submit_on_enter = options.submit_on_enter,
|
|
3761
3769
|
.image_id = options.image,
|
|
3770
|
+
.image_src = options.image_src,
|
|
3762
3771
|
.value = options.value,
|
|
3763
3772
|
.value_x = options.value_x,
|
|
3764
3773
|
.tree_level = options.tree_level,
|
|
@@ -1269,6 +1269,14 @@ pub const tooltip_delay_dependent_attr_message = "tooltip-delay needs anchor on
|
|
|
1269
1269
|
|
|
1270
1270
|
pub const image_binding_message = "image takes one {binding} to a u64 ImageId the app registered at runtime (Cmd.imageLoad, fx.loadImage, fx.registerImageBytes) - runtime image ids are model data, not markup literals; 0 renders nothing (an avatar falls back to its initials)";
|
|
1271
1271
|
pub const image_binding_element_message = "image is only supported on avatar and image - the remaining image-bearing widget (icon-button) stays a Zig view (ElementOptions.image)";
|
|
1272
|
+
pub const image_source_element_message = "source-x, source-y, source-width, and source-height are only supported on avatar and image - they crop a runtime-registered image in decoded-image pixel coordinates";
|
|
1273
|
+
pub const image_source_binding_message = "source-x, source-y, source-width, and source-height require the element's image binding - without a registered image the source rectangle is inert";
|
|
1274
|
+
pub const image_source_complete_message = "source-x, source-y, source-width, and source-height must be declared together - they form one source rectangle in decoded-image pixel coordinates";
|
|
1275
|
+
pub const image_source_attr_names = [_][]const u8{ "source-x", "source-y", "source-width", "source-height" };
|
|
1276
|
+
|
|
1277
|
+
pub fn imageSourceAttrName(name: []const u8) bool {
|
|
1278
|
+
return nameInList(name, &image_source_attr_names);
|
|
1279
|
+
}
|
|
1272
1280
|
pub const image_missing_image_message = "image requires image={binding} naming the u64 ImageId the app registered at runtime - without one the leaf can never draw anything (dead markup, same policy as icon without name)";
|
|
1273
1281
|
pub const image_children_message = "image is a leaf - it takes no children";
|
|
1274
1282
|
|
|
@@ -3353,6 +3361,27 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
|
|
|
3353
3361
|
}
|
|
3354
3362
|
continue;
|
|
3355
3363
|
}
|
|
3364
|
+
if (imageSourceAttrName(attribute.name)) {
|
|
3365
|
+
// A registered-image crop is one atomic rectangle in
|
|
3366
|
+
// decoded-image pixel coordinates. Partial declarations
|
|
3367
|
+
// and crops without an image would otherwise become
|
|
3368
|
+
// silently inert data.
|
|
3369
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
3370
|
+
return attrError(node, attribute, image_source_element_message);
|
|
3371
|
+
}
|
|
3372
|
+
if (node.attr("image") == null) {
|
|
3373
|
+
return attrError(node, attribute, image_source_binding_message);
|
|
3374
|
+
}
|
|
3375
|
+
for (image_source_attr_names) |name| {
|
|
3376
|
+
if (node.attr(name) == null) {
|
|
3377
|
+
return attrError(node, attribute, image_source_complete_message);
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
if (attrExpressionError(attribute.value, invalid_expression_message)) |message| {
|
|
3381
|
+
return attrError(node, attribute, message);
|
|
3382
|
+
}
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3356
3385
|
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
3357
3386
|
// The media-surface producer rendezvous, media-surface
|
|
3358
3387
|
// scoped: surface ids are model data a producer
|
|
@@ -1820,6 +1820,7 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1820
1820
|
// ---------------------------------------------------- attributes
|
|
1821
1821
|
|
|
1822
1822
|
fn applyAttrs(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1823
|
+
applyImageSourceAttrs(node, entries, ui, model, scope, options);
|
|
1823
1824
|
inline for (0..node.attrs.len) |attr_index| {
|
|
1824
1825
|
const attribute = comptime node.attrs[attr_index];
|
|
1825
1826
|
if (comptime std.mem.eql(u8, attribute.name, "kind")) {
|
|
@@ -1840,6 +1841,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1840
1841
|
};
|
|
1841
1842
|
} else if (comptime std.mem.eql(u8, attribute.name, "image")) {
|
|
1842
1843
|
applyImageAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1844
|
+
} else if (comptime markup.imageSourceAttrName(attribute.name)) {
|
|
1845
|
+
// Consumed atomically by applyImageSourceAttrs above.
|
|
1843
1846
|
} else if (comptime std.mem.eql(u8, attribute.name, "surface")) {
|
|
1844
1847
|
applySurfaceAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1845
1848
|
} else if (comptime std.mem.eql(u8, attribute.name, "pty")) {
|
|
@@ -1943,6 +1946,35 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1943
1946
|
};
|
|
1944
1947
|
}
|
|
1945
1948
|
|
|
1949
|
+
/// Comptime mirror of the interpreter's atomic source-rectangle
|
|
1950
|
+
/// construction. Source-known shape mistakes are compile errors;
|
|
1951
|
+
/// bound numeric values evaluate through the shared expression
|
|
1952
|
+
/// path at runtime.
|
|
1953
|
+
fn applyImageSourceAttrs(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1954
|
+
const has_any = comptime blk: {
|
|
1955
|
+
for (markup.image_source_attr_names) |name| {
|
|
1956
|
+
if (node.attr(name) != null) break :blk true;
|
|
1957
|
+
}
|
|
1958
|
+
break :blk false;
|
|
1959
|
+
};
|
|
1960
|
+
if (comptime !has_any) return;
|
|
1961
|
+
comptime {
|
|
1962
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
1963
|
+
fail(node, markup.image_source_element_message);
|
|
1964
|
+
}
|
|
1965
|
+
if (node.attr("image") == null) fail(node, markup.image_source_binding_message);
|
|
1966
|
+
for (markup.image_source_attr_names) |name| {
|
|
1967
|
+
if (node.attr(name) == null) fail(node, markup.image_source_complete_message);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
options.image_src = .{
|
|
1971
|
+
.x = floatAttr(node, entries, comptime node.attr("source-x").?, ui, model, scope),
|
|
1972
|
+
.y = floatAttr(node, entries, comptime node.attr("source-y").?, ui, model, scope),
|
|
1973
|
+
.width = floatAttr(node, entries, comptime node.attr("source-width").?, ui, model, scope),
|
|
1974
|
+
.height = floatAttr(node, entries, comptime node.attr("source-height").?, ui, model, scope),
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1946
1978
|
/// Comptime mirror of the interpreter's `applySurfaceAttr`:
|
|
1947
1979
|
/// `surface="{binding}"` on media-surface resolves to the
|
|
1948
1980
|
/// model-owned u64 surface id a producer targets —
|
|
@@ -1406,12 +1406,14 @@ test "compiled image leaf binding matches the interpreter and the hand-written v
|
|
|
1406
1406
|
try expectSameTree(fixture.ImageLeafMsg, hand, interpreted);
|
|
1407
1407
|
try expectSameTree(fixture.ImageLeafMsg, hand, compiled);
|
|
1408
1408
|
|
|
1409
|
-
// The field binding and
|
|
1410
|
-
//
|
|
1409
|
+
// The field binding, source-coordinate bindings, and id fn all
|
|
1410
|
+
// resolve through comptime-unrolled access.
|
|
1411
1411
|
const cover = compiled.root.children[0];
|
|
1412
1412
|
try testing.expectEqual(canvas.WidgetKind.image, cover.kind);
|
|
1413
1413
|
try testing.expectEqual(@as(canvas.ImageId, 42), cover.image_id);
|
|
1414
|
+
try testing.expectEqualDeep(@as(?geometry.RectF, geometry.RectF.init(4, 8, 32, 24)), cover.image_src);
|
|
1414
1415
|
try testing.expectEqual(@as(canvas.ImageId, 43), compiled.root.children[1].image_id);
|
|
1416
|
+
try testing.expectEqual(@as(?geometry.RectF, null), compiled.root.children[1].image_src);
|
|
1415
1417
|
|
|
1416
1418
|
// 0 draws nothing in both engines — the not-loaded-yet state.
|
|
1417
1419
|
const empty_model = fixture.ImageLeafModel{};
|
|
@@ -1248,6 +1248,13 @@ const Checker = struct {
|
|
|
1248
1248
|
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.image_binding_message);
|
|
1249
1249
|
continue;
|
|
1250
1250
|
}
|
|
1251
|
+
if (markup.imageSourceAttrName(attribute.name)) {
|
|
1252
|
+
// Structural validation owns the atomic/scoped rectangle
|
|
1253
|
+
// rules; the model-aware pass verifies every coordinate
|
|
1254
|
+
// binding is numeric and marks it used.
|
|
1255
|
+
try self.checkClassAttr(node, attribute, .number);
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1251
1258
|
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1252
1259
|
// Media-surface ids are model integers (engine parity —
|
|
1253
1260
|
// the runtime-image-id shape exactly).
|
|
@@ -795,6 +795,27 @@ test "the image leaf's image binding checks as a model integer" {
|
|
|
795
795
|
try testing.expectEqualStrings(markup.image_binding_message, message);
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
+
test "registered-image source rectangle bindings check as numbers" {
|
|
799
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
800
|
+
defer arena_state.deinit();
|
|
801
|
+
const arena = arena_state.allocator();
|
|
802
|
+
|
|
803
|
+
const good = try parseFixture(arena,
|
|
804
|
+
\\<column>
|
|
805
|
+
\\ <image image="{count}" source-x="{ratio}" source-y="{count}" source-width="32" source-height="16" label="Atlas tile" />
|
|
806
|
+
\\</column>
|
|
807
|
+
);
|
|
808
|
+
try testing.expectEqual(null, try contractMessage(arena, good, null));
|
|
809
|
+
|
|
810
|
+
const wrong = try parseFixture(arena,
|
|
811
|
+
\\<column>
|
|
812
|
+
\\ <image image="{count}" source-x="{name}" source-y="0" source-width="32" source-height="16" label="Atlas tile" />
|
|
813
|
+
\\</column>
|
|
814
|
+
);
|
|
815
|
+
const message = (try contractMessage(arena, wrong, null)).?;
|
|
816
|
+
try testing.expect(std.mem.startsWith(u8, message, "expected a number"));
|
|
817
|
+
}
|
|
818
|
+
|
|
798
819
|
test "app: icon references check against the contract's registered icon list" {
|
|
799
820
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
800
821
|
defer arena_state.deinit();
|
|
@@ -696,6 +696,7 @@ test "the image attribute validates as one binding on avatar and image" {
|
|
|
696
696
|
const valid = [_][]const u8{
|
|
697
697
|
"<row>\n <avatar image=\"{user_image}\">CT</avatar>\n</row>",
|
|
698
698
|
"<row>\n <image image=\"{cover}\" width=\"120\" height=\"80\" label=\"Cover art\" />\n</row>",
|
|
699
|
+
"<row>\n <image image=\"{atlas}\" source-x=\"0\" source-y=\"32\" source-width=\"16\" source-height=\"16\" label=\"Atlas tile\" />\n</row>",
|
|
699
700
|
};
|
|
700
701
|
for (valid) |source| {
|
|
701
702
|
var parser = markup.Parser.init(arena, source);
|
|
@@ -711,6 +712,11 @@ test "the image attribute validates as one binding on avatar and image" {
|
|
|
711
712
|
// attribute would be silently inert.
|
|
712
713
|
.{ .source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>", .message = markup.image_binding_element_message },
|
|
713
714
|
.{ .source = "<column>\n <panel image=\"{user_image}\" />\n</column>", .message = markup.image_binding_element_message },
|
|
715
|
+
// Source rectangles are image/avatar-only, require an image, and
|
|
716
|
+
// are atomic so a missing coordinate never defaults silently.
|
|
717
|
+
.{ .source = "<row>\n <badge source-x=\"0\" source-y=\"0\" source-width=\"16\" source-height=\"16\">3</badge>\n</row>", .message = markup.image_source_element_message },
|
|
718
|
+
.{ .source = "<row>\n <avatar source-x=\"0\" source-y=\"0\" source-width=\"16\" source-height=\"16\">CT</avatar>\n</row>", .message = markup.image_source_binding_message },
|
|
719
|
+
.{ .source = "<row>\n <image image=\"{atlas}\" source-x=\"0\" source-y=\"0\" source-width=\"16\" label=\"Tile\" />\n</row>", .message = markup.image_source_complete_message },
|
|
714
720
|
// ...and required on the leaf: an unbound image is statically
|
|
715
721
|
// dead markup (avatar keeps its initials fallback instead).
|
|
716
722
|
.{ .source = "<row>\n <image label=\"Art\" />\n</row>", .message = markup.image_missing_image_message },
|
|
@@ -1714,6 +1714,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1714
1714
|
// ---------------------------------------------------- attributes
|
|
1715
1715
|
|
|
1716
1716
|
fn applyAttrs(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
1717
|
+
try self.applyImageSourceAttrs(scope, node, options);
|
|
1717
1718
|
for (node.attrs) |attribute| {
|
|
1718
1719
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
1719
1720
|
if (std.mem.startsWith(u8, attribute.name, "on-")) {
|
|
@@ -1751,6 +1752,7 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1751
1752
|
try self.applyImageAttr(scope, node, options, attribute);
|
|
1752
1753
|
continue;
|
|
1753
1754
|
}
|
|
1755
|
+
if (markup.imageSourceAttrName(attribute.name)) continue;
|
|
1754
1756
|
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1755
1757
|
try self.applySurfaceAttr(scope, node, options, attribute);
|
|
1756
1758
|
continue;
|
|
@@ -1868,6 +1870,32 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
1868
1870
|
};
|
|
1869
1871
|
}
|
|
1870
1872
|
|
|
1873
|
+
/// The four `source-*` attributes form one optional source
|
|
1874
|
+
/// rectangle in decoded-image pixel coordinates. Build it before
|
|
1875
|
+
/// the scalar attribute walk so declaration order carries no
|
|
1876
|
+
/// meaning; repeat the validator's shape checks for hot-reloaded
|
|
1877
|
+
/// documents that reached the interpreter without validation.
|
|
1878
|
+
fn applyImageSourceAttrs(self: *Self, scope: *Scope, node: markup.MarkupNode, options: *Ui.ElementOptions) BuildError!void {
|
|
1879
|
+
var any = false;
|
|
1880
|
+
for (markup.image_source_attr_names) |name| {
|
|
1881
|
+
if (node.attr(name) != null) any = true;
|
|
1882
|
+
}
|
|
1883
|
+
if (!any) return;
|
|
1884
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) {
|
|
1885
|
+
return self.failVoid(node, markup.image_source_element_message);
|
|
1886
|
+
}
|
|
1887
|
+
if (node.attr("image") == null) return self.failVoid(node, markup.image_source_binding_message);
|
|
1888
|
+
for (markup.image_source_attr_names) |name| {
|
|
1889
|
+
if (node.attr(name) == null) return self.failVoid(node, markup.image_source_complete_message);
|
|
1890
|
+
}
|
|
1891
|
+
options.image_src = .{
|
|
1892
|
+
.x = try self.floatAttr(scope, node, node.attrEntry("source-x").?),
|
|
1893
|
+
.y = try self.floatAttr(scope, node, node.attrEntry("source-y").?),
|
|
1894
|
+
.width = try self.floatAttr(scope, node, node.attrEntry("source-width").?),
|
|
1895
|
+
.height = try self.floatAttr(scope, node, node.attrEntry("source-height").?),
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1871
1899
|
/// `surface="{binding}"` on media-surface: the model-owned u64
|
|
1872
1900
|
/// surface id a producer targets — media-surface-only,
|
|
1873
1901
|
/// binding-only, integer-valued (the runtime-image-id grammar
|
|
@@ -2846,6 +2846,9 @@ pub const ImageLeafModel = struct {
|
|
|
2846
2846
|
/// A signed id field: bindings evaluate as i64, so a negative must
|
|
2847
2847
|
/// reach the image seam as a value, never trap in the u64 cast.
|
|
2848
2848
|
stale_image: i64 = -2,
|
|
2849
|
+
source_x: f32 = 4,
|
|
2850
|
+
source_width: f32 = 32,
|
|
2851
|
+
invalid_source: []const u8 = "wide",
|
|
2849
2852
|
|
|
2850
2853
|
/// A pub fn producing an ImageId binds like a field.
|
|
2851
2854
|
pub fn thumbnail(model: *const ImageLeafModel) canvas.ImageId {
|
|
@@ -2855,7 +2858,7 @@ pub const ImageLeafModel = struct {
|
|
|
2855
2858
|
|
|
2856
2859
|
pub const image_markup_source =
|
|
2857
2860
|
\\<row gap="8">
|
|
2858
|
-
\\ <image image="{cover}" width="120" height="80" label="Cover art" />
|
|
2861
|
+
\\ <image image="{cover}" source-x="{source_x}" source-y="8" source-width="{source_width}" source-height="24" width="120" height="80" label="Cover art" />
|
|
2859
2862
|
\\ <image image="{thumbnail}" width="48" height="48" label="" />
|
|
2860
2863
|
\\</row>
|
|
2861
2864
|
;
|
|
@@ -2875,7 +2878,7 @@ pub const ImageLeafUi = canvas.Ui(ImageLeafMsg);
|
|
|
2875
2878
|
/// shares.
|
|
2876
2879
|
pub fn handImageLeafView(ui: *ImageLeafUi, model: *const ImageLeafModel) ImageLeafUi.Node {
|
|
2877
2880
|
return ui.row(.{ .gap = 8 }, .{
|
|
2878
|
-
ui.image(.{ .image = model.cover, .width = 120, .height = 80, .semantics = .{ .label = "Cover art" } }),
|
|
2881
|
+
ui.image(.{ .image = model.cover, .image_src = geometry.RectF.init(model.source_x, 8, model.source_width, 24), .width = 120, .height = 80, .semantics = .{ .label = "Cover art" } }),
|
|
2879
2882
|
ui.image(.{ .image = model.thumbnail(), .width = 48, .height = 48, .semantics = .{ .label = "" } }),
|
|
2880
2883
|
});
|
|
2881
2884
|
}
|
|
@@ -2902,13 +2905,16 @@ test "the image leaf binds a dynamic ImageId from model fields and fns" {
|
|
|
2902
2905
|
try collectIds(hand_tree.root, &hand_ids, testing.allocator);
|
|
2903
2906
|
try testing.expectEqualSlices(canvas.ObjectId, hand_ids.items, markup_ids.items);
|
|
2904
2907
|
|
|
2905
|
-
// The
|
|
2908
|
+
// The id and source-coordinate bindings land on the widget. The
|
|
2909
|
+
// second image omits a crop and draws the whole registered image.
|
|
2906
2910
|
const cover = markup_tree.root.children[0];
|
|
2907
2911
|
try testing.expectEqual(canvas.WidgetKind.image, cover.kind);
|
|
2908
2912
|
try testing.expectEqual(@as(canvas.ImageId, 42), cover.image_id);
|
|
2913
|
+
try testing.expectEqualDeep(@as(?geometry.RectF, geometry.RectF.init(4, 8, 32, 24)), cover.image_src);
|
|
2909
2914
|
try testing.expectEqualStrings("Cover art", cover.semantics.label);
|
|
2910
2915
|
const thumbnail = markup_tree.root.children[1];
|
|
2911
2916
|
try testing.expectEqual(@as(canvas.ImageId, 43), thumbnail.image_id);
|
|
2917
|
+
try testing.expectEqual(@as(?geometry.RectF, null), thumbnail.image_src);
|
|
2912
2918
|
|
|
2913
2919
|
// 0 is the "no image" sentinel: the leaf renders nothing (the
|
|
2914
2920
|
// model simply has not loaded the image yet).
|
|
@@ -2945,6 +2951,29 @@ test "image leaf misuse fails the build with the teaching messages" {
|
|
|
2945
2951
|
.source = "<row>\n <image image=\"{cover}\" label=\"Art\"><text>Caption</text></image>\n</row>",
|
|
2946
2952
|
.message = canvas.ui_markup.image_children_message,
|
|
2947
2953
|
},
|
|
2954
|
+
.{
|
|
2955
|
+
// A source rectangle is atomic: omitting one coordinate is
|
|
2956
|
+
// a typo, not an implicit zero/default.
|
|
2957
|
+
.source = "<row>\n <image image=\"{cover}\" source-x=\"0\" source-y=\"0\" source-width=\"16\" label=\"Art\" />\n</row>",
|
|
2958
|
+
.message = canvas.ui_markup.image_source_complete_message,
|
|
2959
|
+
},
|
|
2960
|
+
.{
|
|
2961
|
+
// Cropping without an image would be inert (avatar may omit
|
|
2962
|
+
// image normally for its initials fallback).
|
|
2963
|
+
.source = "<row>\n <avatar source-x=\"0\" source-y=\"0\" source-width=\"16\" source-height=\"16\">CT</avatar>\n</row>",
|
|
2964
|
+
.message = canvas.ui_markup.image_source_binding_message,
|
|
2965
|
+
},
|
|
2966
|
+
.{
|
|
2967
|
+
// Only registered-image widgets consume source rectangles.
|
|
2968
|
+
.source = "<row>\n <badge source-x=\"0\" source-y=\"0\" source-width=\"16\" source-height=\"16\">3</badge>\n</row>",
|
|
2969
|
+
.message = canvas.ui_markup.image_source_element_message,
|
|
2970
|
+
},
|
|
2971
|
+
.{
|
|
2972
|
+
// Runtime model values still pass the numeric conversion
|
|
2973
|
+
// gate; a string cannot become a source coordinate.
|
|
2974
|
+
.source = "<row>\n <image image=\"{cover}\" source-x=\"{invalid_source}\" source-y=\"0\" source-width=\"16\" source-height=\"16\" label=\"Art\" />\n</row>",
|
|
2975
|
+
.message = "expected a number",
|
|
2976
|
+
},
|
|
2948
2977
|
.{
|
|
2949
2978
|
// Markup that skipped validation (hot reload) can reach the
|
|
2950
2979
|
// engine without the binding: the leaf could only ever
|
|
@@ -591,6 +591,15 @@ pub const attrs = [_]AttrInfo{
|
|
|
591
591
|
// minimum unconstrained so a capped element still shrinks with a
|
|
592
592
|
// narrow parent.
|
|
593
593
|
.{ .code = 98, .name = "max-width", .class = .number, .group = .option, .field = "max_width" },
|
|
594
|
+
// Registered-image source rectangle, in decoded-image pixel
|
|
595
|
+
// coordinates. The four values are one atomic declaration: the
|
|
596
|
+
// validator scopes them to avatar/image and requires all four beside
|
|
597
|
+
// the image binding. They lower together into ElementOptions.image_src,
|
|
598
|
+
// so no individual attribute names a flat field.
|
|
599
|
+
.{ .code = 99, .name = "source-x", .class = .number, .group = .element },
|
|
600
|
+
.{ .code = 100, .name = "source-y", .class = .number, .group = .element },
|
|
601
|
+
.{ .code = 101, .name = "source-width", .class = .number, .group = .element },
|
|
602
|
+
.{ .code = 102, .name = "source-height", .class = .number, .group = .element },
|
|
594
603
|
};
|
|
595
604
|
|
|
596
605
|
// ----------------------------------------------------------------- events
|
|
@@ -22,7 +22,7 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
22
22
|
// the new fingerprint ONLY for additions; renames/renumbers are
|
|
23
23
|
// schema-version-bump events, not silent edits.
|
|
24
24
|
try testing.expectEqual(@as(usize, 70), schema.elements.len);
|
|
25
|
-
try testing.expectEqual(@as(usize,
|
|
25
|
+
try testing.expectEqual(@as(usize, 102), schema.attrs.len);
|
|
26
26
|
try testing.expectEqual(@as(usize, 15), schema.events.len);
|
|
27
27
|
// The element table runs through the span composite (64), the
|
|
28
28
|
// bubble-reactions composite (65), the media surface (66), the
|
|
@@ -48,9 +48,11 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
48
48
|
// code-diff line sets added-lines (94) and removed-lines (95), and
|
|
49
49
|
// Markdown's registered-image iterable binding images (96), and the
|
|
50
50
|
// textarea Enter policy submit-on-enter (97), and the responsive
|
|
51
|
-
// layout ceiling max-width (98)
|
|
51
|
+
// layout ceiling max-width (98), and the registered-image source
|
|
52
|
+
// rectangle source-x (99), source-y (100), source-width (101), and
|
|
53
|
+
// source-height (102).
|
|
52
54
|
try testing.expectEqual(
|
|
53
|
-
@as(u64,
|
|
55
|
+
@as(u64, 0x3614b1510b48dcf4),
|
|
54
56
|
tableFingerprint(schema.AttrInfo, &schema.attrs),
|
|
55
57
|
);
|
|
56
58
|
// The event table runs through the pointer-hover containment pair
|
|
@@ -562,9 +562,9 @@ test "avatar and image sugar carry registered image ids" {
|
|
|
562
562
|
|
|
563
563
|
var ui = InboxUi.init(arena_state.allocator());
|
|
564
564
|
const tree = try ui.finalize(ui.column(.{}, .{
|
|
565
|
-
ui.avatar(.{ .image = 77, .semantics = .{ .label = "Native SDK" } }, "NS"),
|
|
565
|
+
ui.avatar(.{ .image = 77, .image_src = geometry.RectF.init(32, 0, 32, 32), .semantics = .{ .label = "Native SDK" } }, "NS"),
|
|
566
566
|
ui.avatar(.{}, "NS"),
|
|
567
|
-
ui.image(.{ .image = 42, .semantics = .{ .label = "Chart" } }),
|
|
567
|
+
ui.image(.{ .image = 42, .image_src = geometry.RectF.init(4, 8, 24, 16), .semantics = .{ .label = "Chart" } }),
|
|
568
568
|
}));
|
|
569
569
|
|
|
570
570
|
// With an image id the avatar clips it to the circle (cover fit);
|
|
@@ -572,6 +572,7 @@ test "avatar and image sugar carry registered image ids" {
|
|
|
572
572
|
const with_image = tree.root.children[0];
|
|
573
573
|
try testing.expectEqual(canvas.WidgetKind.avatar, with_image.kind);
|
|
574
574
|
try testing.expectEqual(@as(canvas.ImageId, 77), with_image.image_id);
|
|
575
|
+
try testing.expectEqualDeep(@as(?geometry.RectF, geometry.RectF.init(32, 0, 32, 32)), with_image.image_src);
|
|
575
576
|
try testing.expectEqual(canvas.ImageFit.cover, with_image.image_fit);
|
|
576
577
|
try testing.expectEqualStrings("NS", with_image.text);
|
|
577
578
|
|
|
@@ -582,6 +583,7 @@ test "avatar and image sugar carry registered image ids" {
|
|
|
582
583
|
const image_leaf = tree.root.children[2];
|
|
583
584
|
try testing.expectEqual(canvas.WidgetKind.image, image_leaf.kind);
|
|
584
585
|
try testing.expectEqual(@as(canvas.ImageId, 42), image_leaf.image_id);
|
|
586
|
+
try testing.expectEqualDeep(@as(?geometry.RectF, geometry.RectF.init(4, 8, 24, 16)), image_leaf.image_src);
|
|
585
587
|
}
|
|
586
588
|
|
|
587
589
|
test "payload-carrying handlers build messages from edits and values" {
|
|
@@ -2697,7 +2697,10 @@ fn emitImageWidget(builder: *Builder, widget: Widget) Error!void {
|
|
|
2697
2697
|
.dst = widget.frame,
|
|
2698
2698
|
.opacity = widget.image_opacity,
|
|
2699
2699
|
.fit = widget.image_fit,
|
|
2700
|
-
|
|
2700
|
+
// Packet hosts expose filtering but no per-draw sampler-address
|
|
2701
|
+
// mode. Nearest sampling keeps an atlas crop from filtering
|
|
2702
|
+
// across its source boundary; whole-image draws stay linear.
|
|
2703
|
+
.sampling = if (widget.image_src != null) .nearest else widget.image_sampling,
|
|
2701
2704
|
});
|
|
2702
2705
|
if (clips_image) try builder.popClip();
|
|
2703
2706
|
}
|
|
@@ -2987,7 +2990,9 @@ fn emitAvatarWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Err
|
|
|
2987
2990
|
.dst = widget.frame,
|
|
2988
2991
|
.opacity = widget.image_opacity,
|
|
2989
2992
|
.fit = widget.image_fit,
|
|
2990
|
-
|
|
2993
|
+
// See emitImageWidget: a cropped avatar is an atlas draw and
|
|
2994
|
+
// must not sample neighboring regions on packet hosts.
|
|
2995
|
+
.sampling = if (widget.image_src != null) .nearest else widget.image_sampling,
|
|
2991
2996
|
// The render plan flattens the clip stack to rects, so the
|
|
2992
2997
|
// pill clip above only crops the bounds; the draw's own
|
|
2993
2998
|
// radius mask is what actually rounds the image.
|
|
@@ -829,7 +829,7 @@ test "widget image emits draw image and exposes image semantics" {
|
|
|
829
829
|
.image_id = 42,
|
|
830
830
|
.image_src = geometry.RectF.init(0, 0, 320, 192),
|
|
831
831
|
.image_fit = .cover,
|
|
832
|
-
.image_sampling = .
|
|
832
|
+
.image_sampling = .linear,
|
|
833
833
|
.image_opacity = 0.75,
|
|
834
834
|
.semantics = .{ .label = "Deployment preview" },
|
|
835
835
|
};
|
|
@@ -864,6 +864,8 @@ test "widget image emits draw image and exposes image semantics" {
|
|
|
864
864
|
try expectRect(geometry.RectF.init(0, 0, 320, 192), draw.src);
|
|
865
865
|
try expectRect(geometry.RectF.init(12, 14, 80, 48), draw.dst);
|
|
866
866
|
try std.testing.expectEqual(ImageFit.cover, draw.fit);
|
|
867
|
+
// Atlas crops force nearest sampling at the widget seam so
|
|
868
|
+
// packet hosts cannot filter outside the source rectangle.
|
|
867
869
|
try std.testing.expectEqual(ImageSampling.nearest, draw.sampling);
|
|
868
870
|
try std.testing.expectEqual(@as(f32, 0.75), draw.opacity);
|
|
869
871
|
},
|
package/src/root.zig
CHANGED
|
@@ -253,6 +253,10 @@ pub const TrayItemId = platform.TrayItemId;
|
|
|
253
253
|
pub const TrayOptions = platform.TrayOptions;
|
|
254
254
|
pub const TrayShell = platform.TrayShell;
|
|
255
255
|
pub const TrayMenuItem = platform.TrayMenuItem;
|
|
256
|
+
pub const TraySegmentOption = platform.TraySegmentOption;
|
|
257
|
+
pub const TraySegmentedRow = platform.TraySegmentedRow;
|
|
258
|
+
pub const TrayMetricRow = platform.TrayMetricRow;
|
|
259
|
+
pub const TrayChartRow = platform.TrayChartRow;
|
|
256
260
|
pub const BridgeDispatcher = bridge.Dispatcher;
|
|
257
261
|
pub const BridgePolicy = bridge.Policy;
|
|
258
262
|
pub const BridgeCommandPolicy = bridge.CommandPolicy;
|
|
@@ -103,6 +103,9 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
|
|
|
103
103
|
.role = item.role,
|
|
104
104
|
.key = item.key,
|
|
105
105
|
.modifiers = item.modifiers,
|
|
106
|
+
.segmented = item.segmented,
|
|
107
|
+
.metric = item.metric,
|
|
108
|
+
.chart = item.chart,
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
self.automation_trays[tray_count] = .{
|
package/src/runtime/flow.zig
CHANGED
|
@@ -1012,7 +1012,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
1012
1012
|
// stale or unknown item id is loud driver misuse,
|
|
1013
1013
|
// like widget-click on an unmounted widget.
|
|
1014
1014
|
const target = try parseAutomationTrayTarget(command.value);
|
|
1015
|
-
if (!SystemServiceMethods().
|
|
1015
|
+
if (!SystemServiceMethods().statusItemMenuItemActionable(self, target.status_item_id, target.item_id)) return error.InvalidCommand;
|
|
1016
1016
|
try dispatchPlatformEvent(self, app, .{ .tray_action = .{
|
|
1017
1017
|
.status_item_id = target.status_item_id,
|
|
1018
1018
|
.item_id = target.item_id,
|
package/src/runtime/state.zig
CHANGED
|
@@ -86,6 +86,20 @@ pub const RuntimeTrayItem = struct {
|
|
|
86
86
|
label_storage: [platform.max_tray_item_label_bytes]u8 = undefined,
|
|
87
87
|
detail_storage: [platform.max_tray_item_detail_bytes]u8 = undefined,
|
|
88
88
|
key_storage: [platform.max_menu_key_bytes]u8 = undefined,
|
|
89
|
+
segment_options: [platform.max_tray_segment_options]platform.TraySegmentOption = undefined,
|
|
90
|
+
segment_option_label_storage: [platform.max_tray_segment_options][platform.max_tray_segment_label_bytes]u8 = undefined,
|
|
91
|
+
segment_option_command_storage: [platform.max_tray_segment_options][platform.max_tray_item_command_bytes]u8 = undefined,
|
|
92
|
+
segment_option_count: usize = 0,
|
|
93
|
+
segmented: ?platform.TraySegmentedRow = null,
|
|
94
|
+
metric_primary_storage: [platform.max_tray_item_label_bytes]u8 = undefined,
|
|
95
|
+
metric_secondary_storage: [platform.max_tray_item_detail_bytes]u8 = undefined,
|
|
96
|
+
metric_accessibility_storage: [platform.max_tray_chart_text_bytes]u8 = undefined,
|
|
97
|
+
metric: ?platform.TrayMetricRow = null,
|
|
98
|
+
chart_values: [platform.max_tray_chart_values]f32 = undefined,
|
|
99
|
+
chart_leading_caption_storage: [platform.max_tray_chart_text_bytes]u8 = undefined,
|
|
100
|
+
chart_trailing_summary_storage: [platform.max_tray_chart_text_bytes]u8 = undefined,
|
|
101
|
+
chart_accessibility_label_storage: [platform.max_tray_chart_text_bytes]u8 = undefined,
|
|
102
|
+
chart: ?platform.TrayChartRow = null,
|
|
89
103
|
};
|
|
90
104
|
|
|
91
105
|
pub const RuntimeStatusItem = struct {
|