aumate 0.2.8

Cross-platform desktop automation library with GUI support
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
//! Widget definition types
//!
//! This module defines the `WidgetDef` enum which represents all possible widgets
//! in a declarative manner. These definitions are serializable and can be sent
//! across thread boundaries.

use super::events::WidgetId;
use super::style::WidgetStyle;

/// Base properties shared by all widgets
#[derive(Debug, Clone, Default, PartialEq)]
pub struct WidgetProps {
    /// Optional unique identifier for event targeting
    pub id: Option<WidgetId>,
    /// Whether the widget is visible
    pub visible: bool,
    /// Whether the widget is enabled (interactive)
    pub enabled: bool,
    /// Optional tooltip text
    pub tooltip: Option<String>,
    /// Widget styling
    pub style: WidgetStyle,
}

impl WidgetProps {
    /// Create default widget properties (visible and enabled)
    pub fn new() -> Self {
        Self {
            id: None,
            visible: true,
            enabled: true,
            tooltip: None,
            style: WidgetStyle::default(),
        }
    }

    /// Set the widget ID
    pub fn with_id(mut self, id: impl Into<String>) -> Self {
        self.id = Some(id.into());
        self
    }

    /// Set visibility
    pub fn with_visible(mut self, visible: bool) -> Self {
        self.visible = visible;
        self
    }

    /// Set enabled state
    pub fn with_enabled(mut self, enabled: bool) -> Self {
        self.enabled = enabled;
        self
    }

    /// Set tooltip
    pub fn with_tooltip(mut self, tooltip: impl Into<String>) -> Self {
        self.tooltip = Some(tooltip.into());
        self
    }

    /// Set style
    pub fn with_style(mut self, style: WidgetStyle) -> Self {
        self.style = style;
        self
    }
}

/// Widget definition - describes a UI widget declaratively
#[derive(Debug, Clone, PartialEq)]
pub enum WidgetDef {
    // ==================== Basic Widgets ====================
    /// Static text label
    Label { text: String, props: WidgetProps },

    /// Clickable button
    Button { text: String, props: WidgetProps },

    /// Single-line text input
    TextInput { value: String, placeholder: Option<String>, password: bool, props: WidgetProps },

    /// Checkbox with label
    Checkbox { checked: bool, label: String, props: WidgetProps },

    /// Numeric slider
    Slider { value: f32, min: f32, max: f32, step: Option<f32>, props: WidgetProps },

    /// Progress bar
    ProgressBar { value: f32, show_percentage: bool, props: WidgetProps },

    /// Image display
    Image { data: Vec<u8>, width: u32, height: u32, props: WidgetProps },

    /// Horizontal separator line
    Separator { props: WidgetProps },

    /// Empty spacer
    Spacer { size: f32, props: WidgetProps },

    // ==================== Layout Widgets ====================
    /// Horizontal layout (children arranged left to right)
    HBox { children: Vec<WidgetDef>, spacing: f32, props: WidgetProps },

    /// Vertical layout (children arranged top to bottom)
    VBox { children: Vec<WidgetDef>, spacing: f32, props: WidgetProps },

    /// Grid layout (rows and columns)
    Grid { children: Vec<Vec<WidgetDef>>, row_spacing: f32, col_spacing: f32, props: WidgetProps },

    // ==================== Container Widgets ====================
    /// Panel with optional background
    Panel { child: Box<WidgetDef>, props: WidgetProps },

    /// Scrollable area
    ScrollArea { child: Box<WidgetDef>, max_height: Option<f32>, props: WidgetProps },

    /// Collapsible group with title
    Group { title: Option<String>, child: Box<WidgetDef>, collapsed: bool, props: WidgetProps },

    // ==================== Advanced Widgets ====================
    /// Dropdown select widget
    Dropdown {
        options: Vec<String>,
        selected: Option<usize>,
        placeholder: Option<String>,
        props: WidgetProps,
    },

    /// Radio button group
    RadioGroup {
        options: Vec<String>,
        selected: Option<usize>,
        horizontal: bool,
        props: WidgetProps,
    },

    /// Multi-line text area
    TextArea { value: String, placeholder: Option<String>, rows: u32, props: WidgetProps },

    /// Tab container with multiple pages
    Tabs { tabs: Vec<(String, Box<WidgetDef>)>, active: usize, props: WidgetProps },

    /// Clickable text link (fires event on click)
    Link { text: String, props: WidgetProps },

    /// Selectable label (toggle state)
    SelectableLabel { text: String, selected: bool, props: WidgetProps },

    /// Numeric input with drag-to-change
    DragValue {
        value: f64,
        min: Option<f64>,
        max: Option<f64>,
        speed: f64,
        prefix: Option<String>,
        suffix: Option<String>,
        decimals: Option<usize>,
        props: WidgetProps,
    },

    /// Color picker widget
    ColorPicker { color: [u8; 4], alpha: bool, props: WidgetProps },

    /// Clickable URL hyperlink
    Hyperlink { text: String, url: String, new_tab: bool, props: WidgetProps },

    /// Button with an image
    ImageButton {
        data: Vec<u8>,
        width: u32,
        height: u32,
        frame: bool,
        selected: bool,
        tint: Option<[u8; 4]>,
        props: WidgetProps,
    },
}

impl WidgetDef {
    // ==================== Basic Widget Constructors ====================

    /// Create a label widget
    pub fn label(text: impl Into<String>) -> Self {
        Self::Label { text: text.into(), props: WidgetProps::new() }
    }

    /// Create a button widget
    pub fn button(text: impl Into<String>) -> Self {
        Self::Button { text: text.into(), props: WidgetProps::new() }
    }

    /// Create a text input widget
    pub fn text_input() -> Self {
        Self::TextInput {
            value: String::new(),
            placeholder: None,
            password: false,
            props: WidgetProps::new(),
        }
    }

    /// Create a text input with initial value
    pub fn text_input_with_value(value: impl Into<String>) -> Self {
        Self::TextInput {
            value: value.into(),
            placeholder: None,
            password: false,
            props: WidgetProps::new(),
        }
    }

    /// Create a checkbox widget
    pub fn checkbox(label: impl Into<String>, checked: bool) -> Self {
        Self::Checkbox { checked, label: label.into(), props: WidgetProps::new() }
    }

    /// Create a slider widget
    pub fn slider(value: f32, min: f32, max: f32) -> Self {
        Self::Slider { value, min, max, step: None, props: WidgetProps::new() }
    }

    /// Create a progress bar widget
    pub fn progress_bar(value: f32) -> Self {
        Self::ProgressBar { value, show_percentage: true, props: WidgetProps::new() }
    }

    /// Create an image widget from RGBA data
    pub fn image(data: Vec<u8>, width: u32, height: u32) -> Self {
        Self::Image { data, width, height, props: WidgetProps::new() }
    }

    /// Create a horizontal separator
    pub fn separator() -> Self {
        Self::Separator { props: WidgetProps::new() }
    }

    /// Create a spacer
    pub fn spacer(size: f32) -> Self {
        Self::Spacer { size, props: WidgetProps::new() }
    }

    // ==================== Layout Widget Constructors ====================

    /// Create a horizontal box layout
    pub fn hbox(children: Vec<WidgetDef>) -> Self {
        Self::HBox { children, spacing: 4.0, props: WidgetProps::new() }
    }

    /// Create a vertical box layout
    pub fn vbox(children: Vec<WidgetDef>) -> Self {
        Self::VBox { children, spacing: 4.0, props: WidgetProps::new() }
    }

    /// Create a grid layout
    pub fn grid(children: Vec<Vec<WidgetDef>>) -> Self {
        Self::Grid { children, row_spacing: 4.0, col_spacing: 4.0, props: WidgetProps::new() }
    }

    // ==================== Container Widget Constructors ====================

    /// Create a panel container
    pub fn panel(child: WidgetDef) -> Self {
        Self::Panel { child: Box::new(child), props: WidgetProps::new() }
    }

    /// Create a scroll area container
    pub fn scroll_area(child: WidgetDef) -> Self {
        Self::ScrollArea { child: Box::new(child), max_height: None, props: WidgetProps::new() }
    }

    /// Create a collapsible group
    pub fn group(title: impl Into<String>, child: WidgetDef) -> Self {
        Self::Group {
            title: Some(title.into()),
            child: Box::new(child),
            collapsed: false,
            props: WidgetProps::new(),
        }
    }

    // ==================== Advanced Widget Constructors ====================

    /// Create a dropdown select widget
    pub fn dropdown(options: Vec<String>) -> Self {
        Self::Dropdown { options, selected: None, placeholder: None, props: WidgetProps::new() }
    }

    /// Create a radio button group
    pub fn radio_group(options: Vec<String>) -> Self {
        Self::RadioGroup { options, selected: None, horizontal: false, props: WidgetProps::new() }
    }

    /// Create a multi-line text area
    pub fn text_area() -> Self {
        Self::TextArea {
            value: String::new(),
            placeholder: None,
            rows: 4,
            props: WidgetProps::new(),
        }
    }

    /// Create a multi-line text area with initial value
    pub fn text_area_with_value(value: impl Into<String>) -> Self {
        Self::TextArea {
            value: value.into(),
            placeholder: None,
            rows: 4,
            props: WidgetProps::new(),
        }
    }

    /// Create a tab container
    pub fn tabs(tabs: Vec<(String, WidgetDef)>) -> Self {
        let boxed_tabs: Vec<(String, Box<WidgetDef>)> =
            tabs.into_iter().map(|(label, content)| (label, Box::new(content))).collect();
        Self::Tabs { tabs: boxed_tabs, active: 0, props: WidgetProps::new() }
    }

    /// Create a link widget (clickable text that fires an event)
    pub fn link(text: impl Into<String>) -> Self {
        Self::Link { text: text.into(), props: WidgetProps::new() }
    }

    /// Create a selectable label widget
    pub fn selectable_label(text: impl Into<String>, selected: bool) -> Self {
        Self::SelectableLabel { text: text.into(), selected, props: WidgetProps::new() }
    }

    /// Create a drag value widget for numeric input
    pub fn drag_value(value: f64) -> Self {
        Self::DragValue {
            value,
            min: None,
            max: None,
            speed: 1.0,
            prefix: None,
            suffix: None,
            decimals: None,
            props: WidgetProps::new(),
        }
    }

    /// Create a color picker widget
    pub fn color_picker(color: [u8; 4]) -> Self {
        Self::ColorPicker { color, alpha: true, props: WidgetProps::new() }
    }

    /// Create a hyperlink widget (opens URL in browser)
    pub fn hyperlink(text: impl Into<String>, url: impl Into<String>) -> Self {
        Self::Hyperlink {
            text: text.into(),
            url: url.into(),
            new_tab: true,
            props: WidgetProps::new(),
        }
    }

    /// Create a hyperlink widget with URL as both text and link
    pub fn hyperlink_url(url: impl Into<String>) -> Self {
        let url_str = url.into();
        Self::Hyperlink {
            text: url_str.clone(),
            url: url_str,
            new_tab: true,
            props: WidgetProps::new(),
        }
    }

    /// Create an image button widget
    pub fn image_button(data: Vec<u8>, width: u32, height: u32) -> Self {
        Self::ImageButton {
            data,
            width,
            height,
            frame: true,
            selected: false,
            tint: None,
            props: WidgetProps::new(),
        }
    }

    // ==================== Builder Methods ====================

    /// Set the widget ID
    pub fn with_id(mut self, id: impl Into<String>) -> Self {
        self.props_mut().id = Some(id.into());
        self
    }

    /// Set visibility
    pub fn with_visible(mut self, visible: bool) -> Self {
        self.props_mut().visible = visible;
        self
    }

    /// Set enabled state
    pub fn with_enabled(mut self, enabled: bool) -> Self {
        self.props_mut().enabled = enabled;
        self
    }

    /// Set tooltip
    pub fn with_tooltip(mut self, tooltip: impl Into<String>) -> Self {
        self.props_mut().tooltip = Some(tooltip.into());
        self
    }

    /// Set style
    pub fn with_style(mut self, style: WidgetStyle) -> Self {
        self.props_mut().style = style;
        self
    }

    /// Set font family for text rendering
    pub fn with_font_family(mut self, family: impl Into<String>) -> Self {
        self.props_mut().style.font_family = Some(family.into());
        self
    }

    /// Set spacing for layout widgets (HBox, VBox)
    pub fn with_spacing(mut self, spacing: f32) -> Self {
        match &mut self {
            WidgetDef::HBox { spacing: s, .. } => *s = spacing,
            WidgetDef::VBox { spacing: s, .. } => *s = spacing,
            WidgetDef::Grid { row_spacing, col_spacing, .. } => {
                *row_spacing = spacing;
                *col_spacing = spacing;
            }
            _ => {}
        }
        self
    }

    /// Set placeholder for text input
    pub fn with_placeholder(mut self, placeholder: impl Into<String>) -> Self {
        if let WidgetDef::TextInput { placeholder: p, .. } = &mut self {
            *p = Some(placeholder.into());
        }
        self
    }

    /// Set password mode for text input
    pub fn with_password(mut self, password: bool) -> Self {
        if let WidgetDef::TextInput { password: p, .. } = &mut self {
            *p = password;
        }
        self
    }

    /// Set step for slider
    pub fn with_step(mut self, step: f32) -> Self {
        if let WidgetDef::Slider { step: s, .. } = &mut self {
            *s = Some(step);
        }
        self
    }

    /// Set max height for scroll area
    pub fn with_max_height(mut self, height: f32) -> Self {
        if let WidgetDef::ScrollArea { max_height, .. } = &mut self {
            *max_height = Some(height);
        }
        self
    }

    /// Set collapsed state for group
    pub fn with_collapsed(mut self, collapsed: bool) -> Self {
        if let WidgetDef::Group { collapsed: c, .. } = &mut self {
            *c = collapsed;
        }
        self
    }

    /// Set selected index for dropdown or radio group
    pub fn with_selected(mut self, index: usize) -> Self {
        match &mut self {
            WidgetDef::Dropdown { selected, .. } => *selected = Some(index),
            WidgetDef::RadioGroup { selected, .. } => *selected = Some(index),
            _ => {}
        }
        self
    }

    /// Set horizontal layout for radio group
    pub fn with_horizontal(mut self, horizontal: bool) -> Self {
        if let WidgetDef::RadioGroup { horizontal: h, .. } = &mut self {
            *h = horizontal;
        }
        self
    }

    /// Set number of rows for text area
    pub fn with_rows(mut self, rows: u32) -> Self {
        if let WidgetDef::TextArea { rows: r, .. } = &mut self {
            *r = rows;
        }
        self
    }

    /// Set active tab index for tabs widget
    pub fn with_active(mut self, index: usize) -> Self {
        if let WidgetDef::Tabs { active, .. } = &mut self {
            *active = index;
        }
        self
    }

    /// Set range for drag value widget
    pub fn with_range(mut self, min: f64, max: f64) -> Self {
        if let WidgetDef::DragValue { min: mi, max: ma, .. } = &mut self {
            *mi = Some(min);
            *ma = Some(max);
        }
        self
    }

    /// Set speed for drag value widget
    pub fn with_speed(mut self, speed: f64) -> Self {
        if let WidgetDef::DragValue { speed: s, .. } = &mut self {
            *s = speed;
        }
        self
    }

    /// Set prefix for drag value widget
    pub fn with_prefix(mut self, prefix: impl Into<String>) -> Self {
        if let WidgetDef::DragValue { prefix: p, .. } = &mut self {
            *p = Some(prefix.into());
        }
        self
    }

    /// Set suffix for drag value widget
    pub fn with_suffix(mut self, suffix: impl Into<String>) -> Self {
        if let WidgetDef::DragValue { suffix: s, .. } = &mut self {
            *s = Some(suffix.into());
        }
        self
    }

    /// Set decimal places for drag value widget
    pub fn with_decimals(mut self, decimals: usize) -> Self {
        if let WidgetDef::DragValue { decimals: d, .. } = &mut self {
            *d = Some(decimals);
        }
        self
    }

    /// Set alpha channel display for color picker
    pub fn with_alpha(mut self, alpha: bool) -> Self {
        if let WidgetDef::ColorPicker { alpha: a, .. } = &mut self {
            *a = alpha;
        }
        self
    }

    /// Set new tab behavior for hyperlink
    pub fn with_new_tab(mut self, new_tab: bool) -> Self {
        if let WidgetDef::Hyperlink { new_tab: n, .. } = &mut self {
            *n = new_tab;
        }
        self
    }

    /// Set frame visibility for image button
    pub fn with_frame(mut self, frame: bool) -> Self {
        if let WidgetDef::ImageButton { frame: f, .. } = &mut self {
            *f = frame;
        }
        self
    }

    /// Set selected state for image button
    pub fn with_image_selected(mut self, selected: bool) -> Self {
        if let WidgetDef::ImageButton { selected: s, .. } = &mut self {
            *s = selected;
        }
        self
    }

    /// Set tint color for image button
    pub fn with_tint(mut self, tint: [u8; 4]) -> Self {
        if let WidgetDef::ImageButton { tint: t, .. } = &mut self {
            *t = Some(tint);
        }
        self
    }

    // ==================== Helper Methods ====================

    /// Get mutable reference to widget props
    fn props_mut(&mut self) -> &mut WidgetProps {
        match self {
            WidgetDef::Label { props, .. } => props,
            WidgetDef::Button { props, .. } => props,
            WidgetDef::TextInput { props, .. } => props,
            WidgetDef::Checkbox { props, .. } => props,
            WidgetDef::Slider { props, .. } => props,
            WidgetDef::ProgressBar { props, .. } => props,
            WidgetDef::Image { props, .. } => props,
            WidgetDef::Separator { props } => props,
            WidgetDef::Spacer { props, .. } => props,
            WidgetDef::HBox { props, .. } => props,
            WidgetDef::VBox { props, .. } => props,
            WidgetDef::Grid { props, .. } => props,
            WidgetDef::Panel { props, .. } => props,
            WidgetDef::ScrollArea { props, .. } => props,
            WidgetDef::Group { props, .. } => props,
            WidgetDef::Dropdown { props, .. } => props,
            WidgetDef::RadioGroup { props, .. } => props,
            WidgetDef::TextArea { props, .. } => props,
            WidgetDef::Tabs { props, .. } => props,
            WidgetDef::Link { props, .. } => props,
            WidgetDef::SelectableLabel { props, .. } => props,
            WidgetDef::DragValue { props, .. } => props,
            WidgetDef::ColorPicker { props, .. } => props,
            WidgetDef::Hyperlink { props, .. } => props,
            WidgetDef::ImageButton { props, .. } => props,
        }
    }

    /// Get immutable reference to widget props
    pub fn props(&self) -> &WidgetProps {
        match self {
            WidgetDef::Label { props, .. } => props,
            WidgetDef::Button { props, .. } => props,
            WidgetDef::TextInput { props, .. } => props,
            WidgetDef::Checkbox { props, .. } => props,
            WidgetDef::Slider { props, .. } => props,
            WidgetDef::ProgressBar { props, .. } => props,
            WidgetDef::Image { props, .. } => props,
            WidgetDef::Separator { props } => props,
            WidgetDef::Spacer { props, .. } => props,
            WidgetDef::HBox { props, .. } => props,
            WidgetDef::VBox { props, .. } => props,
            WidgetDef::Grid { props, .. } => props,
            WidgetDef::Panel { props, .. } => props,
            WidgetDef::ScrollArea { props, .. } => props,
            WidgetDef::Group { props, .. } => props,
            WidgetDef::Dropdown { props, .. } => props,
            WidgetDef::RadioGroup { props, .. } => props,
            WidgetDef::TextArea { props, .. } => props,
            WidgetDef::Tabs { props, .. } => props,
            WidgetDef::Link { props, .. } => props,
            WidgetDef::SelectableLabel { props, .. } => props,
            WidgetDef::DragValue { props, .. } => props,
            WidgetDef::ColorPicker { props, .. } => props,
            WidgetDef::Hyperlink { props, .. } => props,
            WidgetDef::ImageButton { props, .. } => props,
        }
    }

    /// Get the widget ID if set
    pub fn id(&self) -> Option<&WidgetId> {
        self.props().id.as_ref()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_label_creation() {
        let label = WidgetDef::label("Hello");
        if let WidgetDef::Label { text, props } = label {
            assert_eq!(text, "Hello");
            assert!(props.visible);
            assert!(props.enabled);
        } else {
            panic!("Expected Label widget");
        }
    }

    #[test]
    fn test_button_with_id() {
        let button = WidgetDef::button("Click").with_id("btn1");
        assert_eq!(button.id(), Some(&"btn1".to_string()));
    }

    #[test]
    fn test_vbox_with_spacing() {
        let vbox =
            WidgetDef::vbox(vec![WidgetDef::label("A"), WidgetDef::label("B")]).with_spacing(10.0);

        if let WidgetDef::VBox { spacing, children, .. } = vbox {
            assert_eq!(spacing, 10.0);
            assert_eq!(children.len(), 2);
        } else {
            panic!("Expected VBox widget");
        }
    }

    #[test]
    fn test_text_input_with_placeholder() {
        let input = WidgetDef::text_input().with_placeholder("Enter name").with_password(false);

        if let WidgetDef::TextInput { placeholder, password, .. } = input {
            assert_eq!(placeholder, Some("Enter name".to_string()));
            assert!(!password);
        } else {
            panic!("Expected TextInput widget");
        }
    }

    #[test]
    fn test_nested_layout() {
        let ui = WidgetDef::vbox(vec![
            WidgetDef::label("Title"),
            WidgetDef::hbox(vec![WidgetDef::button("OK"), WidgetDef::button("Cancel")]),
        ]);

        if let WidgetDef::VBox { children, .. } = ui {
            assert_eq!(children.len(), 2);
            assert!(matches!(children[0], WidgetDef::Label { .. }));
            assert!(matches!(children[1], WidgetDef::HBox { .. }));
        } else {
            panic!("Expected VBox widget");
        }
    }
}