@native-sdk/cli 0.9.3 → 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 +323 -76
- package/build/ts_run.mjs +15 -18
- package/build.zig +83 -8
- package/package.json +14 -10
- package/packages/core/compile-surface/core.ts +1 -0
- package/packages/core/package-lock.json +16 -13
- package/packages/core/package.json +5 -2
- package/packages/core/scripts/compiler_command.mjs +71 -0
- package/packages/core/scripts/compiler_typecheck.mjs +4 -4
- package/packages/core/scripts/embed_markup_c.mjs +25 -0
- package/packages/core/scripts/npm_static_spike.mjs +3 -3
- package/packages/core/scripts/run_external_core_compiler.mjs +21 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -7
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/core.ts +1 -0
- package/packages/core/sdk/events.d.ts +36 -4
- package/packages/core/sdk/events.ts +49 -6
- package/packages/core/src/checker.ts +106 -10
- 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 +28 -6
- package/skill-data/ts-core/SKILL.md +9 -6
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/app_runner/ts_core_main.zig +12 -4
- package/src/app_runner/ts_core_mobile.zig +6 -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 +181 -39
- package/src/runtime/ui_app.zig +40 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/ui_app_window_tests.zig +23 -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 +171 -118
- package/src/tooling/ts_core.zig +12 -8
- package/src/tooling/verbs.zig +233 -5
- package/src/tooling/web_engine.zig +17 -1
- package/tools/corewire/emit_profile.zig +20 -7
- package/tools/corewire/emit_service.zig +49 -24
- package/tools/corewire/main.zig +21 -2
|
@@ -638,23 +638,13 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
638
638
|
}
|
|
639
639
|
for (state.items, 0..) |raw_item, index| {
|
|
640
640
|
const item = if (comptime @typeInfo(@TypeOf(raw_item)) == .pointer) raw_item.* else raw_item;
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
.
|
|
646
|
-
.
|
|
647
|
-
|
|
648
|
-
.role = statusItemRole(item.role),
|
|
649
|
-
.key = item.key,
|
|
650
|
-
.modifiers = .{
|
|
651
|
-
.primary = item.modifiers.primary,
|
|
652
|
-
.command = item.modifiers.command,
|
|
653
|
-
.control = item.modifiers.control,
|
|
654
|
-
.option = item.modifiers.option,
|
|
655
|
-
.shift = item.modifiers.shift,
|
|
656
|
-
},
|
|
657
|
-
};
|
|
641
|
+
const segment_start = index * platform.max_tray_segment_options;
|
|
642
|
+
const chart_start = index * platform.max_tray_chart_values;
|
|
643
|
+
scratch.items[index] = statusItemMenuItem(
|
|
644
|
+
item,
|
|
645
|
+
scratch.segment_options[segment_start .. segment_start + platform.max_tray_segment_options],
|
|
646
|
+
scratch.chart_values[chart_start .. chart_start + platform.max_tray_chart_values],
|
|
647
|
+
);
|
|
658
648
|
}
|
|
659
649
|
return statusItemState(state, scratch.items[0..state.items.len]);
|
|
660
650
|
}
|
|
@@ -684,7 +674,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
684
674
|
}
|
|
685
675
|
for (state.items, 0..) |raw_item, item_index| {
|
|
686
676
|
const item = if (comptime @typeInfo(@TypeOf(raw_item)) == .pointer) raw_item.* else raw_item;
|
|
687
|
-
|
|
677
|
+
const flat_row_index = row_start + item_index;
|
|
678
|
+
const segment_start = flat_row_index * platform.max_tray_segment_options;
|
|
679
|
+
const chart_start = flat_row_index * platform.max_tray_chart_values;
|
|
680
|
+
row_storage[item_index] = statusItemMenuItem(
|
|
681
|
+
item,
|
|
682
|
+
scratch.segment_options[segment_start .. segment_start + platform.max_tray_segment_options],
|
|
683
|
+
scratch.chart_values[chart_start .. chart_start + platform.max_tray_chart_values],
|
|
684
|
+
);
|
|
688
685
|
}
|
|
689
686
|
scratch.status_items[status_index] = .{
|
|
690
687
|
.id = statusItemId(state.id),
|
|
@@ -720,6 +717,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
720
717
|
.x = optionalWindowFloat(window.x),
|
|
721
718
|
.y = optionalWindowFloat(window.y),
|
|
722
719
|
.resizable = window.resizable,
|
|
720
|
+
.restore_policy = windowRestorePolicy(window.restorePolicy),
|
|
723
721
|
.min_width = statusItemFloat(window.minWidth),
|
|
724
722
|
.min_height = statusItemFloat(window.minHeight),
|
|
725
723
|
.titlebar = windowTitlebar(window.titlebar),
|
|
@@ -752,6 +750,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
752
750
|
unreachable;
|
|
753
751
|
}
|
|
754
752
|
|
|
753
|
+
fn windowRestorePolicy(value: anytype) @import("app_manifest").WindowRestorePolicy {
|
|
754
|
+
const Target = @import("app_manifest").WindowRestorePolicy;
|
|
755
|
+
inline for (std.meta.fields(Target)) |field| {
|
|
756
|
+
if (std.mem.eql(u8, @tagName(value), field.name)) return @enumFromInt(field.value);
|
|
757
|
+
}
|
|
758
|
+
unreachable;
|
|
759
|
+
}
|
|
760
|
+
|
|
755
761
|
fn windowClosePolicy(value: anytype) @import("app_manifest").WindowClosePolicy {
|
|
756
762
|
const Target = @import("app_manifest").WindowClosePolicy;
|
|
757
763
|
inline for (std.meta.fields(Target)) |field| {
|
|
@@ -781,8 +787,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
781
787
|
};
|
|
782
788
|
}
|
|
783
789
|
|
|
784
|
-
fn statusItemMenuItem(item: anytype) platform.TrayMenuItem {
|
|
785
|
-
|
|
790
|
+
fn statusItemMenuItem(item: anytype, segment_storage: []platform.TraySegmentOption, chart_storage: []f32) platform.TrayMenuItem {
|
|
791
|
+
var result = platform.TrayMenuItem{
|
|
786
792
|
.id = statusItemId(item.id),
|
|
787
793
|
.label = item.label,
|
|
788
794
|
.command = item.command,
|
|
@@ -799,6 +805,49 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
799
805
|
.shift = item.modifiers.shift,
|
|
800
806
|
},
|
|
801
807
|
};
|
|
808
|
+
if (@hasField(@TypeOf(item), "segmented")) if (item.segmented) |raw_segmented| {
|
|
809
|
+
const segmented = if (comptime @typeInfo(@TypeOf(raw_segmented)) == .pointer) raw_segmented.* else raw_segmented;
|
|
810
|
+
if (segmented.options.len <= segment_storage.len) {
|
|
811
|
+
for (segmented.options, 0..) |raw_option, index| {
|
|
812
|
+
const option = if (comptime @typeInfo(@TypeOf(raw_option)) == .pointer) raw_option.* else raw_option;
|
|
813
|
+
segment_storage[index] = .{
|
|
814
|
+
.id = statusItemId(option.id),
|
|
815
|
+
.label = option.label,
|
|
816
|
+
.command = option.command,
|
|
817
|
+
.selected = option.selected,
|
|
818
|
+
.enabled = option.enabled,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
result.segmented = .{ .options = segment_storage[0..segmented.options.len] };
|
|
822
|
+
} else {
|
|
823
|
+
result.segmented = .{};
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
if (@hasField(@TypeOf(item), "metric")) if (item.metric) |raw_metric| {
|
|
827
|
+
const metric = if (comptime @typeInfo(@TypeOf(raw_metric)) == .pointer) raw_metric.* else raw_metric;
|
|
828
|
+
result.metric = .{
|
|
829
|
+
.primary_text = metric.primaryText,
|
|
830
|
+
.secondary_text = metric.secondaryText,
|
|
831
|
+
.accessibility_label = metric.accessibilityLabel,
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
if (@hasField(@TypeOf(item), "chart")) if (item.chart) |raw_chart| {
|
|
835
|
+
const chart = if (comptime @typeInfo(@TypeOf(raw_chart)) == .pointer) raw_chart.* else raw_chart;
|
|
836
|
+
if (chart.values.len <= chart_storage.len) {
|
|
837
|
+
for (chart.values, 0..) |value, index| chart_storage[index] = statusItemFloat(value);
|
|
838
|
+
result.chart = .{
|
|
839
|
+
.values = chart_storage[0..chart.values.len],
|
|
840
|
+
.min_value = statusItemFloat(chart.minValue),
|
|
841
|
+
.max_value = statusItemFloat(chart.maxValue),
|
|
842
|
+
.leading_caption = chart.leadingCaption,
|
|
843
|
+
.trailing_summary = chart.trailingSummary,
|
|
844
|
+
.accessibility_label = chart.accessibilityLabel,
|
|
845
|
+
};
|
|
846
|
+
} else {
|
|
847
|
+
result.chart = .{};
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
return result;
|
|
802
851
|
}
|
|
803
852
|
|
|
804
853
|
fn statusItemState(state: anytype, items: []const platform.TrayMenuItem) App.StatusItemState {
|
|
@@ -810,6 +859,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
810
859
|
.tone = statusItemTone(presentation.tone),
|
|
811
860
|
.icon_opacity = statusItemFloat(presentation.iconOpacity),
|
|
812
861
|
.monospaced = presentation.monospaced,
|
|
862
|
+
.font_size = if (presentation.fontSize) |value| statusItemFloat(value) else 0,
|
|
863
|
+
.font_weight = if (presentation.fontWeight) |value| statusItemFontWeight(value) else .regular,
|
|
813
864
|
},
|
|
814
865
|
.icon_path = state.iconPath,
|
|
815
866
|
.tooltip = state.tooltip,
|
|
@@ -850,6 +901,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
850
901
|
unreachable;
|
|
851
902
|
}
|
|
852
903
|
|
|
904
|
+
fn statusItemFontWeight(value: anytype) platform.TrayFontWeight {
|
|
905
|
+
const name = @tagName(value);
|
|
906
|
+
inline for (std.meta.fields(platform.TrayFontWeight)) |field| {
|
|
907
|
+
if (std.mem.eql(u8, name, field.name)) return @enumFromInt(field.value);
|
|
908
|
+
}
|
|
909
|
+
unreachable;
|
|
910
|
+
}
|
|
911
|
+
|
|
853
912
|
fn statusItemRole(value: anytype) platform.TrayItemRole {
|
|
854
913
|
const name = @tagName(value);
|
|
855
914
|
inline for (std.meta.fields(platform.TrayItemRole)) |field| {
|
|
@@ -893,14 +952,17 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
893
952
|
}
|
|
894
953
|
const Presentation = statusItemRecordType(@FieldType(State, "presentation"), teaching);
|
|
895
954
|
const presentation_info = @typeInfo(Presentation).@"struct";
|
|
896
|
-
if (presentation_info.fields.len !=
|
|
897
|
-
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced")
|
|
955
|
+
if (presentation_info.fields.len != 7 or !@hasField(Presentation, "title") or !@hasField(Presentation, "width") or
|
|
956
|
+
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced") or
|
|
957
|
+
!@hasField(Presentation, "fontSize") or !@hasField(Presentation, "fontWeight"))
|
|
898
958
|
{
|
|
899
959
|
@compileError(teaching);
|
|
900
960
|
}
|
|
901
961
|
if (@FieldType(Presentation, "title") != []const u8 or !statusItemNumericType(@FieldType(Presentation, "width")) or
|
|
902
962
|
!statusItemEnumType(@FieldType(Presentation, "tone"), &.{ "normal", "warning", "critical" }) or
|
|
903
|
-
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool
|
|
963
|
+
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool or
|
|
964
|
+
!optionalNumericType(@FieldType(Presentation, "fontSize")) or
|
|
965
|
+
!optionalEnumType(@FieldType(Presentation, "fontWeight"), &.{ "regular", "medium", "semibold", "bold" }))
|
|
904
966
|
{
|
|
905
967
|
@compileError(teaching);
|
|
906
968
|
}
|
|
@@ -908,9 +970,10 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
908
970
|
if (items_info != .pointer or items_info.pointer.size != .slice or !items_info.pointer.is_const) @compileError(teaching);
|
|
909
971
|
const Item = statusItemRecordType(items_info.pointer.child, teaching);
|
|
910
972
|
const item_info = @typeInfo(Item).@"struct";
|
|
911
|
-
if (item_info.fields.len !=
|
|
973
|
+
if (item_info.fields.len != 12 or !@hasField(Item, "id") or !@hasField(Item, "label") or
|
|
912
974
|
!@hasField(Item, "command") or !@hasField(Item, "separator") or !@hasField(Item, "enabled") or
|
|
913
|
-
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or !@hasField(Item, "modifiers")
|
|
975
|
+
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or !@hasField(Item, "modifiers") or
|
|
976
|
+
!@hasField(Item, "segmented") or !@hasField(Item, "metric") or !@hasField(Item, "chart"))
|
|
914
977
|
{
|
|
915
978
|
@compileError(teaching);
|
|
916
979
|
}
|
|
@@ -918,7 +981,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
918
981
|
if (@FieldType(Item, "label") != []const u8 or @FieldType(Item, "command") != []const u8 or
|
|
919
982
|
@FieldType(Item, "separator") != bool or @FieldType(Item, "enabled") != bool or
|
|
920
983
|
@FieldType(Item, "detail") != []const u8 or
|
|
921
|
-
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context" }) or
|
|
984
|
+
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context", "segmented", "chart" }) or
|
|
922
985
|
@FieldType(Item, "key") != []const u8)
|
|
923
986
|
{
|
|
924
987
|
@compileError(teaching);
|
|
@@ -932,6 +995,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
932
995
|
{
|
|
933
996
|
@compileError(teaching);
|
|
934
997
|
}
|
|
998
|
+
validateStatusItemRichTypes(Item, teaching);
|
|
935
999
|
}
|
|
936
1000
|
|
|
937
1001
|
fn validateStatusItemsHelper() void {
|
|
@@ -967,11 +1031,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
967
1031
|
}
|
|
968
1032
|
const Presentation = statusItemRecordType(@FieldType(State, "presentation"), teaching);
|
|
969
1033
|
const presentation_info = @typeInfo(Presentation).@"struct";
|
|
970
|
-
if (presentation_info.fields.len !=
|
|
1034
|
+
if (presentation_info.fields.len != 7 or !@hasField(Presentation, "title") or !@hasField(Presentation, "width") or
|
|
971
1035
|
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced") or
|
|
1036
|
+
!@hasField(Presentation, "fontSize") or !@hasField(Presentation, "fontWeight") or
|
|
972
1037
|
@FieldType(Presentation, "title") != []const u8 or !statusItemNumericType(@FieldType(Presentation, "width")) or
|
|
973
1038
|
!statusItemEnumType(@FieldType(Presentation, "tone"), &.{ "normal", "warning", "critical" }) or
|
|
974
|
-
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool
|
|
1039
|
+
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool or
|
|
1040
|
+
!optionalNumericType(@FieldType(Presentation, "fontSize")) or
|
|
1041
|
+
!optionalEnumType(@FieldType(Presentation, "fontWeight"), &.{ "regular", "medium", "semibold", "bold" }))
|
|
975
1042
|
{
|
|
976
1043
|
@compileError(teaching);
|
|
977
1044
|
}
|
|
@@ -979,18 +1046,20 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
979
1046
|
if (items_info != .pointer or items_info.pointer.size != .slice or !items_info.pointer.is_const) @compileError(teaching);
|
|
980
1047
|
const Item = statusItemRecordType(items_info.pointer.child, teaching);
|
|
981
1048
|
const item_info = @typeInfo(Item).@"struct";
|
|
982
|
-
if (item_info.fields.len !=
|
|
1049
|
+
if (item_info.fields.len != 12 or !@hasField(Item, "id") or !@hasField(Item, "label") or
|
|
983
1050
|
!@hasField(Item, "command") or !@hasField(Item, "separator") or !@hasField(Item, "enabled") or
|
|
984
1051
|
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or
|
|
985
|
-
!@hasField(Item, "modifiers") or
|
|
1052
|
+
!@hasField(Item, "modifiers") or !@hasField(Item, "segmented") or !@hasField(Item, "metric") or !@hasField(Item, "chart") or
|
|
1053
|
+
!statusItemNumericType(@FieldType(Item, "id")) or
|
|
986
1054
|
@FieldType(Item, "label") != []const u8 or @FieldType(Item, "command") != []const u8 or
|
|
987
1055
|
@FieldType(Item, "separator") != bool or @FieldType(Item, "enabled") != bool or
|
|
988
1056
|
@FieldType(Item, "detail") != []const u8 or
|
|
989
|
-
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context" }) or
|
|
1057
|
+
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context", "segmented", "chart" }) or
|
|
990
1058
|
@FieldType(Item, "key") != []const u8)
|
|
991
1059
|
{
|
|
992
1060
|
@compileError(teaching);
|
|
993
1061
|
}
|
|
1062
|
+
validateStatusItemRichTypes(Item, teaching);
|
|
994
1063
|
const Modifiers = statusItemRecordType(@FieldType(Item, "modifiers"), teaching);
|
|
995
1064
|
const modifiers_info = @typeInfo(Modifiers).@"struct";
|
|
996
1065
|
if (modifiers_info.fields.len != 5 or !@hasField(Modifiers, "primary") or !@hasField(Modifiers, "command") or
|
|
@@ -1018,9 +1087,10 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1018
1087
|
if (return_info != .pointer or return_info.pointer.size != .slice or !return_info.pointer.is_const) @compileError(teaching);
|
|
1019
1088
|
const Window = statusItemRecordType(return_info.pointer.child, teaching);
|
|
1020
1089
|
const info = @typeInfo(Window).@"struct";
|
|
1021
|
-
if (info.fields.len !=
|
|
1090
|
+
if (info.fields.len != 19 or !@hasField(Window, "label") or !@hasField(Window, "canvasLabel") or
|
|
1022
1091
|
!@hasField(Window, "title") or !@hasField(Window, "width") or !@hasField(Window, "height") or
|
|
1023
1092
|
!@hasField(Window, "x") or !@hasField(Window, "y") or !@hasField(Window, "resizable") or
|
|
1093
|
+
!@hasField(Window, "restorePolicy") or
|
|
1024
1094
|
!@hasField(Window, "minWidth") or !@hasField(Window, "minHeight") or !@hasField(Window, "titlebar") or
|
|
1025
1095
|
!@hasField(Window, "transparent") or !@hasField(Window, "alwaysOnTop") or !@hasField(Window, "clickThrough") or
|
|
1026
1096
|
!@hasField(Window, "activateOnShow") or !@hasField(Window, "allowsFullscreen") or
|
|
@@ -1029,6 +1099,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1029
1099
|
@FieldType(Window, "title") != []const u8 or !statusItemNumericType(@FieldType(Window, "width")) or
|
|
1030
1100
|
!statusItemNumericType(@FieldType(Window, "height")) or !optionalNumericType(@FieldType(Window, "x")) or
|
|
1031
1101
|
!optionalNumericType(@FieldType(Window, "y")) or @FieldType(Window, "resizable") != bool or
|
|
1102
|
+
!statusItemEnumType(@FieldType(Window, "restorePolicy"), &.{ "clamp_to_visible_screen", "center_on_primary" }) or
|
|
1032
1103
|
!statusItemNumericType(@FieldType(Window, "minWidth")) or !statusItemNumericType(@FieldType(Window, "minHeight")) or
|
|
1033
1104
|
!statusItemEnumType(@FieldType(Window, "titlebar"), &.{ "standard", "hidden_inset", "hidden_inset_tall", "chromeless" }) or
|
|
1034
1105
|
@FieldType(Window, "transparent") != bool or @FieldType(Window, "alwaysOnTop") != bool or
|
|
@@ -1048,6 +1119,43 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1048
1119
|
return info == .optional and statusItemEnumType(info.optional.child, expected);
|
|
1049
1120
|
}
|
|
1050
1121
|
|
|
1122
|
+
fn validateStatusItemRichTypes(comptime Item: type, comptime teaching: []const u8) void {
|
|
1123
|
+
const segmented_info = @typeInfo(@FieldType(Item, "segmented"));
|
|
1124
|
+
const metric_info = @typeInfo(@FieldType(Item, "metric"));
|
|
1125
|
+
const chart_info = @typeInfo(@FieldType(Item, "chart"));
|
|
1126
|
+
if (segmented_info != .optional or metric_info != .optional or chart_info != .optional) @compileError(teaching);
|
|
1127
|
+
|
|
1128
|
+
const Segmented = statusItemRecordType(segmented_info.optional.child, teaching);
|
|
1129
|
+
const segmented_fields = @typeInfo(Segmented).@"struct".fields;
|
|
1130
|
+
if (segmented_fields.len != 1 or !@hasField(Segmented, "options")) @compileError(teaching);
|
|
1131
|
+
const options_info = @typeInfo(@FieldType(Segmented, "options"));
|
|
1132
|
+
if (options_info != .pointer or options_info.pointer.size != .slice or !options_info.pointer.is_const) @compileError(teaching);
|
|
1133
|
+
const Option = statusItemRecordType(options_info.pointer.child, teaching);
|
|
1134
|
+
const option_info = @typeInfo(Option).@"struct";
|
|
1135
|
+
if (option_info.fields.len != 5 or !@hasField(Option, "id") or !@hasField(Option, "label") or
|
|
1136
|
+
!@hasField(Option, "command") or !@hasField(Option, "selected") or !@hasField(Option, "enabled") or
|
|
1137
|
+
!statusItemNumericType(@FieldType(Option, "id")) or @FieldType(Option, "label") != []const u8 or
|
|
1138
|
+
@FieldType(Option, "command") != []const u8 or @FieldType(Option, "selected") != bool or
|
|
1139
|
+
@FieldType(Option, "enabled") != bool) @compileError(teaching);
|
|
1140
|
+
|
|
1141
|
+
const Metric = statusItemRecordType(metric_info.optional.child, teaching);
|
|
1142
|
+
const metric_fields = @typeInfo(Metric).@"struct".fields;
|
|
1143
|
+
if (metric_fields.len != 3 or !@hasField(Metric, "primaryText") or !@hasField(Metric, "secondaryText") or
|
|
1144
|
+
!@hasField(Metric, "accessibilityLabel") or @FieldType(Metric, "primaryText") != []const u8 or
|
|
1145
|
+
@FieldType(Metric, "secondaryText") != []const u8 or @FieldType(Metric, "accessibilityLabel") != []const u8) @compileError(teaching);
|
|
1146
|
+
|
|
1147
|
+
const Chart = statusItemRecordType(chart_info.optional.child, teaching);
|
|
1148
|
+
const chart_fields = @typeInfo(Chart).@"struct".fields;
|
|
1149
|
+
if (chart_fields.len != 6 or !@hasField(Chart, "values") or !@hasField(Chart, "minValue") or
|
|
1150
|
+
!@hasField(Chart, "maxValue") or !@hasField(Chart, "leadingCaption") or
|
|
1151
|
+
!@hasField(Chart, "trailingSummary") or !@hasField(Chart, "accessibilityLabel")) @compileError(teaching);
|
|
1152
|
+
const values_info = @typeInfo(@FieldType(Chart, "values"));
|
|
1153
|
+
if (values_info != .pointer or values_info.pointer.size != .slice or !values_info.pointer.is_const or
|
|
1154
|
+
!statusItemNumericType(values_info.pointer.child) or !statusItemNumericType(@FieldType(Chart, "minValue")) or
|
|
1155
|
+
!statusItemNumericType(@FieldType(Chart, "maxValue")) or @FieldType(Chart, "leadingCaption") != []const u8 or
|
|
1156
|
+
@FieldType(Chart, "trailingSummary") != []const u8 or @FieldType(Chart, "accessibilityLabel") != []const u8) @compileError(teaching);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1051
1159
|
fn statusItemNumericType(comptime T: type) bool {
|
|
1052
1160
|
return @typeInfo(T) == .int or @typeInfo(T) == .float;
|
|
1053
1161
|
}
|
|
@@ -1550,7 +1658,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1550
1658
|
|
|
1551
1659
|
const StatusItemsAdapterTestCore = struct {
|
|
1552
1660
|
const Tone = enum { normal, warning, critical };
|
|
1553
|
-
const Role = enum { command, info, header, hero, agent, context };
|
|
1661
|
+
const Role = enum { command, info, header, hero, agent, context, segmented, chart };
|
|
1554
1662
|
const Modifiers = struct {
|
|
1555
1663
|
primary: bool,
|
|
1556
1664
|
command: bool,
|
|
@@ -1564,6 +1672,29 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1564
1672
|
tone: Tone,
|
|
1565
1673
|
iconOpacity: f64,
|
|
1566
1674
|
monospaced: bool,
|
|
1675
|
+
fontSize: ?f64,
|
|
1676
|
+
fontWeight: ?enum { regular, medium, semibold, bold },
|
|
1677
|
+
};
|
|
1678
|
+
const SegmentOption = struct {
|
|
1679
|
+
id: f64,
|
|
1680
|
+
label: []const u8,
|
|
1681
|
+
command: []const u8,
|
|
1682
|
+
selected: bool,
|
|
1683
|
+
enabled: bool,
|
|
1684
|
+
};
|
|
1685
|
+
const Segmented = struct { options: []const SegmentOption };
|
|
1686
|
+
const Metric = struct {
|
|
1687
|
+
primaryText: []const u8,
|
|
1688
|
+
secondaryText: []const u8,
|
|
1689
|
+
accessibilityLabel: []const u8,
|
|
1690
|
+
};
|
|
1691
|
+
const Chart = struct {
|
|
1692
|
+
values: []const f64,
|
|
1693
|
+
minValue: f64,
|
|
1694
|
+
maxValue: f64,
|
|
1695
|
+
leadingCaption: []const u8,
|
|
1696
|
+
trailingSummary: []const u8,
|
|
1697
|
+
accessibilityLabel: []const u8,
|
|
1567
1698
|
};
|
|
1568
1699
|
const Item = struct {
|
|
1569
1700
|
id: f64,
|
|
@@ -1575,6 +1706,9 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1575
1706
|
role: Role,
|
|
1576
1707
|
key: []const u8,
|
|
1577
1708
|
modifiers: Modifiers,
|
|
1709
|
+
segmented: ?Segmented,
|
|
1710
|
+
metric: ?Metric,
|
|
1711
|
+
chart: ?Chart,
|
|
1578
1712
|
};
|
|
1579
1713
|
const Descriptor = struct {
|
|
1580
1714
|
id: f64,
|
|
@@ -1598,6 +1732,9 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1598
1732
|
.role = .command,
|
|
1599
1733
|
.key = "r",
|
|
1600
1734
|
.modifiers = .{ .primary = true, .command = false, .control = false, .option = false, .shift = false },
|
|
1735
|
+
.segmented = null,
|
|
1736
|
+
.metric = null,
|
|
1737
|
+
.chart = null,
|
|
1601
1738
|
}};
|
|
1602
1739
|
const descriptors = [_]Descriptor{.{
|
|
1603
1740
|
.id = 7,
|
|
@@ -1607,7 +1744,7 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1607
1744
|
.activationCommand = "spend.open",
|
|
1608
1745
|
.alternateActivationCommand = "",
|
|
1609
1746
|
.openCommand = "spend.refresh",
|
|
1610
|
-
.presentation = .{ .title = "$7", .width = 52, .tone = .warning, .iconOpacity = 0.75, .monospaced = true },
|
|
1747
|
+
.presentation = .{ .title = "$7", .width = 52, .tone = .warning, .iconOpacity = 0.75, .monospaced = true, .fontSize = null, .fontWeight = null },
|
|
1611
1748
|
.items = &rows,
|
|
1612
1749
|
}};
|
|
1613
1750
|
|
|
@@ -1629,6 +1766,8 @@ test "TypeScript statusItems adapter validates and projects canonical descriptor
|
|
|
1629
1766
|
try std.testing.expectEqual(@as(platform.StatusItemId, 7), descriptors[0].id);
|
|
1630
1767
|
try std.testing.expect(!descriptors[0].visible);
|
|
1631
1768
|
try std.testing.expectEqualStrings("$7", descriptors[0].state.presentation.title);
|
|
1769
|
+
try std.testing.expectEqual(@as(f32, 0), descriptors[0].state.presentation.font_size);
|
|
1770
|
+
try std.testing.expectEqual(platform.TrayFontWeight.regular, descriptors[0].state.presentation.font_weight);
|
|
1632
1771
|
try std.testing.expectEqualStrings("spend.png", descriptors[0].state.icon_path);
|
|
1633
1772
|
try std.testing.expectEqual(@as(usize, 1), descriptors[0].state.items.len);
|
|
1634
1773
|
try std.testing.expectEqual(@as(platform.TrayItemId, 3), descriptors[0].state.items[0].id);
|
|
@@ -1637,6 +1776,7 @@ test "TypeScript statusItems adapter validates and projects canonical descriptor
|
|
|
1637
1776
|
|
|
1638
1777
|
const WindowsAdapterTestCore = struct {
|
|
1639
1778
|
const Titlebar = enum { standard, hidden_inset, hidden_inset_tall, chromeless };
|
|
1779
|
+
const RestorePolicy = enum { clamp_to_visible_screen, center_on_primary };
|
|
1640
1780
|
const ClosePolicy = enum { quit, hide };
|
|
1641
1781
|
const Descriptor = struct {
|
|
1642
1782
|
label: []const u8,
|
|
@@ -1647,6 +1787,7 @@ const WindowsAdapterTestCore = struct {
|
|
|
1647
1787
|
x: ?f64,
|
|
1648
1788
|
y: ?f64,
|
|
1649
1789
|
resizable: bool,
|
|
1790
|
+
restorePolicy: RestorePolicy,
|
|
1650
1791
|
minWidth: f64,
|
|
1651
1792
|
minHeight: f64,
|
|
1652
1793
|
titlebar: Titlebar,
|
|
@@ -1660,11 +1801,11 @@ const WindowsAdapterTestCore = struct {
|
|
|
1660
1801
|
};
|
|
1661
1802
|
|
|
1662
1803
|
const descriptors = [_]Descriptor{
|
|
1663
|
-
.{ .label = "one", .canvasLabel = "one-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .chromeless, .transparent = true, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1664
|
-
.{ .label = "two", .canvasLabel = "two-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1665
|
-
.{ .label = "three", .canvasLabel = "three-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1666
|
-
.{ .label = "four", .canvasLabel = "four-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1667
|
-
.{ .label = "excess", .canvasLabel = "excess-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1804
|
+
.{ .label = "one", .canvasLabel = "one-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .center_on_primary, .minWidth = 0, .minHeight = 0, .titlebar = .chromeless, .transparent = true, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1805
|
+
.{ .label = "two", .canvasLabel = "two-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1806
|
+
.{ .label = "three", .canvasLabel = "three-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1807
|
+
.{ .label = "four", .canvasLabel = "four-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1808
|
+
.{ .label = "excess", .canvasLabel = "excess-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1668
1809
|
};
|
|
1669
1810
|
|
|
1670
1811
|
pub const Msg = union(enum) { noop };
|
|
@@ -1723,6 +1864,7 @@ test "TypeScript windows adapter keeps the declared prefix on overflow and proje
|
|
|
1723
1864
|
try std.testing.expectEqual(Adapter.App.max_ui_windows, descriptors.len);
|
|
1724
1865
|
try std.testing.expectEqualStrings("one", descriptors[0].label);
|
|
1725
1866
|
try std.testing.expectEqual(@import("app_manifest").WindowTitlebarStyle.chromeless, descriptors[0].titlebar);
|
|
1867
|
+
try std.testing.expectEqual(@import("app_manifest").WindowRestorePolicy.center_on_primary, descriptors[0].restore_policy);
|
|
1726
1868
|
try std.testing.expect(descriptors[0].transparent);
|
|
1727
1869
|
try std.testing.expectEqualStrings("four", descriptors[3].label);
|
|
1728
1870
|
}
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -316,6 +316,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
316
316
|
title_buffer: [platform.max_tray_title_bytes]u8 = undefined,
|
|
317
317
|
arena_buffer: [2048]u8 = undefined,
|
|
318
318
|
items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
319
|
+
segment_options: [platform.max_tray_items * platform.max_tray_segment_options]platform.TraySegmentOption = undefined,
|
|
320
|
+
chart_values: [platform.max_tray_items * platform.max_tray_chart_values]f32 = undefined,
|
|
319
321
|
};
|
|
320
322
|
|
|
321
323
|
/// Scratch for `status_items_fn`. The flat row store gives each
|
|
@@ -326,6 +328,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
326
328
|
title_buffers: [platform.max_status_items][platform.max_tray_title_bytes]u8 = undefined,
|
|
327
329
|
arena_buffer: [platform.max_status_items * 2048]u8 = undefined,
|
|
328
330
|
items: [platform.max_status_items * platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
331
|
+
segment_options: [platform.max_status_items * platform.max_tray_items * platform.max_tray_segment_options]platform.TraySegmentOption = undefined,
|
|
332
|
+
chart_values: [platform.max_status_items * platform.max_tray_items * platform.max_tray_chart_values]f32 = undefined,
|
|
329
333
|
};
|
|
330
334
|
|
|
331
335
|
const AppliedStatusItem = struct {
|
|
@@ -370,6 +374,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
370
374
|
x: ?f32 = null,
|
|
371
375
|
y: ?f32 = null,
|
|
372
376
|
resizable: bool = true,
|
|
377
|
+
/// Placement policy passed to the host when creating this
|
|
378
|
+
/// fresh, non-restored window. On macOS,
|
|
379
|
+
/// `.center_on_primary` centers a descriptor without an authored
|
|
380
|
+
/// origin on the primary screen; other hosts currently retain
|
|
381
|
+
/// their native default placement.
|
|
382
|
+
restore_policy: app_manifest.WindowRestorePolicy = .clamp_to_visible_screen,
|
|
373
383
|
/// Content min-size floor the WINDOW enforces (macOS
|
|
374
384
|
/// `contentMinSize`): the user's resize stops at the floor
|
|
375
385
|
/// instead of the layout clamping/clipping panes below
|
|
@@ -2880,6 +2890,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2880
2890
|
.x = descriptor.x,
|
|
2881
2891
|
.y = descriptor.y,
|
|
2882
2892
|
.resizable = descriptor.resizable,
|
|
2893
|
+
.restore_policy = descriptor.restore_policy,
|
|
2883
2894
|
.titlebar = descriptor.titlebar,
|
|
2884
2895
|
.transparent = descriptor.transparent,
|
|
2885
2896
|
.always_on_top = descriptor.always_on_top,
|
|
@@ -4836,7 +4847,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4836
4847
|
hasher.update(presentation.title);
|
|
4837
4848
|
hasher.update(std.mem.asBytes(&presentation.width));
|
|
4838
4849
|
hasher.update(std.mem.asBytes(&presentation.icon_opacity));
|
|
4839
|
-
hasher.update(
|
|
4850
|
+
hasher.update(std.mem.asBytes(&presentation.font_size));
|
|
4851
|
+
hasher.update(&.{ @intFromEnum(presentation.tone), @intFromBool(presentation.monospaced), @intFromEnum(presentation.font_weight) });
|
|
4840
4852
|
return hasher.final();
|
|
4841
4853
|
}
|
|
4842
4854
|
|
|
@@ -4853,6 +4865,33 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4853
4865
|
hasher.update(item.detail);
|
|
4854
4866
|
hasher.update(std.mem.asBytes(&item.key.len));
|
|
4855
4867
|
hasher.update(item.key);
|
|
4868
|
+
if (item.segmented) |segmented| {
|
|
4869
|
+
hasher.update(std.mem.asBytes(&segmented.options.len));
|
|
4870
|
+
for (segmented.options) |option| {
|
|
4871
|
+
hasher.update(std.mem.asBytes(&option.id));
|
|
4872
|
+
hasher.update(std.mem.asBytes(&option.label.len));
|
|
4873
|
+
hasher.update(option.label);
|
|
4874
|
+
hasher.update(std.mem.asBytes(&option.command.len));
|
|
4875
|
+
hasher.update(option.command);
|
|
4876
|
+
hasher.update(&.{ @intFromBool(option.selected), @intFromBool(option.enabled) });
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
if (item.metric) |metric| {
|
|
4880
|
+
for ([_][]const u8{ metric.primary_text, metric.secondary_text, metric.accessibility_label }) |field| {
|
|
4881
|
+
hasher.update(std.mem.asBytes(&field.len));
|
|
4882
|
+
hasher.update(field);
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
if (item.chart) |chart| {
|
|
4886
|
+
hasher.update(std.mem.asBytes(&chart.values.len));
|
|
4887
|
+
hasher.update(std.mem.sliceAsBytes(chart.values));
|
|
4888
|
+
hasher.update(std.mem.asBytes(&chart.min_value));
|
|
4889
|
+
hasher.update(std.mem.asBytes(&chart.max_value));
|
|
4890
|
+
for ([_][]const u8{ chart.leading_caption, chart.trailing_summary, chart.accessibility_label }) |field| {
|
|
4891
|
+
hasher.update(std.mem.asBytes(&field.len));
|
|
4892
|
+
hasher.update(field);
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4856
4895
|
hasher.update(&.{
|
|
4857
4896
|
@intFromBool(item.separator),
|
|
4858
4897
|
@intFromBool(item.enabled),
|
|
@@ -4540,11 +4540,74 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
|
|
|
4540
4540
|
|
|
4541
4541
|
// Unknown or malformed item ids are loud driver misuse, never a
|
|
4542
4542
|
// silent no-op or a fallback command dispatch.
|
|
4543
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 11"));
|
|
4543
4544
|
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 99"));
|
|
4544
4545
|
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action open"));
|
|
4545
4546
|
try std.testing.expectEqual(@as(u32, 1), app_state.model.selected_issue);
|
|
4546
4547
|
}
|
|
4547
4548
|
|
|
4549
|
+
const SegmentedAutomationModel = struct { selected: bool = true };
|
|
4550
|
+
const SegmentedAutomationMsg = union(enum) { enable, disable };
|
|
4551
|
+
const SegmentedAutomationApp = ui_app_model.UiApp(SegmentedAutomationModel, SegmentedAutomationMsg);
|
|
4552
|
+
|
|
4553
|
+
fn segmentedAutomationUpdate(model: *SegmentedAutomationModel, msg: SegmentedAutomationMsg) void {
|
|
4554
|
+
switch (msg) {
|
|
4555
|
+
.enable => model.selected = true,
|
|
4556
|
+
.disable => model.selected = false,
|
|
4557
|
+
}
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
fn segmentedAutomationView(ui: *SegmentedAutomationApp.Ui, _: *const SegmentedAutomationModel) SegmentedAutomationApp.Ui.Node {
|
|
4561
|
+
return ui.text(.{}, "Segments");
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
fn segmentedAutomationCommand(name: []const u8) ?SegmentedAutomationMsg {
|
|
4565
|
+
if (std.mem.eql(u8, name, "segment.enable")) return .enable;
|
|
4566
|
+
if (std.mem.eql(u8, name, "segment.disable")) return .disable;
|
|
4567
|
+
return null;
|
|
4568
|
+
}
|
|
4569
|
+
|
|
4570
|
+
fn segmentedAutomationStatusItem(model: *const SegmentedAutomationModel, scratch: *SegmentedAutomationApp.StatusItemScratch) SegmentedAutomationApp.StatusItemState {
|
|
4571
|
+
scratch.segment_options[0] = .{ .id = 20, .label = "On", .command = "segment.enable", .selected = model.selected, .enabled = false };
|
|
4572
|
+
scratch.segment_options[1] = .{ .id = 21, .label = "Off", .command = "segment.disable", .selected = !model.selected };
|
|
4573
|
+
scratch.items[0] = .{ .role = .segmented, .segmented = .{ .options = scratch.segment_options[0..2] } };
|
|
4574
|
+
return .{ .items = scratch.items[0..1] };
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
test "automation tray-action rejects disabled segmented options" {
|
|
4578
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
4579
|
+
defer harness.destroy(std.testing.allocator);
|
|
4580
|
+
harness.null_platform.gpu_surfaces = true;
|
|
4581
|
+
|
|
4582
|
+
const app_state = try std.testing.allocator.create(SegmentedAutomationApp);
|
|
4583
|
+
defer std.testing.allocator.destroy(app_state);
|
|
4584
|
+
app_state.* = SegmentedAutomationApp.init(std.heap.page_allocator, .{}, .{
|
|
4585
|
+
.name = "ui-app-tray-segmented-automation",
|
|
4586
|
+
.scene = counter_scene,
|
|
4587
|
+
.canvas_label = canvas_label,
|
|
4588
|
+
.update = segmentedAutomationUpdate,
|
|
4589
|
+
.view = segmentedAutomationView,
|
|
4590
|
+
.on_command = segmentedAutomationCommand,
|
|
4591
|
+
.status_item_fn = segmentedAutomationStatusItem,
|
|
4592
|
+
});
|
|
4593
|
+
defer app_state.deinit();
|
|
4594
|
+
const app = app_state.app();
|
|
4595
|
+
try harness.start(app);
|
|
4596
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
4597
|
+
.label = canvas_label,
|
|
4598
|
+
.size = geometry.SizeF.init(400, 300),
|
|
4599
|
+
.scale_factor = 1,
|
|
4600
|
+
.frame_index = 1,
|
|
4601
|
+
.timestamp_ns = 1_000_000,
|
|
4602
|
+
.nonblank = true,
|
|
4603
|
+
} });
|
|
4604
|
+
|
|
4605
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 20"));
|
|
4606
|
+
try std.testing.expect(app_state.model.selected);
|
|
4607
|
+
try harness.runtime.dispatchAutomationCommand(app, "tray-action 21");
|
|
4608
|
+
try std.testing.expect(!app_state.model.selected);
|
|
4609
|
+
}
|
|
4610
|
+
|
|
4548
4611
|
const TaskModel = struct {
|
|
4549
4612
|
completed: u32 = 0,
|
|
4550
4613
|
deleted: u32 = 0,
|
|
@@ -21,6 +21,7 @@ const settings_window_label = "settings";
|
|
|
21
21
|
const PanelModel = struct {
|
|
22
22
|
settings_open: bool = false,
|
|
23
23
|
position_settings: bool = true,
|
|
24
|
+
center_settings: bool = false,
|
|
24
25
|
transparent_settings: bool = false,
|
|
25
26
|
bumps: u32 = 0,
|
|
26
27
|
user_closes: u32 = 0,
|
|
@@ -63,6 +64,7 @@ fn panelWindows(model: *const PanelModel, scratch: *PanelApp.WindowsScratch) []c
|
|
|
63
64
|
.height = 240,
|
|
64
65
|
.x = if (model.position_settings) 84 else null,
|
|
65
66
|
.y = if (model.position_settings) 126 else null,
|
|
67
|
+
.restore_policy = if (model.center_settings) .center_on_primary else .clamp_to_visible_screen,
|
|
66
68
|
.min_width = 280,
|
|
67
69
|
.min_height = 200,
|
|
68
70
|
.titlebar = if (model.transparent_settings) .chromeless else .standard,
|
|
@@ -245,6 +247,27 @@ test "a Msg declares the settings window, its canvas installs, and automation dr
|
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
249
|
|
|
250
|
+
test "a windows_fn restore policy reaches fresh WindowOptions" {
|
|
251
|
+
const fixture = try Fixture.create();
|
|
252
|
+
defer fixture.destroy();
|
|
253
|
+
|
|
254
|
+
fixture.app_state.model.position_settings = false;
|
|
255
|
+
fixture.app_state.model.center_settings = true;
|
|
256
|
+
try fixture.clickSettingsButton();
|
|
257
|
+
const info = fixture.settingsWindowInfo() orelse return error.TestUnexpectedResult;
|
|
258
|
+
|
|
259
|
+
for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count], 0..) |window, index| {
|
|
260
|
+
if (window.id != info.id) continue;
|
|
261
|
+
// Model-declared windows deliberately set restore_state=false. With
|
|
262
|
+
// no authored origin this remains a fresh/default placement while
|
|
263
|
+
// preserving the descriptor's policy at WindowOptions.
|
|
264
|
+
try std.testing.expectEqual(support.platform.WindowInitialPlacement.default, fixture.harness.null_platform.window_placement[index]);
|
|
265
|
+
try std.testing.expectEqual(support.platform.WindowRestorePolicy.center_on_primary, fixture.harness.null_platform.window_restore_policy[index]);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
return error.WindowNotFound;
|
|
269
|
+
}
|
|
270
|
+
|
|
248
271
|
test "a transparent descriptor selects premultiplied canvas alpha and an alpha-zero clear" {
|
|
249
272
|
const fixture = try Fixture.create();
|
|
250
273
|
defer fixture.destroy();
|