Skip to main content

crisol_core/spec/
widget.rs

1//! The widget tree of a host spec.
2
3use serde::{Deserialize, Serialize};
4
5use super::*;
6/// A widget in the spec tree.
7
8#[derive(Clone, Debug, Serialize, Deserialize)]
9#[cfg_attr(feature = "schema", derive(JsonSchema))]
10#[serde(tag = "kind", rename_all = "snake_case")]
11#[non_exhaustive]
12/// # Example
13///
14/// ```
15/// use crisol_core::spec::WidgetSpec;
16/// ```
17#[cfg_attr(feature = "schema", schemars(description = "A widget in the spec tree."))]
18pub enum WidgetSpec {
19    /// A label.
20    Label {
21        /// Text.
22        text: String,
23        /// Point size.
24        size: f32,
25        /// `default`, `muted`, `accent`, `danger`, `success`.
26        tone: String,
27        /// Strong weight.
28        strong: bool,
29    },
30    /// A button that emits its command id.
31    Button {
32        /// Stable id.
33        id: String,
34        /// Label.
35        label: String,
36        /// `primary`, `secondary`, `ghost`, `outline`, `danger`.
37        variant: String,
38        /// Enabled state.
39        enabled: bool,
40    },
41    /// A single-line text input.
42    TextField {
43        /// Stable id.
44        id: String,
45        /// Label.
46        label: String,
47        /// Initial value.
48        value: String,
49        /// Hint.
50        hint: String,
51    },
52    /// A checkbox.
53    Checkbox {
54        /// Stable id.
55        id: String,
56        /// Label.
57        label: String,
58        /// Initial state.
59        checked: bool,
60    },
61    /// A switch.
62    Switch {
63        /// Stable id.
64        id: String,
65        /// Label.
66        label: String,
67        /// Initial state.
68        on: bool,
69    },
70    /// A select.
71    Select {
72        /// Stable id.
73        id: String,
74        /// Label.
75        label: String,
76        /// Options.
77        options: Vec<String>,
78        /// Selected index.
79        selected: usize,
80    },
81    /// A slider.
82    Slider {
83        /// Stable id.
84        id: String,
85        /// Label.
86        label: String,
87        /// Minimum.
88        min: f64,
89        /// Maximum.
90        max: f64,
91        /// Value.
92        value: f64,
93        /// Step.
94        step: f64,
95    },
96    /// A horizontal rule.
97    Separator,
98    /// Empty space.
99    Spacer {
100        /// Height in points.
101        height: f32,
102    },
103    /// A horizontal row.
104    Row {
105        /// Children.
106        children: Vec<WidgetSpec>,
107        /// Gap in points.
108        gap: f32,
109    },
110    /// A vertical column.
111    Column {
112        /// Children.
113        children: Vec<WidgetSpec>,
114        /// Gap in points.
115        gap: f32,
116    },
117    /// A titled card.
118    Card {
119        /// Title.
120        title: String,
121        /// Children.
122        children: Vec<WidgetSpec>,
123    },
124    /// A tab strip and its active content.
125    Tabs {
126        /// Stable id.
127        id: String,
128        /// Tabs.
129        tabs: Vec<String>,
130        /// Active index.
131        active: usize,
132        /// Content per tab.
133        children: Vec<Vec<WidgetSpec>>,
134    },
135    /// An explorer-style tree.
136    Tree {
137        /// Stable id.
138        id: String,
139        /// Nodes.
140        nodes: Vec<TreeSpec>,
141        /// Selected key.
142        selected: Option<String>,
143    },
144    /// A typed data grid over a host dataset.
145    DataGrid {
146        /// Stable id.
147        id: String,
148        /// Dataset name registered with `Host::set_dataset`.
149        dataset: String,
150        /// Viewport height.
151        height: f32,
152    },
153    /// A plot over points or a host dataset.
154    Plot {
155        /// Stable id.
156        id: String,
157        /// Title.
158        title: String,
159        /// Series.
160        series: Vec<SeriesSpec>,
161        /// Height.
162        height: f32,
163        /// `cpu` or `gpu`.
164        renderer: String,
165    },
166    /// A Rust extension widget registered with `Host::register_custom`.
167    Custom {
168        /// Registered widget kind.
169        widget: String,
170        /// Opaque properties passed to the extension.
171        props: serde_json::Value,
172    },
173}