zaxis 0.0.5

An event-driven immediate mode GUI for desktop tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
use super::*;
use crate::{
    Border, Color, CornerRadius, Padding, ScrollStyle, SplitHandleStyle, SplitSurface, Vec2,
};
use std::time::Duration;

trait PatchValue: Clone {
    fn apply_to(&self, target: &mut Self) {
        *target = self.clone();
    }
}
macro_rules! values { ($($ty:ty),*)=> {$(impl PatchValue for $ty {})*}; }
values!(
    f32,
    f64,
    crate::FontWeight,
    usize,
    bool,
    Duration,
    Vec2,
    Color,
    Border,
    CornerRadius,
    Padding,
    ScrollStyle,
    SplitSurface,
    SplitHandleStyle
);
impl PatchValue for ControlStyle {
    fn apply_to(&self, target: &mut Self) {
        target.merge(*self);
    }
}
impl PatchValue for SurfaceStyle {
    fn apply_to(&self, target: &mut Self) {
        target.merge(*self);
    }
}

macro_rules! patch {
    ($name:ident, $target:ty, {$($field:ident: $ty:ty),* $(,)?}) => {
        #[derive(Clone, Debug, Default, PartialEq)]
        pub struct $name { $(pub $field: Option<$ty>,)* }
        impl $name {
            pub fn apply(&self, style: &mut $target) {
                $(if let Some(value) = &self.$field { value.apply_to(&mut style.$field); })*
            }
        }
    };
}

patch!(NumberStyleOverride, crate::NumberStyle, {
    surface: crate::ControlStyle,

    width: f32,
    height: f32,
    padding: Padding,
    rounding: CornerRadius,
    font_size: f32,
    fill: Color,
    hovered: Color,
    invalid: Color,
    sensitivity: f64,
    shift_multiplier: f64,
    ctrl_multiplier: f64,
});

patch!(GridStyleOverride, crate::GridStyle, {
    surface: crate::SurfaceStyle,

    padding: Padding,
    cell_padding: Padding,
    spacing: Vec2,
    component_spacing: f32,
    row_min_height: f32,
    fill: Color,
    rounding: f32,
});

patch!(TableStyleOverride, crate::TableStyle, {
    row: crate::ControlStyle,
    header: crate::ControlStyle,

    rounding: CornerRadius,
    border: Border,
    padding: Padding,
    cell_padding: Padding,
    header_height: f32,
    row_min_height: f32,
    component_spacing: f32,
    font_size: f32,
    header_font_weight: crate::FontWeight,
    fill: Color,
    header_fill: Color,
    text_color: Color,
    alternate_fill: Color,
    selected_fill: Color,
    hovered_fill: Color,
    separator_color: Color,
    separator_width: f32,
    resize_handle_width: f32,
    striped: bool,
    separators: bool,
    scroll: ScrollStyle,
});

patch!(ComboBoxStyleOverride, crate::ComboBoxStyle, {
    trigger: crate::ControlStyle,
    option: crate::ControlStyle,

    width: f32,
    trigger_height: f32,
    label_height: f32,
    label_gap: f32,
    row_height: f32,
    row_gap: f32,
    visible_rows: usize,
    popup_gap: f32,
    trigger_padding: Padding,
    popup_padding: Padding,
    rounding: CornerRadius,
    font_size: f32,
    label_font_size: f32,
    trigger_fill: Color,
    popup_fill: Color,
    text: Color,
    muted_text: Color,
    disabled_text: Color,
    check_color: Color,
    active_fill: Color,
    border: Border,
    hover_border: Border,
    popup_border: Border,
    animation_duration: Duration,
});

patch!(ScrollStyleOverride, crate::ScrollStyle, {
    thumb: crate::ControlStyle,

    padding: Padding,
    spacing: f32,
    bar_width: f32,
    bar_margin: f32,
    min_thumb_length: f32,
    thumb_color: Color,
    thumb_hovered: Color,
    hint_size: f32,
    hint_color: Color,
});

patch!(SplitStyleOverride, crate::SplitStyle, {
    container: SplitSurface,
    panel: SplitSurface,
    gap: f32,
    handle: SplitHandleStyle,
    keyboard_step: f32,
    keyboard_large_step: f32,
    spacing: f32,
});

#[derive(Clone, Debug, Default, PartialEq)]
pub struct StyleOverrides {
    pub accent: Option<Color>,
    pub on_accent: Option<Color>,
    pub disabled_text: Option<Color>,
    pub selected_fill: Option<Color>,
    pub selected_text: Option<Color>,
    pub success: Option<Color>,
    pub on_success: Option<Color>,
    pub warning: Option<Color>,
    pub on_warning: Option<Color>,
    pub error: Option<Color>,
    pub on_error: Option<Color>,
    pub control_height: Option<f32>,
    pub opacity: Option<f32>,
    pub elevation: Option<crate::Shadow>,
    pub typography: Option<Typography>,
    pub button: ButtonStyle,
    pub checkbox: CheckboxStyle,
    pub switch: SwitchStyle,
    pub segmented: SegmentedStyle,
    pub radio: RadioStyle,
    pub segmented_outlined: SegmentedStyle,
    pub tabs: TabsStyle,
    pub dock: crate::DockStyle,
    pub slider: SliderStyle,
    pub text_edit: TextEditStyle,
    pub window: WindowStyle,
    pub title_bar: TitleBarStyle,
    pub popup: PopupStyle,
    pub modal: ModalStyle,
    pub card: CardStyle,
    pub color_picker: ColorPickerStyle,
    pub text: TextStyle,
    pub separator: SeparatorStyle,
    pub loader: LoaderStyle,
    pub progress: ProgressStyle,
    pub split: SplitStyleOverride,
    pub collapsing: crate::CollapsingStyle,
    pub tree: crate::TreeStyle,
    pub number: NumberStyleOverride,
    pub grid: GridStyleOverride,
    pub table: TableStyleOverride,
    pub combo_box: ComboBoxStyleOverride,
    pub scroll: ScrollStyleOverride,
    pub drag: crate::DragStyle,
    pub motion: Option<crate::MotionStyle>,
    pub background: Option<Color>,
    pub window_fill: Option<Color>,
    pub title_fill: Option<Color>,
    pub text_color: Option<Color>,
    pub muted_text: Option<Color>,
    pub border: Option<Border>,
    pub button_fill: Option<Color>,
    pub button_hovered: Option<Color>,
    pub hover_style: Option<crate::HoverStyle>,
    pub button_pressed: Option<Color>,
    pub text_edit_fill: Option<Color>,
    pub text_edit_hovered: Option<Color>,
    pub text_edit_placeholder: Option<Color>,
    pub text_edit_selection: Option<Color>,
    pub text_edit_padding: Option<Padding>,
    pub text_edit_rounding: Option<CornerRadius>,
    pub text_edit_width: Option<f32>,
    pub text_edit_height: Option<f32>,
    pub text_edit_font_size: Option<f32>,
    pub text_edit_cursor_width: Option<f32>,
    pub text_edit_blink_interval: Option<std::time::Duration>,
    pub focus_border: Option<Border>,
    pub rounding: Option<CornerRadius>,
    pub window_padding: Option<Padding>,
    pub button_padding: Option<Padding>,
    pub font_size: Option<f32>,
    pub title_height: Option<f32>,
    pub spacing: Option<f32>,
    pub blur_radius: Option<f32>,
    pub blur_opacity: Option<f32>,
}
impl StyleOverrides {
    pub fn apply(&self, style: &mut crate::Style) {
        if let Some(value) = &self.accent {
            style.accent = *value;
        }
        if let Some(value) = &self.on_accent {
            style.on_accent = *value;
        }
        if let Some(value) = &self.disabled_text {
            style.disabled_text = *value;
        }
        if let Some(value) = &self.selected_fill {
            style.selected_fill = *value;
        }
        if let Some(value) = &self.selected_text {
            style.selected_text = *value;
        }
        if let Some(value) = &self.success {
            style.success = *value;
        }
        if let Some(value) = &self.on_success {
            style.on_success = *value;
        }
        if let Some(value) = &self.warning {
            style.warning = *value;
        }
        if let Some(value) = &self.on_warning {
            style.on_warning = *value;
        }
        if let Some(value) = &self.error {
            style.error = *value;
        }
        if let Some(value) = &self.on_error {
            style.on_error = *value;
        }
        if let Some(value) = &self.control_height {
            style.control_height = *value;
        }
        if let Some(value) = &self.opacity {
            style.opacity = *value;
        }
        if let Some(value) = &self.elevation {
            style.elevation = *value;
        }
        if let Some(value) = &self.typography {
            style.typography = *value;
        }
        style.button.merge(self.button);
        style.checkbox.merge(self.checkbox);
        style.switch.merge(self.switch);
        style.segmented.merge(self.segmented);
        style.radio.merge(self.radio);
        style.segmented_outlined.merge(self.segmented_outlined);
        style.tabs.merge(self.tabs);
        style.dock.merge(self.dock);
        style.slider.merge(self.slider);
        style.text_edit.merge(self.text_edit);
        style.window.merge(self.window);
        style.title_bar.merge(self.title_bar);
        style.popup.merge(self.popup);
        style.modal.merge(self.modal);
        style.card.merge(self.card);
        style.color_picker.merge(self.color_picker);
        style.text.merge(self.text);
        style.separator.merge(self.separator);
        style.loader.merge(self.loader);
        style.progress.merge(self.progress);
        self.split.apply(&mut style.split);
        style.collapsing.merge(&self.collapsing);
        style.tree.merge(&self.tree);
        self.number.apply(&mut style.number);
        self.grid.apply(&mut style.grid);
        self.table.apply(&mut style.table);
        self.combo_box.apply(&mut style.combo_box);
        self.scroll.apply(&mut style.scroll);
        style.drag.merge(&self.drag);
        if let Some(value) = &self.motion {
            style.motion = value.clone();
        }
        if let Some(value) = &self.background {
            style.background = *value;
        }
        if let Some(value) = &self.window_fill {
            style.window_fill = *value;
        }
        if let Some(value) = &self.title_fill {
            style.title_fill = *value;
        }
        if let Some(value) = &self.text_color {
            style.text_color = *value;
        }
        if let Some(value) = &self.muted_text {
            style.muted_text = *value;
        }
        if let Some(value) = &self.border {
            style.border = *value;
        }
        if let Some(value) = &self.button_fill {
            style.button_fill = *value;
        }
        if let Some(value) = &self.button_hovered {
            style.button_hovered = *value;
        }
        if let Some(value) = &self.hover_style {
            style.hover_style = *value;
        }
        if let Some(value) = &self.button_pressed {
            style.button_pressed = *value;
        }
        if let Some(value) = &self.text_edit_fill {
            style.text_edit_fill = *value;
        }
        if let Some(value) = &self.text_edit_hovered {
            style.text_edit_hovered = *value;
        }
        if let Some(value) = &self.text_edit_placeholder {
            style.text_edit_placeholder = *value;
        }
        if let Some(value) = &self.text_edit_selection {
            style.text_edit_selection = *value;
        }
        if let Some(value) = &self.text_edit_padding {
            style.text_edit_padding = *value;
        }
        if let Some(value) = &self.text_edit_rounding {
            style.text_edit_rounding = *value;
        }
        if let Some(value) = &self.text_edit_width {
            style.text_edit_width = *value;
        }
        if let Some(value) = &self.text_edit_height {
            style.text_edit_height = *value;
        }
        if let Some(value) = &self.text_edit_font_size {
            style.text_edit_font_size = *value;
        }
        if let Some(value) = &self.text_edit_cursor_width {
            style.text_edit_cursor_width = *value;
        }
        if let Some(value) = &self.text_edit_blink_interval {
            style.text_edit_blink_interval = *value;
        }
        if let Some(value) = &self.focus_border {
            style.focus_border = *value;
        }
        if let Some(value) = &self.rounding {
            style.rounding = *value;
        }
        if let Some(value) = &self.window_padding {
            style.window_padding = *value;
        }
        if let Some(value) = &self.button_padding {
            style.button_padding = *value;
        }
        if let Some(value) = &self.font_size {
            style.font_size = *value;
        }
        if let Some(value) = &self.title_height {
            style.title_height = *value;
        }
        if let Some(value) = &self.spacing {
            style.spacing = *value;
        }
        if let Some(value) = &self.blur_radius {
            style.blur_radius = *value;
        }
        if let Some(value) = &self.blur_opacity {
            style.blur_opacity = *value;
        }
    }
    pub fn resolve(&self, base: &crate::Style) -> crate::Style {
        let mut style = base.clone();
        self.apply(&mut style);
        style
    }
}