mgui-core 0.1.0

mgui 框架核心:Element/RenderObject/Widget 三树、布局与绘制协议、帧管线与响应式原语
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
//! 阶段 4-A:Theme + Direction — 第一个 InheritedWidget 用例
//!
//! 设计文档 § 6 + § 19.Theme:全局视觉风格沿树向下传递。
//!
//! ```ignore
//! ThemeWidget::new(ThemeData::dark())
//!     .direction(Direction::Ltr)
//!     .child(MyApp())
//! ```
//!
//! 任何后代 widget 在 `state.build(ctx)` 中调 `ctx.depend_on::<ThemeWidget>()` 或
//! 便捷的 `ctx.theme()` / `ctx.direction()` 拿当前主题。

use crate::inherited::InheritedWidget;
use crate::widget::{Widget, WidgetNode};
use crate::{Color, Point, Size};
use std::any::Any;
use std::rc::Rc;

// =================================================================
// ThemeData — 纯数据,无 Widget 概念
// =================================================================

/// Text style defaults (theme-level).
/// Individual TextWidget can override via TextStyle.
#[derive(Debug, Clone, PartialEq)]
pub struct TextTheme {
    pub headline: TextStyleTheme,
    pub title: TextStyleTheme,
    pub body: TextStyleTheme,
    pub caption: TextStyleTheme,
}

#[derive(Debug, Clone, PartialEq)]
pub struct TextStyleTheme {
    pub font_size: f32,
    pub color: Color,
}

/// Button style defaults.
#[derive(Debug, Clone, PartialEq)]
pub struct ButtonStyle {
    pub background: Color,
    pub foreground: Color,
    pub radius: f32,
    pub focus_ring_color: Color,
    pub focus_ring_width: f32,
}

/// Scrollbar style defaults (ListView + ScrollView).
#[derive(Debug, Clone, PartialEq)]
pub struct ScrollbarStyle {
    pub thumb_color: Color,
    /// 指针悬停(或拖拽中)在 thumb 上时的高亮色
    pub thumb_hover_color: Color,
    pub thumb_radius: f32,
    pub thumb_width: f32,       // paint width (hit area is +2px)
    pub hit_width: f32,         // hit test area width
    pub thumb_min_size: f32,    // min thumb size in main axis px
    pub thumb_track_ratio: f32, // thumb_main = viewport_main * ratio
}

/// TextField / 输入框样式(IDEA 风格:无边框底色 + 焦点蓝边)。
#[derive(Debug, Clone, PartialEq)]
pub struct InputStyle {
    pub background: Color,
    pub border: Color,
    pub focused_border: Color,
    pub text_color: Color,
    pub placeholder_color: Color,
    pub radius: f32,
}

/// Tooltip 浮层样式。
#[derive(Debug, Clone, PartialEq)]
pub struct TooltipStyle {
    pub background: Color,
    pub foreground: Color,
    pub border: Color,
    pub radius: f32,
}

/// 菜单 / 右键 ContextMenu / 下拉列表样式。
#[derive(Debug, Clone, PartialEq)]
pub struct MenuStyle {
    pub background: Color,
    pub foreground: Color,
    pub hover_background: Color,
    pub border: Color,
    pub radius: f32,
}

/// TabBar / TabView / TabbedPane 样式。
#[derive(Debug, Clone, PartialEq)]
pub struct TabStyle {
    pub background: Color,
    pub active_foreground: Color,
    pub inactive_foreground: Color,
    pub hover_background: Color,
    pub indicator_color: Color,
}

/// NavigationMenu 样式。
#[derive(Debug, Clone, PartialEq)]
pub struct NavStyle {
    pub active_background: Color,
    pub active_foreground: Color,
    pub foreground: Color,
    pub hover_background: Color,
    pub indicator_color: Color,
}

/// 反馈类组件样式(进度条 / Toast 等)。
#[derive(Debug, Clone, PartialEq)]
pub struct FeedbackStyle {
    pub progress_track: Color,
    pub progress_value: Color,
    pub success: Color,
    pub warning: Color,
}

/// Dropdown 触发器 + 弹出面板样式。
#[derive(Debug, Clone, PartialEq)]
pub struct DropdownStyle {
    pub background: Color,
    pub foreground: Color,
    pub placeholder: Color,
    pub border: Color,
    pub open_border: Color,
    pub hover: Color,
    pub selected_background: Color,
    pub disabled: Color,
}

/// Dialog 遮罩 + 对话框样式。
#[derive(Debug, Clone, PartialEq)]
pub struct DialogStyle {
    pub barrier: Color,
    pub background: Color,
    pub radius: f32,
}

/// ListView / 列表类样式。
#[derive(Debug, Clone, PartialEq)]
pub struct ListStyle {
    pub hover_background: Color,
    pub selected_background: Color,
    pub foreground: Color,
}

/// 主题色板 + 子主题。
///
/// 所有 `update_should_notify` 走 `PartialEq` 派生自动比较。
///
/// 风格基准:**JetBrains IDEA New UI**(`idea_dark()` / `idea_light()`),
/// `dark()` / `light()` 为同名别名。通用令牌(border / divider / hover)
/// 供全部组件共享,做到"一次改主题、全局换肤"。
#[derive(Debug, Clone, PartialEq)]
pub struct ThemeData {
    // --- ColorScheme (core) ---
    pub background: Color,
    pub foreground: Color,
    pub primary: Color,
    pub accent: Color,
    pub surface: Color,
    pub error: Color,

    // --- 通用令牌(全组件共享) ---
    pub border: Color,    // 组件描边
    pub divider: Color,   // Divider / 分隔线
    pub hover: Color,     // hover 覆盖层(带 alpha)
    pub disabled: Color,  // 禁用态前景(或带 alpha 覆盖)
    pub selection: Color, // 文本/列表选中背景(primary 系 alpha)
    pub icon: Color,      // 图标默认 tint

    // --- Radius ---
    pub radius_sm: f32, // 2.0 — checkbox / small pill
    pub radius_md: f32, // 4.0 — button / input(IDEA 小圆角)
    pub radius_lg: f32, // 8.0 — dialog / menu / large card

    // --- Spacing ---
    pub spacing: f32, // 8.0 — default widget spacing

    // --- Sub-themes ---
    pub text: TextTheme,
    pub button: ButtonStyle,
    pub scrollbar: ScrollbarStyle,
    pub input: InputStyle,
    pub tooltip: TooltipStyle,
    pub menu: MenuStyle,
    pub tab: TabStyle,
    pub nav: NavStyle,
    pub feedback: FeedbackStyle,
    pub dropdown: DropdownStyle,
    pub dialog: DialogStyle,
    pub list: ListStyle,
}

impl Default for ThemeData {
    fn default() -> Self {
        Self::idea_dark()
    }
}

impl ThemeData {
    /// JetBrains IDEA New UI — 深色(Darcula 系新 UI)。
    pub fn idea_dark() -> Self {
        let bg = Color::from_rgb8(43, 45, 48); // #2B2D30 主背景
        let fg = Color::from_rgb8(223, 225, 229); // #DFE1E5 前景文字
        let primary = Color::from_rgb8(84, 138, 247); // #548AF7 主强调蓝
        let accent = Color::from_rgb8(242, 197, 92); // #F2C55C 次强调(警告黄系)
        let surface = Color::from_rgb8(57, 59, 64); // #393B40 面板/浮层底
        let error = Color::from_rgb8(229, 87, 101); // #E55765
        let border = Color::from_rgb8(78, 81, 87); // #4E5157 描边
        let caption = Color::from_rgb8(157, 160, 168); // #9DA0A8 次要文字
        let text = TextTheme {
            headline: TextStyleTheme { font_size: 20.0, color: fg },
            title: TextStyleTheme { font_size: 15.0, color: fg },
            body: TextStyleTheme { font_size: 13.0, color: fg },
            caption: TextStyleTheme { font_size: 12.0, color: caption },
        };
        let button = ButtonStyle {
            background: primary,
            foreground: Color::WHITE,
            radius: 4.0,
            focus_ring_color: primary,
            focus_ring_width: 2.0,
        };
        let scrollbar = ScrollbarStyle {
            thumb_color: Color::rgba(0.55, 0.58, 0.63, 0.60),
            thumb_hover_color: Color::rgba(0.72, 0.75, 0.80, 0.90),
            thumb_radius: 4.0,
            thumb_width: 8.0,
            hit_width: 10.0,
            thumb_min_size: 24.0,
            thumb_track_ratio: 0.32,
        };
        let input = InputStyle {
            background: Color::from_rgb8(67, 69, 74), // #43454A
            border,
            focused_border: primary,
            text_color: fg,
            placeholder_color: Color::from_rgb8(126, 131, 140), // #7E838C
            radius: 4.0,
        };
        let tooltip = TooltipStyle { background: surface, foreground: fg, border, radius: 4.0 };
        let menu = MenuStyle {
            background: surface,
            foreground: fg,
            hover_background: Color::from_rgb8(74, 77, 82), // #4A4D52
            border,
            radius: 6.0,
        };
        let tab = TabStyle {
            background: bg,
            active_foreground: fg,
            inactive_foreground: caption,
            hover_background: Color::from_rgb8(62, 65, 70), // #3E4146
            indicator_color: primary,
        };
        let nav = NavStyle {
            active_background: Color::rgba(0.33, 0.54, 0.97, 0.18),
            active_foreground: primary,
            foreground: fg,
            hover_background: Color::from_rgb8(74, 77, 82),
            indicator_color: primary,
        };
        let feedback = FeedbackStyle {
            progress_track: Color::rgba(1.0, 1.0, 1.0, 0.15),
            progress_value: primary,
            success: Color::from_rgb8(54, 150, 86), // #369656
            warning: accent,
        };
        let dropdown = DropdownStyle {
            background: surface,
            foreground: fg,
            placeholder: Color::from_rgb8(126, 131, 140), // #7E838C
            border,
            open_border: primary,
            hover: Color::from_rgb8(74, 77, 82), // #4A4D52
            selected_background: Color::rgba(0.33, 0.54, 0.97, 0.22),
            disabled: Color::rgba(1.0, 1.0, 1.0, 0.35),
        };
        let dialog = DialogStyle { barrier: Color::rgba(0.0, 0.0, 0.0, 0.45), background: surface, radius: 8.0 };
        let list = ListStyle {
            hover_background: Color::rgba(1.0, 1.0, 1.0, 0.06),
            selected_background: Color::rgba(0.33, 0.54, 0.97, 0.22),
            foreground: fg,
        };
        Self {
            background: bg,
            foreground: fg,
            primary,
            accent,
            surface,
            error,
            border,
            divider: Color::from_rgb8(62, 65, 70), // #3E4146 — 在 #2B2D30 上清晰可辨
            hover: Color::rgba(1.0, 1.0, 1.0, 0.08),
            disabled: Color::rgba(1.0, 1.0, 1.0, 0.35),
            selection: Color::rgba(0.33, 0.54, 0.97, 0.28),
            icon: fg,
            radius_sm: 2.0,
            radius_md: 4.0,
            radius_lg: 8.0,
            spacing: 8.0,
            text,
            button,
            scrollbar,
            input,
            tooltip,
            menu,
            tab,
            nav,
            feedback,
            dropdown,
            dialog,
            list,
        }
    }

    /// JetBrains IDEA New UI — 浅色。
    pub fn idea_light() -> Self {
        let bg = Color::from_rgb8(255, 255, 255); // #FFFFFF
        let fg = Color::from_rgb8(31, 31, 31); // #1F1F1F
        let primary = Color::from_rgb8(53, 116, 240); // #3574F0
        let accent = Color::from_rgb8(232, 163, 61); // #E8A33D
        let surface = Color::from_rgb8(247, 248, 250); // #F7F8FA 面板底
        let error = Color::from_rgb8(229, 87, 101); // #E55765
        let border = Color::from_rgb8(201, 204, 214); // #C9CCD6
        let caption = Color::from_rgb8(140, 140, 140); // #8C8C8C
        let text = TextTheme {
            headline: TextStyleTheme { font_size: 20.0, color: fg },
            title: TextStyleTheme { font_size: 15.0, color: fg },
            body: TextStyleTheme { font_size: 13.0, color: fg },
            caption: TextStyleTheme { font_size: 12.0, color: caption },
        };
        let button = ButtonStyle {
            background: primary,
            foreground: Color::WHITE,
            radius: 4.0,
            focus_ring_color: primary,
            focus_ring_width: 2.0,
        };
        let scrollbar = ScrollbarStyle {
            thumb_color: Color::rgba(0.5, 0.55, 0.65, 0.55),
            thumb_hover_color: Color::rgba(0.35, 0.40, 0.50, 0.80),
            thumb_radius: 4.0,
            thumb_width: 8.0,
            hit_width: 10.0,
            thumb_min_size: 24.0,
            thumb_track_ratio: 0.32,
        };
        let input = InputStyle {
            background: Color::WHITE,
            border,
            focused_border: primary,
            text_color: fg,
            placeholder_color: Color::from_rgb8(154, 160, 166), // #9AA0A6
            radius: 4.0,
        };
        let tooltip = TooltipStyle { background: Color::from_rgb8(250, 251, 252), foreground: fg, border, radius: 4.0 };
        let menu = MenuStyle {
            background: Color::WHITE,
            foreground: fg,
            hover_background: Color::from_rgb8(235, 239, 245), // #EBEFF5
            border,
            radius: 6.0,
        };
        let tab = TabStyle {
            background: bg,
            active_foreground: fg,
            inactive_foreground: caption,
            hover_background: Color::from_rgb8(240, 242, 246), // #F0F2F6
            indicator_color: primary,
        };
        let nav = NavStyle {
            active_background: Color::rgba(0.21, 0.46, 0.94, 0.12),
            active_foreground: primary,
            foreground: fg,
            hover_background: Color::from_rgb8(240, 242, 246),
            indicator_color: primary,
        };
        let feedback = FeedbackStyle {
            progress_track: Color::rgba(0.0, 0.0, 0.0, 0.10),
            progress_value: primary,
            success: Color::from_rgb8(54, 150, 86),
            warning: Color::from_rgb8(237, 162, 0), // #EDA200
        };
        let dropdown = DropdownStyle {
            background: Color::WHITE,
            foreground: fg,
            placeholder: Color::from_rgb8(154, 160, 166), // #9AA0A6
            border,
            open_border: primary,
            hover: Color::from_rgb8(235, 239, 245), // #EBEFF5
            selected_background: Color::rgba(0.21, 0.46, 0.94, 0.12),
            disabled: Color::rgba(0.0, 0.0, 0.0, 0.35),
        };
        let dialog = DialogStyle { barrier: Color::rgba(0.0, 0.0, 0.0, 0.45), background: Color::WHITE, radius: 8.0 };
        let list = ListStyle {
            hover_background: Color::rgba(0.0, 0.0, 0.0, 0.04),
            selected_background: Color::rgba(0.21, 0.46, 0.94, 0.12),
            foreground: fg,
        };
        Self {
            background: bg,
            foreground: fg,
            primary,
            accent,
            surface,
            error,
            border,
            divider: Color::from_rgb8(213, 216, 222), // #D5D8DE — 在 #FFFFFF 上清晰可辨
            hover: Color::rgba(0.0, 0.0, 0.0, 0.05),
            disabled: Color::rgba(0.0, 0.0, 0.0, 0.35),
            selection: Color::rgba(0.21, 0.46, 0.94, 0.18),
            icon: fg,
            radius_sm: 2.0,
            radius_md: 4.0,
            radius_lg: 8.0,
            spacing: 8.0,
            text,
            button,
            scrollbar,
            input,
            tooltip,
            menu,
            tab,
            nav,
            feedback,
            dropdown,
            dialog,
            list,
        }
    }

    /// 深色主题 — IDEA New UI 风格(`idea_dark()` 别名)。
    pub fn dark() -> Self {
        Self::idea_dark()
    }

    /// 浅色主题 — IDEA New UI 风格(`idea_light()` 别名)。
    pub fn light() -> Self {
        Self::idea_light()
    }
}

// =================================================================
// Direction — 文本方向(Ltr / Rtl)
// =================================================================

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Direction {
    #[default]
    Ltr,
    Rtl,
}

// =================================================================
// ThemeWidget + InheritedWidget impl
// =================================================================

/// 用户显式颜色优先,否则回退到主题/token 值。
///
/// P1-8:用 `Option` 表达"未覆盖",不再依赖与默认色相等的 sentinel 判断
/// (用户显式选择与哨兵相同的颜色时也能正确覆盖)。
pub const fn resolve_color(explicit: Option<Color>, themed: Color) -> Color {
    match explicit {
        Some(color) => color,
        None => themed,
    }
}

/// 数值版 `resolve_color`:显式尺寸/宽度优先,否则用主题/回退值。
pub const fn resolve_f32(explicit: Option<f32>, themed: f32) -> f32 {
    match explicit {
        Some(value) => value,
        None => themed,
    }
}

/// Theme 提供者 widget。挂到树中,所有后代可通过 `ctx.theme()` 访问。
///
/// `theme` 用 `Rc` 共享:State 缓存主题时只 clone 引用,不再复制整份 ThemeData。
#[derive(Debug)]
pub struct ThemeWidget {
    pub theme: Rc<ThemeData>,
    pub direction: Direction,
    pub child: Option<WidgetNode>,
}

impl ThemeWidget {
    pub fn new(theme: ThemeData) -> Self {
        Self::from_rc(Rc::new(theme))
    }

    pub fn from_rc(theme: Rc<ThemeData>) -> Self {
        Self { theme, direction: Direction::Ltr, child: None }
    }

    pub fn dark() -> Self {
        Self::new(ThemeData::dark())
    }

    pub fn light() -> Self {
        Self::new(ThemeData::light())
    }

    pub fn with_direction(mut self, d: Direction) -> Self {
        self.direction = d;
        self
    }

    pub fn child(mut self, c: impl Widget) -> Self {
        self.child = Some(WidgetNode::new(c));
        self
    }

    pub fn child_node(mut self, c: WidgetNode) -> Self {
        self.child = Some(c);
        self
    }
}

impl InheritedWidget for ThemeWidget {
    fn update_should_notify(&self, old: &dyn InheritedWidget) -> bool {
        // downcast old 到 ThemeWidget 比较 theme + direction
        if let Some(old_theme) = old.as_any().downcast_ref::<ThemeWidget>() {
            if Rc::ptr_eq(&self.theme, &old_theme.theme) {
                return self.direction != old_theme.direction;
            }
            *self.theme != *old_theme.theme || self.direction != old_theme.direction
        } else {
            true
        }
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

impl ThemeWidget {
    pub fn theme(&self) -> &ThemeData {
        &self.theme
    }

    pub fn direction(&self) -> Direction {
        self.direction
    }
}

impl Widget for ThemeWidget {
    fn as_any(&self) -> &dyn Any {
        self
    }

    fn as_inherited(&self) -> Option<&dyn crate::inherited::InheritedWidget> {
        Some(self)
    }

    fn create_render_object(&self) -> Box<dyn crate::render_object::RenderObject> {
        // 透传 child RO,但必须**包一层 ProxyRenderObject**:
        // 直接把 child widget 的 RO 树当自己的 RO,会让 element 树(1 个 child)
        // 与 RO 树(child 的整棵子树)不同构;propagate 只能按索引替换前 N 个 slot,
        // 其余 slot 成为陈旧副本(Theme 根节点会重复绘制 nested boundary)。
        match &self.child {
            Some(c) => Box::new(crate::render_object::ProxyRenderObject::new(c.0.create_render_object())),
            None => Box::new(crate::render_object::RRectRenderObject::new(Size::ZERO, Color::TRANSPARENT, 0.0)),
        }
    }

    fn children(&self) -> Vec<WidgetNode> {
        self.child.clone().into_iter().collect()
    }

    fn children_with_positions(&self) -> Vec<(Point, WidgetNode)> {
        self.child.clone().into_iter().map(|c| (Point::ZERO, c)).collect()
    }
}

// =================================================================
// DirectionWidget — 单独暴露 direction(如果只想用 Direction 不想用 Theme)
// =================================================================

/// 单独的 Direction 提供者,方便只想换方向不换主题的场景。
#[derive(Debug)]
pub struct DirectionWidget {
    pub direction: Direction,
    pub child: Option<WidgetNode>,
}

impl DirectionWidget {
    pub fn new(d: Direction) -> Self {
        Self { direction: d, child: None }
    }

    pub fn child(mut self, c: impl Widget) -> Self {
        self.child = Some(WidgetNode::new(c));
        self
    }
}

impl InheritedWidget for DirectionWidget {
    fn update_should_notify(&self, old: &dyn InheritedWidget) -> bool {
        if let Some(old_dir) = old.as_any().downcast_ref::<DirectionWidget>() {
            self.direction != old_dir.direction
        } else {
            true
        }
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

impl DirectionWidget {
    pub fn direction(&self) -> Direction {
        self.direction
    }
}

impl Widget for DirectionWidget {
    fn as_any(&self) -> &dyn Any {
        self
    }

    fn as_inherited(&self) -> Option<&dyn crate::inherited::InheritedWidget> {
        Some(self)
    }

    fn create_render_object(&self) -> Box<dyn crate::render_object::RenderObject> {
        // 与 ThemeWidget 相同:透传 child 必须包 Proxy,保证 element/RO 同构。
        match &self.child {
            Some(c) => Box::new(crate::render_object::ProxyRenderObject::new(c.0.create_render_object())),
            None => Box::new(crate::render_object::RRectRenderObject::new(Size::ZERO, Color::TRANSPARENT, 0.0)),
        }
    }

    fn children(&self) -> Vec<WidgetNode> {
        self.child.clone().into_iter().collect()
    }

    fn children_with_positions(&self) -> Vec<(Point, WidgetNode)> {
        self.child.clone().into_iter().map(|c| (Point::ZERO, c)).collect()
    }
}