1use serde::{Deserialize, Serialize};
37use serde_json::Value;
38
39pub use kernel_api::{self, SolidOp, TriMesh};
40
41pub const API_VERSION: &str = "0.1";
44
45pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
48
49pub fn contract_satisfies(min: &str) -> bool {
53 let numbers = |v: &str| -> Option<Vec<u64>> {
54 v.trim()
55 .trim_start_matches("printcad:workbench@")
56 .split('.')
57 .map(|part| part.trim().parse().ok())
58 .collect()
59 };
60 match (numbers(min), numbers(CONTRACT_VERSION)) {
61 (Some(min), Some(ours)) => {
62 let ours = ours.iter().copied().chain(std::iter::repeat(0));
63 for (want, have) in min.iter().zip(ours) {
64 if have != *want {
65 return have > *want;
66 }
67 }
68 true
69 }
70 _ => false,
71 }
72}
73
74pub const WIT: &str = include_str!("../wit/workbench.wit");
77
78pub fn api_compatible(api: &str) -> bool {
80 let major = |v: &str| {
81 let mut parts = v.split('.');
82 let first = parts.next().unwrap_or("");
83 if first == "0" {
85 format!("0.{}", parts.next().unwrap_or(""))
86 } else {
87 first.to_string()
88 }
89 };
90 let api = api.trim().trim_start_matches("printcad:workbench@");
91 major(api) == major(API_VERSION)
92}
93
94#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
98pub struct Manifest {
99 pub id: String,
102 pub name: String,
103 pub version: String,
105 pub api: String,
107 #[serde(default, skip_serializing_if = "Option::is_none")]
112 pub min_contract: Option<String>,
113 #[serde(default)]
114 pub description: String,
115 #[serde(default)]
117 pub feature_kinds: Vec<String>,
118 #[serde(default)]
119 pub capabilities: Capabilities,
120 #[serde(default = "default_memory_mb")]
122 pub memory_mb: u32,
123}
124
125fn default_memory_mb() -> u32 {
126 1024
127}
128
129impl Default for Manifest {
130 fn default() -> Self {
131 Self {
132 id: String::new(),
133 name: String::new(),
134 version: String::new(),
135 api: format!("printcad:workbench@{API_VERSION}"),
136 min_contract: None,
137 description: String::new(),
138 feature_kinds: Vec::new(),
139 capabilities: Capabilities::default(),
140 memory_mb: default_memory_mb(),
141 }
142 }
143}
144
145#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
147pub struct Capabilities {
148 #[serde(default)]
150 pub save_dialog: bool,
151 #[serde(default)]
153 pub open_dialog: bool,
154 #[serde(default)]
156 pub helper: bool,
157 #[serde(default)]
159 pub network: bool,
160}
161
162impl Capabilities {
163 pub fn and(&self, other: &Capabilities) -> Capabilities {
165 Capabilities {
166 save_dialog: self.save_dialog && other.save_dialog,
167 open_dialog: self.open_dialog && other.open_dialog,
168 helper: self.helper && other.helper,
169 network: self.network && other.network,
170 }
171 }
172
173 pub fn names(&self) -> Vec<&'static str> {
175 let mut out = Vec::new();
176 if self.save_dialog {
177 out.push("save_dialog");
178 }
179 if self.open_dialog {
180 out.push("open_dialog");
181 }
182 if self.helper {
183 out.push("helper");
184 }
185 if self.network {
186 out.push("network");
187 }
188 out
189 }
190}
191
192#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
196pub struct Registration {
197 pub label: String,
198 #[serde(default)]
199 pub description: String,
200 #[serde(default)]
202 pub icon: String,
203 #[serde(default)]
205 pub modal: bool,
206 #[serde(default)]
207 pub tools: Vec<Tool>,
208 #[serde(default)]
210 pub actions: Vec<Action>,
211 #[serde(default)]
214 pub commands: Vec<Command>,
215 #[serde(default)]
218 pub length_keys: Vec<String>,
219 #[serde(default)]
224 pub bought_kinds: Vec<String>,
225 #[serde(default)]
230 pub radial: Vec<String>,
231}
232
233#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
234#[serde(rename_all = "snake_case")]
235pub enum ToolBehavior {
236 #[default]
238 Radio,
239 Check,
241 Action,
243}
244
245#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
246pub struct Tool {
247 pub id: String,
248 pub label: String,
249 #[serde(default)]
250 pub icon: String,
251 #[serde(default)]
252 pub behavior: ToolBehavior,
253 #[serde(default)]
254 pub group: Option<String>,
255 #[serde(default = "one")]
257 pub row: u8,
258 #[serde(default)]
259 pub category: Option<String>,
260 #[serde(default)]
262 pub shortcuts: Vec<String>,
263}
264
265fn one() -> u8 {
266 1
267}
268
269impl Default for Tool {
270 fn default() -> Self {
271 Self {
272 id: String::new(),
273 label: String::new(),
274 icon: String::new(),
275 behavior: ToolBehavior::default(),
276 group: None,
277 row: one(),
278 category: None,
279 shortcuts: Vec::new(),
280 }
281 }
282}
283
284#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
285pub struct Action {
286 pub id: String,
287 pub label: String,
288 #[serde(default)]
289 pub shortcuts: Vec<String>,
290}
291
292#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
293#[serde(rename_all = "snake_case")]
294pub enum ParamKind {
295 Number,
296 Integer,
297 Bool,
298 String,
299 Id,
300 List,
301 #[default]
302 Any,
303}
304
305#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
306pub struct Param {
307 pub name: String,
308 #[serde(default)]
309 pub kind: ParamKind,
310 #[serde(default)]
311 pub required: bool,
312 #[serde(default)]
313 pub doc: String,
314}
315
316#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
317pub struct Command {
318 pub id: String,
319 pub summary: String,
320 #[serde(default)]
321 pub params: Vec<Param>,
322 #[serde(default)]
323 pub returns: String,
324 #[serde(default)]
326 pub read_only: bool,
327 #[serde(default)]
330 pub notes: Vec<String>,
331 #[serde(default)]
333 pub examples: Vec<Example>,
334 #[serde(default)]
336 pub see_also: Vec<String>,
337}
338
339#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
341pub struct Example {
342 pub title: String,
344 pub script: String,
347}
348
349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
353pub struct Node {
354 pub id: String,
355 pub kind: String,
356 pub name: String,
357 #[serde(default)]
358 pub body: Option<String>,
359 pub data: Value,
362 #[serde(default)]
363 pub visible: bool,
364 #[serde(default)]
366 pub made_by: Option<String>,
367 #[serde(default)]
369 pub deps: Vec<String>,
370 #[serde(default)]
372 pub seq: u64,
373}
374
375#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
376pub struct Body {
377 pub id: String,
378 pub name: String,
379 pub hidden: bool,
380 pub placement: [f64; 16],
382 #[serde(default)]
384 pub bounds: Option<([f32; 3], [f32; 3])>,
385}
386
387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
389pub struct Parameter {
390 pub key: String,
392 #[serde(default)]
394 pub name: Option<String>,
395 pub label: String,
396 #[serde(default)]
397 pub dim: Dim,
398 pub pointer: String,
400 #[serde(default = "unit_scale")]
402 pub scale: f64,
403 #[serde(default)]
404 pub integer: bool,
405}
406
407fn unit_scale() -> f64 {
408 1.0
409}
410
411impl Default for Parameter {
412 fn default() -> Self {
413 Self {
414 key: String::new(),
415 name: None,
416 label: String::new(),
417 dim: Dim::default(),
418 pointer: String::new(),
419 scale: unit_scale(),
420 integer: false,
421 }
422 }
423}
424
425#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
426#[serde(rename_all = "snake_case")]
427pub enum Dim {
428 #[default]
429 Length,
430 Angle,
431 Number,
432}
433
434#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
436pub struct FeatureInfo {
437 pub icon: String,
438 pub kind_label: String,
439 #[serde(default)]
440 pub family_label: String,
441 #[serde(default)]
443 pub builds_solid: bool,
444 #[serde(default, skip_serializing_if = "Option::is_none")]
448 pub status: Option<FeatureStatus>,
449}
450
451#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
453pub struct FeatureStatus {
454 pub state: FeatureState,
455 #[serde(default)]
458 pub job: Option<u64>,
459 #[serde(default)]
461 pub fraction: Option<f32>,
462 #[serde(default)]
464 pub note: Option<String>,
465}
466
467#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
468#[serde(rename_all = "snake_case")]
469pub enum FeatureState {
470 #[default]
471 NotRun,
472 Running,
473 Done,
474 Warnings,
475 Failed,
476 OutOfDate,
477}
478
479#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
484pub struct RebuildRequest {
485 pub bodies: Vec<BodyHistory>,
486}
487
488#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
489pub struct BodyHistory {
490 pub body: String,
491 pub features: Vec<Node>,
492}
493
494#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
496pub struct Rebuild {
497 pub body: String,
498 pub plan: Plan,
499 #[serde(default, skip_serializing_if = "Vec::is_empty")]
501 pub threads: Vec<CosmeticThread>,
502}
503
504#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
511pub struct CosmeticThread {
512 pub feature: String,
514 pub point: [f64; 3],
517 #[serde(default)]
520 pub name: Option<u64>,
521 pub pitch: f64,
523 #[serde(default)]
526 pub length: f64,
527 #[serde(default)]
528 pub left_handed: bool,
529 #[serde(default, skip_serializing_if = "Option::is_none")]
532 pub designation: Option<String>,
533}
534
535#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
541#[serde(tag = "type", rename_all = "snake_case")]
542pub enum Plan {
543 Ops {
545 ops: Vec<SolidOp>,
546 op_features: Vec<String>,
547 },
548 #[default]
550 Empty,
551 Error {
553 #[serde(default)]
554 feature: Option<String>,
555 message: String,
556 },
557}
558
559#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
564pub struct Input {
565 pub event: Event,
566 #[serde(default)]
568 pub tool: Option<String>,
569 #[serde(default)]
570 pub pointer: Pointer,
571}
572
573#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
575pub struct Pointer {
576 #[serde(default)]
578 pub position: Option<[f32; 2]>,
579 #[serde(default)]
581 pub ray: Option<([f32; 3], [f32; 3])>,
582 #[serde(default)]
584 pub world: Option<[f32; 3]>,
585 #[serde(default)]
586 pub body: Option<String>,
587 #[serde(default)]
589 pub selected_body: Option<String>,
590 #[serde(default)]
591 pub face: Option<FaceRef>,
592 #[serde(default)]
594 pub faces: Vec<FaceRef>,
595 #[serde(default)]
596 pub edges: Vec<EdgeRef>,
597 #[serde(default)]
599 pub active_feature: Option<String>,
600 #[serde(default)]
601 pub ctrl: bool,
602 #[serde(default, skip_serializing_if = "Option::is_none")]
605 pub hover_face: Option<FaceRef>,
606 #[serde(default, skip_serializing_if = "Option::is_none")]
608 pub hover_edge: Option<EdgeRef>,
609 #[serde(default, skip_serializing_if = "Option::is_none")]
612 pub vertex: Option<VertexRef>,
613}
614
615#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
617pub struct VertexRef {
618 pub body: String,
619 pub point: [f32; 3],
620}
621
622#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
623pub struct FaceRef {
624 pub point: [f32; 3],
625 pub normal: [f32; 3],
626 #[serde(default)]
628 pub surface: Option<kernel_api::FaceSurface>,
629 #[serde(default, skip_serializing_if = "Option::is_none")]
632 pub name: Option<u64>,
633}
634
635#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
636pub struct EdgeRef {
637 pub body: String,
638 pub point: [f32; 3],
639 pub direction: [f32; 3],
640 pub length: f32,
641 #[serde(default)]
644 pub circle: Option<EdgeCircle>,
645 #[serde(default, skip_serializing_if = "Option::is_none")]
648 pub faces: Option<[u64; 2]>,
649}
650
651#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
653pub struct EdgeCircle {
654 pub center: [f32; 3],
655 pub normal: [f32; 3],
656 pub radius: f32,
657}
658
659#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
660#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
661#[serde(rename_all = "snake_case")]
662pub enum Button {
663 Left,
664 Middle,
665 Right,
666 Other,
667}
668
669#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
670#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
671#[serde(tag = "type", rename_all = "snake_case")]
672pub enum Event {
673 Press {
674 button: Button,
675 },
676 Release {
677 button: Button,
678 },
679 Move,
680 Key {
682 key: String,
683 down: bool,
684 },
685 ToolActivated,
687 Action {
689 id: String,
690 },
691 Activated,
692 Deactivated,
693 ValuesMoved {
695 features: Vec<String>,
696 },
697 JobFinished {
699 job: u64,
700 result: Result<String, String>,
701 },
702 EditFeature {
706 feature: String,
707 },
708 FeatureMoved {
714 feature: String,
715 target: String,
716 before: bool,
717 },
718 FileOpened {
721 id: String,
722 files: Vec<OpenedFile>,
723 },
724}
725
726#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
729pub struct OpenedFile {
730 pub name: String,
731 pub contents: Vec<u8>,
732}
733
734#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
737pub struct FileKind {
738 pub label: String,
739 pub extensions: Vec<String>,
740}
741
742#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
745pub struct FileToWrite {
746 pub name: String,
747 pub contents: Vec<u8>,
748}
749
750#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
757pub struct Frame {
758 #[serde(default)]
759 pub hud: Hud,
760 #[serde(default)]
761 pub status: Status,
762 #[serde(default)]
764 pub task: Option<Task>,
765 #[serde(default)]
766 pub panel: Vec<Widget>,
767 #[serde(default)]
769 pub editing: Option<String>,
770 #[serde(default)]
772 pub locks_view: bool,
773 #[serde(default)]
775 pub numeric_input: bool,
776 #[serde(default)]
778 pub toggled: Vec<String>,
779 #[serde(default)]
781 pub disabled: Vec<String>,
782 #[serde(default)]
783 pub lines: Vec<Polyline>,
784 #[serde(default)]
785 pub marks: Vec<Mark>,
786 #[serde(default)]
787 pub labels: Vec<Label>,
788 #[serde(default)]
789 pub meshes: Vec<Mesh>,
790 #[serde(default, skip_serializing_if = "Vec::is_empty")]
793 pub kept: Vec<KeptMesh>,
794 #[serde(default, skip_serializing_if = "Vec::is_empty")]
796 pub regions: Vec<Region>,
797 #[serde(default, skip_serializing_if = "Vec::is_empty")]
801 pub transport: Vec<Widget>,
802 #[serde(default, skip_serializing_if = "Option::is_none")]
806 pub card: Option<FloatingCard>,
807 #[serde(default)]
811 pub animating: bool,
812}
813
814#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
829#[serde(default)]
830pub struct FloatingCard {
831 pub id: String,
834 pub title: String,
835 pub icon: Option<String>,
836 pub at: Option<[f32; 3]>,
838 pub screen: Option<[f32; 2]>,
841 pub widgets: Vec<Widget>,
842 pub focus: Option<String>,
845 pub ok: String,
847 pub refusal: Option<String>,
850 pub hint: Option<String>,
853 pub ok_only: bool,
856}
857
858#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
859pub struct Hud {
860 #[serde(default)]
862 pub tool: Option<ToolHint>,
863 #[serde(default)]
865 pub badge: Option<(Rgb, String)>,
866 #[serde(default)]
867 pub legend: Vec<(Rgb, String)>,
868 #[serde(default)]
870 pub footer: Vec<String>,
871}
872
873#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
874pub struct ToolHint {
875 pub icon: String,
876 pub name: String,
877 pub prompt: String,
878 #[serde(default)]
880 pub keys: Vec<(String, String)>,
881}
882
883#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
884pub struct Status {
885 #[serde(default)]
886 pub state: Option<(Rgb, String)>,
887 #[serde(default)]
888 pub selection: Option<String>,
889 #[serde(default)]
890 pub mode: Option<String>,
891}
892
893#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
894pub struct Task {
895 pub title: String,
896 #[serde(default)]
897 pub icon: String,
898 #[serde(default)]
900 pub confirmable: bool,
901}
902
903pub type Rgb = [f32; 3];
905
906#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
909pub struct Polyline {
910 pub points: Vec<[f32; 3]>,
911 pub color: Rgb,
912 #[serde(default = "one_px")]
913 pub width: f32,
914 #[serde(default)]
915 pub dashed: bool,
916 #[serde(default)]
917 pub closed: bool,
918}
919
920fn one_px() -> f32 {
921 1.5
922}
923
924impl Default for Polyline {
925 fn default() -> Self {
926 Self {
927 points: Vec::new(),
928 color: [1.0; 3],
929 width: one_px(),
930 dashed: false,
931 closed: false,
932 }
933 }
934}
935
936#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
937pub struct Mark {
938 pub at: [f32; 3],
939 pub color: Rgb,
940 pub kind: MarkKind,
941}
942
943#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
949#[serde(tag = "type", rename_all = "snake_case")]
950pub enum MarkKind {
951 Dot { radius: f32 },
952 Cross { size: f32 },
953 Icon { name: String, size: f32 },
954}
955
956impl Default for MarkKind {
957 fn default() -> Self {
958 MarkKind::Dot { radius: 4.0 }
959 }
960}
961
962#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
963pub struct Label {
964 pub at: [f32; 3],
965 pub text: String,
966 pub color: Rgb,
967 #[serde(default = "label_size")]
968 pub size: f32,
969 #[serde(default)]
971 pub pill: bool,
972 #[serde(default)]
973 pub mono: bool,
974}
975
976fn label_size() -> f32 {
977 12.0
978}
979
980impl Default for Label {
981 fn default() -> Self {
982 Self {
983 at: [0.0; 3],
984 text: String::new(),
985 color: [1.0; 3],
986 size: label_size(),
987 pill: false,
988 mono: false,
989 }
990 }
991}
992
993#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
995pub struct Mesh {
996 pub positions: Vec<[f32; 3]>,
997 pub indices: Vec<u32>,
998 pub color: Rgb,
999 #[serde(default)]
1000 pub wireframe: bool,
1001 #[serde(default = "opaque")]
1002 pub opacity: f32,
1003 #[serde(default)]
1005 pub on_top: bool,
1006 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1009 pub colors: Vec<Rgb>,
1010}
1011
1012fn opaque() -> f32 {
1013 1.0
1014}
1015
1016impl Default for Mesh {
1017 fn default() -> Self {
1018 Self {
1019 positions: Vec::new(),
1020 indices: Vec::new(),
1021 color: [1.0; 3],
1022 wireframe: false,
1023 opacity: opaque(),
1024 on_top: false,
1025 colors: Vec::new(),
1026 }
1027 }
1028}
1029
1030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1032pub struct KeptMesh {
1033 pub handle: u64,
1034 pub color: Rgb,
1036 #[serde(default)]
1037 pub wireframe: bool,
1038 #[serde(default = "opaque")]
1039 pub opacity: f32,
1040 #[serde(default)]
1041 pub on_top: bool,
1042}
1043
1044impl Default for KeptMesh {
1045 fn default() -> Self {
1046 Self {
1047 handle: 0,
1048 color: [1.0; 3],
1049 wireframe: false,
1050 opacity: opaque(),
1051 on_top: false,
1052 }
1053 }
1054}
1055
1056#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1059pub struct Region {
1060 pub outline: Vec<[f32; 3]>,
1061 #[serde(default)]
1062 pub holes: Vec<Vec<[f32; 3]>>,
1063 pub color: Rgb,
1064 #[serde(default = "region_opacity")]
1066 pub opacity: f32,
1067 #[serde(default)]
1069 pub hatch: Option<f32>,
1070 #[serde(default = "hatch_angle")]
1072 pub hatch_angle: f32,
1073 #[serde(default)]
1075 pub on_top: bool,
1076}
1077
1078fn region_opacity() -> f32 {
1079 0.35
1080}
1081
1082fn hatch_angle() -> f32 {
1083 45.0
1084}
1085
1086impl Default for Region {
1087 fn default() -> Self {
1088 Self {
1089 outline: Vec::new(),
1090 holes: Vec::new(),
1091 color: [1.0; 3],
1092 opacity: region_opacity(),
1093 hatch: None,
1094 hatch_angle: hatch_angle(),
1095 on_top: false,
1096 }
1097 }
1098}
1099
1100#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1109#[serde(tag = "type", rename_all = "snake_case")]
1110pub enum Widget {
1111 Heading {
1112 text: String,
1113 },
1114 Text {
1115 text: String,
1116 #[serde(default)]
1117 mono: bool,
1118 },
1119 Note {
1120 #[serde(default)]
1121 kind: NoteKind,
1122 #[serde(default)]
1123 title: Option<String>,
1124 text: String,
1125 },
1126 Number {
1130 id: String,
1131 label: String,
1132 value: f64,
1133 #[serde(default)]
1134 dim: Dim,
1135 #[serde(default)]
1136 bind: Option<Bind>,
1137 #[serde(default)]
1138 min: Option<f64>,
1139 #[serde(default)]
1140 max: Option<f64>,
1141 #[serde(default = "two")]
1142 decimals: usize,
1143 #[serde(default)]
1144 error: Option<String>,
1145 },
1146 Choice {
1147 id: String,
1148 label: String,
1149 options: Vec<String>,
1150 selected: usize,
1151 },
1152 Toggle {
1153 id: String,
1154 label: String,
1155 on: bool,
1156 },
1157 TextField {
1158 id: String,
1159 label: String,
1160 value: String,
1161 },
1162 Button {
1163 id: String,
1164 label: String,
1165 #[serde(default)]
1166 style: ButtonStyle,
1167 #[serde(default = "yes")]
1168 enabled: bool,
1169 },
1170 Pick {
1174 id: String,
1175 label: String,
1176 #[serde(default)]
1178 value: Option<String>,
1179 #[serde(default)]
1180 armed: bool,
1181 },
1182 List {
1184 id: String,
1185 items: Vec<ListItem>,
1186 #[serde(default)]
1187 selected: Option<usize>,
1188 },
1189 Table {
1193 id: String,
1194 columns: Vec<String>,
1195 rows: Vec<Vec<String>>,
1196 #[serde(default)]
1197 selected: Option<usize>,
1198 #[serde(default)]
1200 editable: Vec<bool>,
1201 },
1202 Group {
1203 title: String,
1204 #[serde(default = "yes")]
1205 open: bool,
1206 children: Vec<Widget>,
1207 },
1208 Progress {
1209 label: String,
1210 #[serde(default)]
1212 fraction: Option<f32>,
1213 #[serde(default)]
1215 job: Option<u64>,
1216 },
1217 Separator,
1218 Diagram {
1226 id: String,
1227 width: f32,
1228 height: f32,
1229 #[serde(default)]
1230 shapes: Vec<DiagramShape>,
1231 #[serde(default)]
1232 dimensions: Vec<Dimension>,
1233 #[serde(default)]
1234 callouts: Vec<Callout>,
1235 },
1236 Header {
1238 icon: String,
1239 title: String,
1240 },
1241 Value {
1243 label: String,
1244 value: String,
1245 #[serde(default)]
1246 mono: bool,
1247 },
1248 Row {
1251 children: Vec<Widget>,
1252 },
1253 Hinted {
1255 hint: String,
1256 widget: Box<Widget>,
1257 },
1258 HintedFigure {
1261 hint: String,
1262 figure: Box<Widget>,
1263 widget: Box<Widget>,
1264 },
1265 Slider {
1268 id: String,
1269 label: String,
1270 value: f64,
1271 min: f64,
1272 max: f64,
1273 #[serde(default)]
1275 step: Option<f64>,
1276 #[serde(default = "two")]
1277 decimals: usize,
1278 #[serde(default = "yes")]
1280 show_value: bool,
1281 },
1282 Sheet {
1285 id: String,
1286 columns: Vec<String>,
1287 rows: Vec<Vec<Cell>>,
1288 },
1289 Section(PanelSection),
1291 Item(Item),
1293 Items(ItemList),
1295 Filter(FilterField),
1297 Status(StatusLine),
1299 Stack(Stack),
1301 Flow(Flow),
1303 Fill(Fill),
1305 Fields(Fields),
1307 Inline(Inline),
1309 PickChip(PickChip),
1311 Entry(Entry),
1313 TaskHeader(TaskHeader),
1315 Quantity(Quantity),
1318 Check(Check),
1320 Select(Select),
1322 Grid(FieldGrid),
1324 Alert(Alert),
1326 Card(Card),
1328 Caption(Caption),
1330 Gap(Gap),
1332 Plot(Plot),
1334 Swatches(Swatches),
1336 Color(ColorField),
1338 Range(Range),
1340 RowButton(RowButton),
1342 Selectable(Selectable),
1344 Gallery(Gallery),
1346 Settings(SettingsGroup),
1349 Cells(Cells),
1352 Action(PanelAction),
1354 Toggles(Toggles),
1357}
1358
1359macro_rules! widget_children {
1362 ($widget:expr, $deref:ident, $iter:ident $(, $mut:ident)?) => {{
1363 let mut out = Vec::new();
1364 match $widget {
1365 Widget::Group { children, .. }
1366 | Widget::Row { children }
1367 | Widget::Section(PanelSection { children, .. })
1368 | Widget::Stack(Stack { children, .. })
1369 | Widget::Flow(Flow { children, .. })
1370 | Widget::Fields(Fields { children, .. })
1371 | Widget::Grid(FieldGrid { children, .. })
1372 | Widget::Card(Card { children, .. })
1373 | Widget::Cells(Cells { children, .. })
1374 | Widget::Settings(SettingsGroup { children, .. }) => out.extend(children),
1375 Widget::Hinted { widget, .. } => out.push(&$($mut)? **widget),
1376 Widget::HintedFigure { figure, widget, .. } => {
1377 out.push(&$($mut)? **figure);
1378 out.push(&$($mut)? **widget);
1379 }
1380 Widget::Fill(Fill { child }) | Widget::Inline(Inline { child }) => {
1381 out.push(&$($mut)? **child)
1382 }
1383 Widget::Item(item) => out.extend(item.field.$deref()),
1384 Widget::Items(list) => {
1385 for item in list.items.$iter() {
1386 out.extend(item.field.$deref());
1387 }
1388 }
1389 Widget::Heading { .. }
1390 | Widget::Text { .. }
1391 | Widget::Note { .. }
1392 | Widget::Number { .. }
1393 | Widget::Choice { .. }
1394 | Widget::Toggle { .. }
1395 | Widget::TextField { .. }
1396 | Widget::Button { .. }
1397 | Widget::Pick { .. }
1398 | Widget::List { .. }
1399 | Widget::Table { .. }
1400 | Widget::Progress { .. }
1401 | Widget::Separator
1402 | Widget::Diagram { .. }
1403 | Widget::Header { .. }
1404 | Widget::Value { .. }
1405 | Widget::Slider { .. }
1406 | Widget::Sheet { .. }
1407 | Widget::Filter(_)
1408 | Widget::Status(_)
1409 | Widget::PickChip(_)
1410 | Widget::Entry(_)
1411 | Widget::TaskHeader(_)
1412 | Widget::Quantity(_)
1413 | Widget::Check(_)
1414 | Widget::Select(_)
1415 | Widget::Alert(_)
1416 | Widget::Caption(_)
1417 | Widget::Gap(_)
1418 | Widget::Plot(_)
1419 | Widget::Swatches(_)
1420 | Widget::Color(_)
1421 | Widget::Range(_)
1422 | Widget::RowButton(_)
1423 | Widget::Selectable(_)
1424 | Widget::Gallery(_)
1425 | Widget::Action(_)
1426 | Widget::Toggles(_) => {}
1427 }
1428 out
1429 }};
1430}
1431
1432impl Widget {
1433 pub fn children(&self) -> Vec<&Widget> {
1437 widget_children!(self, as_deref, iter)
1438 }
1439
1440 pub fn children_mut(&mut self) -> Vec<&mut Widget> {
1442 widget_children!(self, as_deref_mut, iter_mut, mut)
1443 }
1444
1445 pub fn walk<'a>(&'a self, visit: &mut impl FnMut(&'a Widget)) {
1448 visit(self);
1449 for child in self.children() {
1450 child.walk(visit);
1451 }
1452 }
1453
1454 pub fn walk_mut(&mut self, visit: &mut impl FnMut(&mut Widget)) {
1456 visit(self);
1457 for child in self.children_mut() {
1458 child.walk_mut(visit);
1459 }
1460 }
1461
1462 pub fn id(&self) -> Option<&str> {
1464 let id = match self {
1465 Widget::Number { id, .. }
1466 | Widget::Choice { id, .. }
1467 | Widget::Toggle { id, .. }
1468 | Widget::TextField { id, .. }
1469 | Widget::Button { id, .. }
1470 | Widget::Pick { id, .. }
1471 | Widget::List { id, .. }
1472 | Widget::Table { id, .. }
1473 | Widget::Diagram { id, .. }
1474 | Widget::Slider { id, .. }
1475 | Widget::Sheet { id, .. }
1476 | Widget::Section(PanelSection { id, .. })
1477 | Widget::Item(Item { id, .. })
1478 | Widget::Items(ItemList { id, .. })
1479 | Widget::Filter(FilterField { id, .. })
1480 | Widget::PickChip(PickChip { id, .. })
1481 | Widget::Entry(Entry { id, .. })
1482 | Widget::Quantity(Quantity { id, .. })
1483 | Widget::Check(Check { id, .. })
1484 | Widget::Select(Select { id, .. })
1485 | Widget::Swatches(Swatches { id, .. })
1486 | Widget::Color(ColorField { id, .. })
1487 | Widget::Range(Range { id, .. })
1488 | Widget::RowButton(RowButton { id, .. })
1489 | Widget::Selectable(Selectable { id, .. })
1490 | Widget::Gallery(Gallery { id, .. })
1491 | Widget::Action(PanelAction { id, .. })
1492 | Widget::Toggles(Toggles { id, .. }) => id,
1493 Widget::Alert(Alert { id, .. }) => id.as_ref()?,
1494 _ => return None,
1495 };
1496 (!id.is_empty()).then_some(id.as_str())
1497 }
1498
1499 pub fn field_label(&self) -> Option<&str> {
1502 let label = match self {
1503 Widget::Number { label, .. }
1504 | Widget::Choice { label, .. }
1505 | Widget::TextField { label, .. }
1506 | Widget::Pick { label, .. }
1507 | Widget::Value { label, .. }
1508 | Widget::Slider { label, .. }
1509 | Widget::PickChip(PickChip { label, .. })
1510 | Widget::Entry(Entry { label, .. })
1511 | Widget::Quantity(Quantity { label, .. })
1512 | Widget::Check(Check { label, .. })
1513 | Widget::Select(Select { label, .. })
1514 | Widget::Range(Range { label, .. })
1515 | Widget::Color(ColorField { label, .. })
1516 | Widget::Toggles(Toggles { label, .. })
1517 | Widget::Flow(Flow { label, .. }) => label,
1518 _ => return None,
1519 };
1520 (!label.is_empty()).then_some(label.as_str())
1521 }
1522}
1523
1524pub fn retain_widgets(widgets: &mut Vec<Widget>, keep: &mut impl FnMut(&Widget) -> bool) {
1528 widgets.retain(|w| keep(w));
1529 for widget in widgets {
1530 retain_within(widget, keep);
1531 }
1532}
1533
1534fn retain_within(widget: &mut Widget, keep: &mut impl FnMut(&Widget) -> bool) {
1535 match widget {
1536 Widget::Group { children, .. }
1537 | Widget::Row { children }
1538 | Widget::Section(PanelSection { children, .. })
1539 | Widget::Stack(Stack { children, .. })
1540 | Widget::Flow(Flow { children, .. })
1541 | Widget::Fields(Fields { children, .. })
1542 | Widget::Grid(FieldGrid { children, .. })
1543 | Widget::Card(Card { children, .. })
1544 | Widget::Cells(Cells { children, .. })
1545 | Widget::Settings(SettingsGroup { children, .. }) => retain_widgets(children, keep),
1546 other => {
1547 for child in other.children_mut() {
1548 retain_within(child, keep);
1549 }
1550 }
1551 }
1552}
1553
1554pub fn walk_widgets(widgets: &[Widget]) -> Vec<&Widget> {
1556 let mut all = Vec::new();
1557 for widget in widgets {
1558 widget.walk(&mut |w| all.push(w));
1559 }
1560 all
1561}
1562
1563#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
1571#[serde(rename_all = "snake_case")]
1572pub enum Tone {
1573 #[default]
1574 Neutral,
1575 Good,
1576 Warning,
1577 Bad,
1578 Info,
1579 Accent,
1581 Muted,
1583}
1584
1585#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1591pub struct PanelAction {
1592 pub id: String,
1593 #[serde(default)]
1594 pub icon: Option<String>,
1595 #[serde(default)]
1597 pub label: String,
1598 #[serde(default)]
1600 pub hint: String,
1601 #[serde(default)]
1603 pub separated: bool,
1604}
1605
1606#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1612#[serde(default)]
1613pub struct Toggles {
1614 pub id: String,
1615 pub label: String,
1616 pub buttons: Vec<ToggleButton>,
1617}
1618
1619#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1621#[serde(default)]
1622pub struct ToggleButton {
1623 pub id: String,
1624 pub icon: String,
1626 pub hint: String,
1628 pub on: bool,
1629 pub disabled: bool,
1631}
1632
1633#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1638#[serde(default)]
1639pub struct PanelSection {
1640 pub id: String,
1642 pub title: String,
1643 pub count: Option<usize>,
1644 pub summary: Option<String>,
1645 pub open: bool,
1647 pub actions: Vec<PanelAction>,
1648 pub children: Vec<Widget>,
1649}
1650
1651impl Default for PanelSection {
1652 fn default() -> Self {
1653 Self {
1654 id: String::new(),
1655 title: String::new(),
1656 count: None,
1657 summary: None,
1658 open: true,
1659 actions: Vec::new(),
1660 children: Vec::new(),
1661 }
1662 }
1663}
1664
1665#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1668#[serde(default)]
1669pub struct Tag {
1670 pub text: String,
1671 pub tone: Tone,
1673 pub selected: bool,
1675 pub lit: bool,
1677}
1678
1679#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1682#[serde(default)]
1683pub struct Badge {
1684 pub icon: String,
1685 pub tone: Tone,
1686 pub hint: String,
1688 pub lit: bool,
1690 pub color: Option<[u8; 3]>,
1692}
1693
1694#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1697#[serde(default)]
1698pub struct Item {
1699 pub id: String,
1702 pub icon: Option<String>,
1703 pub tone: Tone,
1705 pub muted: bool,
1707 pub problem: bool,
1709 pub label: String,
1710 pub secondary: Option<String>,
1712 pub value: Option<String>,
1714 pub value_plain: bool,
1716 pub tags: Vec<Tag>,
1717 pub badges: Vec<Badge>,
1718 pub selected: bool,
1719 pub kind: Option<String>,
1721 pub hint: Option<String>,
1723 pub menu: Vec<PanelAction>,
1725 pub related: bool,
1728 pub lit: bool,
1731 pub color: Option<[u8; 3]>,
1734 pub value_tone: Tone,
1736 pub value_hint: Option<String>,
1738 pub flag: Option<StatusLine>,
1740 pub reveal: bool,
1742 pub editing: bool,
1745 pub field: Option<Box<Widget>>,
1749}
1750
1751#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1756#[serde(default)]
1757pub struct ItemList {
1758 pub id: String,
1759 pub items: Vec<Item>,
1760 pub multi: bool,
1761 pub filter: Option<String>,
1763 pub empty: Option<String>,
1765}
1766
1767#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1774#[serde(default)]
1775pub struct FilterField {
1776 pub id: String,
1777 pub hint: String,
1779 pub kinds: Vec<String>,
1780 pub kind: usize,
1782 pub by_bench: bool,
1783}
1784
1785#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1787#[serde(default)]
1788pub struct StatusLine {
1789 pub text: String,
1790 pub tone: Tone,
1791 pub detail: String,
1793}
1794
1795#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1799#[serde(default)]
1800pub struct TaskHeader {
1801 pub subtitle: String,
1803 pub status: Option<StatusLine>,
1804}
1805
1806#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1810#[serde(default)]
1811pub struct Stack {
1812 pub children: Vec<Widget>,
1813 pub tight: bool,
1814 pub spacing: Option<f32>,
1816}
1817
1818#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1822#[serde(default)]
1823pub struct Flow {
1824 pub children: Vec<Widget>,
1825 pub no_wrap: bool,
1826 pub label: String,
1829}
1830
1831#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1833pub struct Fill {
1834 pub child: Box<Widget>,
1835}
1836
1837impl Default for Fill {
1838 fn default() -> Self {
1839 Self {
1840 child: Box::new(Widget::Separator),
1841 }
1842 }
1843}
1844
1845#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1849#[serde(default)]
1850pub struct Fields {
1851 pub children: Vec<Widget>,
1852 pub label_width: Option<f32>,
1854}
1855
1856#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1858pub struct Inline {
1859 pub child: Box<Widget>,
1860}
1861
1862impl Default for Inline {
1863 fn default() -> Self {
1864 Self {
1865 child: Box::new(Widget::Separator),
1866 }
1867 }
1868}
1869
1870#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1873#[serde(default)]
1874pub struct PickChip {
1875 pub id: String,
1876 pub label: String,
1877 pub value: Option<String>,
1879 pub armed: bool,
1880 pub placeholder: String,
1882}
1883
1884#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1886#[serde(default)]
1887pub struct Entry {
1888 pub id: String,
1889 pub label: String,
1890 pub value: String,
1891 pub placeholder: String,
1892 pub multiline: bool,
1894 pub width: Option<f32>,
1896 pub mono: bool,
1898 pub live: bool,
1900 pub formulas: bool,
1903 pub large: bool,
1905}
1906
1907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1912#[serde(default)]
1913pub struct Quantity {
1914 pub id: String,
1915 pub label: String,
1916 pub value: f64,
1917 pub dim: Dim,
1918 pub bind: Option<Bind>,
1919 pub min: Option<f64>,
1920 pub max: Option<f64>,
1921 pub decimals: usize,
1922 pub error: Option<String>,
1923 pub speed: Option<f64>,
1926 pub width: Option<f32>,
1928 pub enabled: bool,
1929 pub focus: bool,
1931 pub unit: Option<String>,
1933 pub stepper: Option<Stepper>,
1935 pub bare: bool,
1939 pub drag_min: Option<f64>,
1944 pub drag_max: Option<f64>,
1945 pub shown: Option<String>,
1950 pub held: Option<bool>,
1954}
1955
1956impl Default for Quantity {
1957 fn default() -> Self {
1958 Self {
1959 id: String::new(),
1960 label: String::new(),
1961 value: 0.0,
1962 dim: Dim::default(),
1963 bind: None,
1964 min: None,
1965 max: None,
1966 decimals: 2,
1967 error: None,
1968 speed: None,
1969 width: None,
1970 enabled: true,
1971 focus: false,
1972 unit: None,
1973 stepper: None,
1974 bare: false,
1975 drag_min: None,
1976 drag_max: None,
1977 shown: None,
1978 held: None,
1979 }
1980 }
1981}
1982
1983#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1987#[serde(default)]
1988pub struct Stepper {
1989 pub text: String,
1990 pub down: bool,
1991 pub up: bool,
1992 pub down_hint: String,
1993 pub up_hint: String,
1994}
1995
1996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2000#[serde(default)]
2001pub struct Check {
2002 pub id: String,
2003 pub label: String,
2004 pub text: String,
2005 pub on: bool,
2006 pub enabled: bool,
2007 pub hint: String,
2009}
2010
2011impl Default for Check {
2012 fn default() -> Self {
2013 Self {
2014 id: String::new(),
2015 label: String::new(),
2016 text: String::new(),
2017 on: false,
2018 enabled: true,
2019 hint: String::new(),
2020 }
2021 }
2022}
2023
2024#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2026#[serde(default)]
2027pub struct Select {
2028 pub id: String,
2029 pub label: String,
2030 pub options: Vec<String>,
2031 pub selected: usize,
2032 pub width: Option<f32>,
2034 pub enabled: bool,
2035 pub text: Option<String>,
2039 pub disabled: Vec<usize>,
2041 pub hints: Vec<String>,
2043 pub separated: Vec<usize>,
2045 pub segmented: bool,
2048 pub search: bool,
2051}
2052
2053impl Default for Select {
2054 fn default() -> Self {
2055 Self {
2056 id: String::new(),
2057 label: String::new(),
2058 options: Vec::new(),
2059 selected: 0,
2060 width: None,
2061 enabled: true,
2062 text: None,
2063 disabled: Vec::new(),
2064 hints: Vec::new(),
2065 separated: Vec::new(),
2066 segmented: false,
2067 search: false,
2068 }
2069 }
2070}
2071
2072#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2077#[serde(default)]
2078pub struct FieldGrid {
2079 pub id: String,
2081 pub children: Vec<Widget>,
2082 pub roomy: bool,
2083 pub apart: bool,
2085}
2086
2087#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2090#[serde(default)]
2091pub struct Alert {
2092 pub id: Option<String>,
2093 pub kind: NoteKind,
2094 pub title: Option<String>,
2095 pub text: String,
2096}
2097
2098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2101#[serde(default)]
2102pub struct Card {
2103 pub icon: Option<String>,
2104 pub title: String,
2105 pub icon_size: f32,
2107 pub children: Vec<Widget>,
2108 pub padding: Option<f32>,
2110}
2111
2112impl Default for Card {
2113 fn default() -> Self {
2114 Self {
2115 icon: None,
2116 title: String::new(),
2117 icon_size: 18.0,
2118 children: Vec::new(),
2119 padding: None,
2120 }
2121 }
2122}
2123
2124#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2128#[serde(default)]
2129pub struct Caption {
2130 pub text: String,
2131 pub tone: Tone,
2132 pub small: bool,
2133 pub mono: bool,
2134 pub overline: bool,
2136 pub strong: bool,
2139 pub medium: bool,
2141 pub primary: bool,
2143}
2144
2145#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2148#[serde(default)]
2149pub struct Plot {
2150 pub height: f32,
2151 pub series: Vec<PlotSeries>,
2152}
2153
2154#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2156#[serde(default)]
2157pub struct PlotSeries {
2158 pub points: Vec<[f64; 2]>,
2159 pub tone: Tone,
2160}
2161
2162#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2167#[serde(default)]
2168pub struct Cells {
2169 pub id: String,
2171 pub columns: usize,
2173 pub children: Vec<Widget>,
2174}
2175
2176#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
2178#[serde(rename_all = "snake_case")]
2179pub enum GapSize {
2180 #[default]
2181 Small,
2182 Medium,
2183 Large,
2184 Section,
2187}
2188
2189#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2191#[serde(default)]
2192pub struct Gap {
2193 pub size: GapSize,
2194}
2195
2196#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2198#[serde(default)]
2199pub struct Swatch {
2200 pub color: [u8; 3],
2201 pub chosen: bool,
2203}
2204
2205#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2209#[serde(default)]
2210pub struct Swatches {
2211 pub id: String,
2212 pub swatches: Vec<Swatch>,
2213 pub keys: bool,
2217}
2218
2219#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2222#[serde(default)]
2223pub struct ColorField {
2224 pub id: String,
2225 pub label: String,
2226 pub color: [f32; 3],
2228}
2229
2230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2234#[serde(default)]
2235pub struct Range {
2236 pub id: String,
2237 pub label: String,
2238 pub value: f64,
2239 pub min: f64,
2240 pub max: f64,
2241 pub step: Option<f64>,
2243 pub decimals: usize,
2244 pub suffix: String,
2245 pub enabled: bool,
2246}
2247
2248impl Default for Range {
2249 fn default() -> Self {
2250 Self {
2251 id: String::new(),
2252 label: String::new(),
2253 value: 0.0,
2254 min: 0.0,
2255 max: 1.0,
2256 step: None,
2257 decimals: 2,
2258 suffix: String::new(),
2259 enabled: true,
2260 }
2261 }
2262}
2263
2264#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2269#[serde(default)]
2270pub struct RowButton {
2271 pub id: String,
2272 pub text: String,
2273 pub current: bool,
2274}
2275
2276#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2280#[serde(default)]
2281pub struct Selectable {
2282 pub id: String,
2283 pub text: String,
2284 pub selected: bool,
2285}
2286
2287#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2291#[serde(default)]
2292pub struct Picture {
2293 pub key: String,
2294 pub width: u32,
2295 pub height: u32,
2296 pub rgba: Vec<u8>,
2299}
2300
2301#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2303#[serde(default)]
2304pub struct Tile {
2305 pub label: String,
2306 pub picture: Picture,
2307}
2308
2309#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2313#[serde(default)]
2314pub struct Gallery {
2315 pub id: String,
2316 pub tiles: Vec<Tile>,
2317 pub selected: Option<usize>,
2318}
2319
2320#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2327#[serde(default)]
2328pub struct SettingsGroup {
2329 pub title: String,
2330 pub children: Vec<Widget>,
2331}
2332
2333macro_rules! block_into_widget {
2334 ($($block:ident => $variant:ident),* $(,)?) => {
2335 $(impl From<$block> for Widget {
2336 fn from(block: $block) -> Self {
2337 Widget::$variant(block)
2338 }
2339 })*
2340 };
2341}
2342
2343block_into_widget! {
2344 PanelSection => Section,
2345 Item => Item,
2346 ItemList => Items,
2347 FilterField => Filter,
2348 StatusLine => Status,
2349 Stack => Stack,
2350 Flow => Flow,
2351 Fill => Fill,
2352 Fields => Fields,
2353 Inline => Inline,
2354 PickChip => PickChip,
2355 Entry => Entry,
2356 TaskHeader => TaskHeader,
2357 Quantity => Quantity,
2358 Check => Check,
2359 Select => Select,
2360 FieldGrid => Grid,
2361 Alert => Alert,
2362 Card => Card,
2363 Caption => Caption,
2364 Gap => Gap,
2365 Plot => Plot,
2366 Swatches => Swatches,
2367 ColorField => Color,
2368 Range => Range,
2369 Toggles => Toggles,
2370 RowButton => RowButton,
2371 Selectable => Selectable,
2372 Gallery => Gallery,
2373 SettingsGroup => Settings,
2374 Cells => Cells,
2375 PanelAction => Action,
2376}
2377
2378#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2384#[serde(tag = "type", rename_all = "snake_case")]
2385pub enum Cell {
2386 Text {
2388 text: String,
2389 #[serde(default)]
2390 mono: bool,
2391 #[serde(default)]
2392 strong: bool,
2393 },
2394 Link { text: String },
2396 Edit { text: String },
2398 Check {
2400 on: bool,
2401 #[serde(default)]
2402 hint: Option<String>,
2403 },
2404}
2405
2406#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
2409#[serde(rename_all = "snake_case")]
2410pub enum DiagramStroke {
2411 #[default]
2413 Outline,
2414 Hidden,
2416 Axis,
2418 Thin,
2420 Accent,
2422}
2423
2424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2430#[serde(tag = "type", rename_all = "snake_case")]
2431pub enum DiagramShape {
2432 Path {
2435 points: Vec<[f32; 2]>,
2436 #[serde(default)]
2437 closed: bool,
2438 #[serde(default)]
2439 stroke: DiagramStroke,
2440 #[serde(default)]
2441 fill: bool,
2442 },
2443 Circle {
2444 center: [f32; 2],
2445 radius: f32,
2446 #[serde(default)]
2447 stroke: DiagramStroke,
2448 #[serde(default)]
2449 fill: bool,
2450 },
2451 Text {
2453 at: [f32; 2],
2454 text: String,
2455 #[serde(default)]
2456 mono: bool,
2457 },
2458}
2459
2460#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2465pub struct Dimension {
2466 pub from: [f32; 2],
2467 pub to: [f32; 2],
2468 #[serde(default)]
2469 pub offset: f32,
2470 pub text: String,
2471 #[serde(default)]
2473 pub emphasis: bool,
2474}
2475
2476#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2479pub struct Callout {
2480 pub anchor: [f32; 2],
2481 pub at: [f32; 2],
2482 pub text: String,
2483 #[serde(default)]
2484 pub emphasis: bool,
2485}
2486
2487fn two() -> usize {
2488 2
2489}
2490
2491fn yes() -> bool {
2492 true
2493}
2494
2495#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
2496#[serde(rename_all = "snake_case")]
2497pub enum NoteKind {
2498 #[default]
2499 Info,
2500 Success,
2501 Warning,
2502 Error,
2503}
2504
2505#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
2506#[serde(rename_all = "snake_case")]
2507pub enum ButtonStyle {
2508 Primary,
2509 #[default]
2510 Secondary,
2511 Destructive,
2512 Small,
2514 Plain,
2516 PlainSmall,
2518 Outline,
2520}
2521
2522#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
2524pub struct Bind {
2525 pub feature: String,
2526 pub key: String,
2527}
2528
2529#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
2530pub struct ListItem {
2531 pub label: String,
2532 #[serde(default)]
2533 pub detail: Option<String>,
2534 #[serde(default)]
2535 pub icon: Option<String>,
2536}
2537
2538#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
2540#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2541#[serde(rename_all = "snake_case")]
2542pub enum PanelSlot {
2543 Task,
2544 Settings,
2545 Transport,
2547 Card,
2549}
2550
2551#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
2553#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2554#[serde(tag = "type", rename_all = "snake_case")]
2555pub enum PanelEvent {
2556 Number {
2557 id: String,
2558 value: f64,
2559 },
2560 Choice {
2561 id: String,
2562 index: usize,
2563 },
2564 Toggle {
2565 id: String,
2566 on: bool,
2567 },
2568 Text {
2569 id: String,
2570 value: String,
2571 },
2572 Button {
2573 id: String,
2574 },
2575 Pick {
2576 id: String,
2577 },
2578 Select {
2579 id: String,
2580 index: usize,
2581 },
2582 Cell {
2584 id: String,
2585 row: usize,
2586 column: usize,
2587 value: String,
2588 },
2589 CellText {
2591 id: String,
2592 row: usize,
2593 column: usize,
2594 value: String,
2595 },
2596 CellCheck {
2598 id: String,
2599 row: usize,
2600 column: usize,
2601 on: bool,
2602 },
2603 DiagramPress {
2607 id: String,
2608 x: f32,
2609 y: f32,
2610 #[serde(default)]
2611 dragging: bool,
2612 #[serde(default)]
2613 released: bool,
2614 },
2615 Hover {
2618 id: String,
2619 index: Option<usize>,
2620 },
2621 Activate {
2623 id: String,
2624 index: usize,
2625 },
2626 ContextMenu {
2628 id: String,
2629 index: usize,
2630 action: String,
2631 },
2632 Tag {
2634 id: String,
2635 index: usize,
2636 tag: usize,
2637 },
2638 Selection {
2640 id: String,
2641 indices: Vec<usize>,
2642 },
2643 Filter {
2645 id: String,
2646 text: String,
2647 kind: usize,
2648 },
2649 Clear {
2651 id: String,
2652 },
2653 Badge {
2655 id: String,
2656 index: usize,
2657 badge: usize,
2658 },
2659 HoverPart {
2662 id: String,
2663 index: Option<usize>,
2664 tag: Option<usize>,
2665 badge: Option<usize>,
2666 },
2667 ItemText {
2670 id: String,
2671 index: usize,
2672 value: String,
2673 done: bool,
2674 },
2675 Color {
2677 id: String,
2678 color: [f32; 3],
2679 },
2680 TextLeft {
2683 id: String,
2684 value: String,
2685 escaped: bool,
2686 },
2687 CardClose {
2690 id: String,
2691 accept: bool,
2692 },
2693}
2694
2695impl PanelEvent {
2696 pub fn id(&self) -> &str {
2697 match self {
2698 PanelEvent::Number { id, .. }
2699 | PanelEvent::Choice { id, .. }
2700 | PanelEvent::Toggle { id, .. }
2701 | PanelEvent::Text { id, .. }
2702 | PanelEvent::Button { id }
2703 | PanelEvent::Pick { id }
2704 | PanelEvent::Select { id, .. }
2705 | PanelEvent::Cell { id, .. }
2706 | PanelEvent::CellText { id, .. }
2707 | PanelEvent::CellCheck { id, .. }
2708 | PanelEvent::DiagramPress { id, .. }
2709 | PanelEvent::Hover { id, .. }
2710 | PanelEvent::Activate { id, .. }
2711 | PanelEvent::ContextMenu { id, .. }
2712 | PanelEvent::Tag { id, .. }
2713 | PanelEvent::Selection { id, .. }
2714 | PanelEvent::Filter { id, .. }
2715 | PanelEvent::Clear { id }
2716 | PanelEvent::Badge { id, .. }
2717 | PanelEvent::HoverPart { id, .. }
2718 | PanelEvent::ItemText { id, .. }
2719 | PanelEvent::Color { id, .. }
2720 | PanelEvent::TextLeft { id, .. }
2721 | PanelEvent::CardClose { id, .. } => id,
2722 }
2723 }
2724}
2725
2726#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
2729#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2730#[serde(tag = "type", content = "id", rename_all = "snake_case")]
2731pub enum MenuScope {
2732 ViewportBody(String),
2733 TreeFeature(String),
2734 TreeBody(String),
2735 StartPage,
2736 EditMenu,
2737 Popup(String),
2740}
2741
2742#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2743pub struct MenuItem {
2744 pub id: String,
2745 pub label: String,
2746 #[serde(default)]
2747 pub icon: Option<String>,
2748 #[serde(default)]
2749 pub hint: Option<String>,
2750 #[serde(default = "yes")]
2751 pub enabled: bool,
2752 #[serde(default)]
2753 pub separator_before: bool,
2754 #[serde(default)]
2757 pub checked: bool,
2758}
2759
2760impl Default for MenuItem {
2761 fn default() -> Self {
2762 Self {
2763 id: String::new(),
2764 label: String::new(),
2765 icon: None,
2766 hint: None,
2767 enabled: yes(),
2768 separator_before: false,
2769 checked: false,
2770 }
2771 }
2772}
2773
2774#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2782#[serde(tag = "type", rename_all = "snake_case")]
2783pub enum Request {
2784 ActivateTool {
2785 tool: String,
2786 },
2787 SelectBody {
2788 body: String,
2789 },
2790 JournalLabel {
2792 label: String,
2793 },
2794 SwitchWorkbench {
2795 workbench: String,
2796 },
2797 OrientCamera {
2798 origin: [f32; 3],
2799 normal: [f32; 3],
2800 up: [f32; 3],
2801 },
2802 FinishEditing,
2803 SaveFile {
2806 name: String,
2807 kind: String,
2808 extension: String,
2809 contents: Vec<u8>,
2810 },
2811 SaveFiles {
2814 files: Vec<FileToWrite>,
2815 },
2816 OpenFile {
2820 id: String,
2821 kinds: Vec<FileKind>,
2822 #[serde(default)]
2823 multiple: bool,
2824 },
2825 CopyText {
2828 text: String,
2829 },
2830 OpenMenu {
2836 tag: String,
2837 items: Vec<MenuItem>,
2838 },
2839}
2840
2841pub mod panel;
2846
2847pub mod calls {
2848 pub const ADD_FEATURE: &str = "doc.add_feature";
2851 pub const SET_FEATURE_DATA: &str = "doc.set_feature_data";
2853 pub const REMOVE_FEATURE: &str = "doc.remove_feature";
2855 pub const MOVE_FEATURE: &str = "doc.move_feature";
2859 pub const RENAME_FEATURE: &str = "doc.rename_feature";
2861 pub const SET_FEATURE_VISIBLE: &str = "doc.set_feature_visible";
2863 pub const CREATE_BODY: &str = "doc.create_body";
2865 pub const REMOVE_BODY: &str = "doc.remove_body";
2870 pub const SET_PLACEMENT: &str = "doc.set_placement";
2872 pub const JOB_START: &str = "job.start";
2875 pub const JOB_CANCEL: &str = "job.cancel";
2877 pub const GEOM_HOLES: &str = "geom.holes";
2882 pub const GEOM_FACE_EDGES: &str = "geom.face_edges";
2886 pub const GEOM_SECTION: &str = "geom.section";
2891 pub const GEOM_FACE_LOOPS: &str = "geom.face_loops";
2896}
2897
2898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2900pub struct Section {
2901 pub plane: kernel_api::ProfilePlane,
2904 pub loops: Vec<SectionLoop>,
2905}
2906
2907#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2910pub struct SectionLoop {
2911 pub closed: bool,
2912 pub curves: Vec<SectionCurve>,
2913}
2914
2915#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2916pub struct SectionCurve {
2917 pub curve: kernel_api::ProjectedEdge,
2919 #[serde(default)]
2921 pub reversed: bool,
2922 pub points: Vec<[f64; 3]>,
2924 #[serde(default)]
2926 pub face: Option<u64>,
2927}
2928
2929#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2931pub struct FaceLoops {
2932 #[serde(default)]
2934 pub name: Option<u64>,
2935 pub loops: Vec<Vec<LoopEdge>>,
2937}
2938
2939#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2940pub struct LoopEdge {
2941 pub points: Vec<[f64; 3]>,
2943 pub length: f64,
2944 #[serde(default)]
2945 pub circle: Option<EdgeCircle>,
2946 #[serde(default)]
2948 pub seam: bool,
2949 #[serde(default)]
2952 pub faces: Option<[u64; 2]>,
2953}
2954
2955#[cfg(test)]
2956mod tests {
2957 use super::*;
2958
2959 #[test]
2960 fn a_host_loads_packages_of_its_own_contract_version() {
2961 assert!(api_compatible("printcad:workbench@0.1"));
2962 assert!(api_compatible("0.1.4"));
2963 assert!(!api_compatible("printcad:workbench@0.2"));
2964 assert!(!api_compatible("1.0"));
2965 assert!(contract_satisfies(CONTRACT_VERSION));
2967 assert!(contract_satisfies("0.1"));
2968 assert!(contract_satisfies("printcad:workbench@0.1.0"));
2969 assert!(!contract_satisfies("0.1.999"));
2970 assert!(!contract_satisfies("0.2.0"));
2971 assert!(!contract_satisfies("next"));
2972 }
2973
2974 #[test]
2975 fn a_block_reads_with_its_fields_left_out_and_writes_back_the_same() {
2976 let section: Widget =
2977 serde_json::from_str(r#"{"type":"section","title":"Elements","count":9}"#).unwrap();
2978 let Widget::Section(PanelSection {
2979 open,
2980 count,
2981 children,
2982 ..
2983 }) = §ion
2984 else {
2985 panic!("{section:?}");
2986 };
2987 assert!(*open && *count == Some(9) && children.is_empty());
2988 let item: Widget = Item {
2989 label: "Line 1".into(),
2990 value: Some("89.92 mm".into()),
2991 ..Default::default()
2992 }
2993 .into();
2994 for widget in [section, item] {
2995 let json = serde_json::to_string(&widget).unwrap();
2996 assert_eq!(serde_json::from_str::<Widget>(&json).unwrap(), widget);
2997 }
2998 }
2999
3000 fn contract(version: &str) -> String {
3002 version.split('.').take(2).collect::<Vec<_>>().join(".")
3003 }
3004
3005 #[test]
3006 fn the_crate_the_wit_package_and_the_contract_share_a_version() {
3007 let declared = WIT
3008 .lines()
3009 .find_map(|line| line.trim().strip_prefix("package printcad:workbench@"))
3010 .and_then(|rest| rest.strip_suffix(';'))
3011 .expect("the WIT file names its package");
3012 assert_eq!(contract(declared), API_VERSION);
3013 assert_eq!(contract(env!("CARGO_PKG_VERSION")), API_VERSION);
3014 }
3015
3016 #[test]
3017 fn tagged_values_read_as_a_guest_writes_them() {
3018 let widget: Widget = serde_json::from_str(
3019 r#"{"type":"number","id":"teeth","label":"Teeth","value":20,"bind":{"feature":"f","key":"/teeth"}}"#,
3020 )
3021 .unwrap();
3022 match widget {
3023 Widget::Number {
3024 decimals,
3025 dim,
3026 bind,
3027 ..
3028 } => {
3029 assert_eq!(decimals, 2);
3030 assert_eq!(dim, Dim::Length);
3031 assert_eq!(bind.unwrap().key, "/teeth");
3032 }
3033 other => panic!("{other:?}"),
3034 }
3035 let plan: Plan = serde_json::from_str(r#"{"type":"error","message":"no"}"#).unwrap();
3036 assert_eq!(
3037 plan,
3038 Plan::Error {
3039 feature: None,
3040 message: "no".into()
3041 }
3042 );
3043 let scope = serde_json::to_string(&MenuScope::TreeBody("b".into())).unwrap();
3044 assert_eq!(scope, r#"{"type":"tree_body","id":"b"}"#);
3045 assert_eq!(
3046 serde_json::from_str::<MenuScope>(&scope).unwrap(),
3047 MenuScope::TreeBody("b".into())
3048 );
3049 let event = serde_json::to_string(&Event::JobFinished {
3050 job: 3,
3051 result: Ok("x".into()),
3052 })
3053 .unwrap();
3054 assert_eq!(
3055 event,
3056 r#"{"type":"job_finished","job":3,"result":{"Ok":"x"}}"#
3057 );
3058 }
3059
3060 #[test]
3061 fn layout_widgets_read_as_a_guest_writes_them() {
3062 let widget: Widget = serde_json::from_str(
3063 r#"{"type":"row","children":[
3064 {"type":"value","label":"Moves","value":"Part"},
3065 {"type":"hinted","hint":"Why","widget":
3066 {"type":"button","id":"x","label":"X","style":"small"}}
3067 ]}"#,
3068 )
3069 .unwrap();
3070 assert_eq!(
3071 widget,
3072 Widget::Row {
3073 children: vec![
3074 Widget::Value {
3075 label: "Moves".into(),
3076 value: "Part".into(),
3077 mono: false,
3078 },
3079 Widget::Hinted {
3080 hint: "Why".into(),
3081 widget: Box::new(Widget::Button {
3082 id: "x".into(),
3083 label: "X".into(),
3084 style: ButtonStyle::Small,
3085 enabled: true,
3086 }),
3087 },
3088 ],
3089 }
3090 );
3091 }
3092
3093 #[test]
3094 fn a_sheet_and_its_cell_events_read_as_written() {
3095 let widget: Widget = serde_json::from_str(
3096 r#"{"type":"sheet","id":"parts","columns":["Part","Bought"],"rows":[[
3097 {"type":"link","text":"Bolt"},{"type":"check","on":true}
3098 ]]}"#,
3099 )
3100 .unwrap();
3101 let Widget::Sheet { rows, .. } = widget else {
3102 panic!("{widget:?}");
3103 };
3104 assert_eq!(
3105 rows[0][1],
3106 Cell::Check {
3107 on: true,
3108 hint: None
3109 }
3110 );
3111 let event = PanelEvent::CellText {
3112 id: "parts".into(),
3113 row: 2,
3114 column: 5,
3115 value: "ACME".into(),
3116 };
3117 let json = serde_json::to_string(&event).unwrap();
3118 assert_eq!(
3119 json,
3120 r#"{"type":"cell_text","id":"parts","row":2,"column":5,"value":"ACME"}"#
3121 );
3122 assert_eq!(event.id(), "parts");
3123 }
3124
3125 #[test]
3126 fn a_struct_left_to_its_defaults_reads_as_its_fields_left_out() {
3127 fn read<T: serde::de::DeserializeOwned>(json: &str) -> T {
3128 serde_json::from_str(json).unwrap()
3129 }
3130 assert_eq!(read::<Tool>(r#"{"id":"","label":""}"#), Tool::default());
3131 assert_eq!(
3132 read::<Parameter>(r#"{"key":"","label":"","pointer":""}"#),
3133 Parameter::default()
3134 );
3135 assert_eq!(
3136 read::<MenuItem>(r#"{"id":"","label":""}"#),
3137 MenuItem::default()
3138 );
3139 assert_eq!(
3140 read::<Label>(r#"{"at":[0,0,0],"text":"","color":[1,1,1]}"#),
3141 Label::default()
3142 );
3143 assert_eq!(
3144 read::<Mesh>(r#"{"positions":[],"indices":[],"color":[1,1,1]}"#),
3145 Mesh::default()
3146 );
3147 assert_eq!(
3148 read::<Polyline>(r#"{"points":[],"color":[1,1,1]}"#),
3149 Polyline::default()
3150 );
3151 assert_eq!(
3152 read::<Region>(r#"{"outline":[],"color":[1,1,1]}"#),
3153 Region::default()
3154 );
3155 assert_eq!(
3156 read::<KeptMesh>(r#"{"handle":0,"color":[1,1,1]}"#),
3157 KeptMesh::default()
3158 );
3159 assert_eq!(
3160 read::<Manifest>(r#"{"id":"","name":"","version":"","api":"printcad:workbench@0.1"}"#),
3161 Manifest::default()
3162 );
3163 }
3164
3165 #[test]
3168 fn an_event_of_a_kind_not_known_yet_reads_as_an_unknown_variant() {
3169 let input = r#"{"event":{"type":"gesture","scale":2},"pointer":{}}"#;
3170 let error = serde_json::from_str::<Input>(input).unwrap_err();
3171 assert!(error.to_string().starts_with("unknown variant"), "{error}");
3172 let error = serde_json::from_str::<PanelEvent>(r#"{"type":"drag","id":"x"}"#).unwrap_err();
3173 assert!(error.to_string().starts_with("unknown variant"), "{error}");
3174 }
3175
3176 #[test]
3177 fn a_frame_left_empty_reads_from_nothing() {
3178 let frame: Frame = serde_json::from_str("{}").unwrap();
3179 assert_eq!(frame, Frame::default());
3180 }
3181}