euv-ui 0.47.1

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
use super::*;

/// Declarative `#[component]` implementation for `EuvTag`.
#[component]
/// Inherent implementation of [`EuvTag`].
impl EuvTag {
    /// Renders `EuvTag` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let ctx: Context = current_context();
        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let (accent, _): (Color, Color) = self.get_tone().colors(p);
        let muted_surface: SurfaceColors = p.surface(SurfaceRole::Muted);
        let border_col: Color = if self.get_tone() == EuvTone::Neutral {
            p.get_border()
        } else {
            accent
        };
        let Self { label, .. } = self;
        let mut row_st: Style = Style::default();
        row_st
            .get_mut_layout()
            .set_flex_direction(FlexDirection::Row)
            .set_height(Length::Px(24.0))
            .set_justify_content(JustifyContent::Center)
            .set_align_items(AlignItems::Center)
            .set_padding(Edges::symmetric(0.0, SPACE_SM))
            .set_overflow(Overflow::Hidden);
        row_st
            .get_mut_paint()
            .set_background(Some(muted_surface.get_bg()))
            .set_border(Border::new(g.get_border_width().max(0.0), border_col))
            .set_radius(CornerRadius::all(RADIUS_PILL));
        let mut txt_st: Style = Style::default();
        txt_st
            .get_mut_text()
            .set_font_size(12.0)
            .set_weight(FontWeight::Medium)
            .set_color(muted_surface.get_fg())
            .set_align(TextAlign::Center)
            .set_overflow(TextOverflow::Ellipsis);
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                let root: NodeId = tree.create_view(row_st);
                let txt_id: NodeId = tree.create_text(label.clone(), txt_st);
                tree.append_child(root, txt_id);
                root
            },
            NodeId::default(),
        )
    }
}

/// Declarative `#[component]` implementation for `EuvAvatar`.
#[component]
/// Inherent implementation of [`EuvAvatar`].
impl EuvAvatar {
    /// Renders `EuvAvatar` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let ctx: Context = current_context();
        let p: ThemePalette = live_tokens_untracked(self.get_tokens()).get_palette();
        let primary_surface: SurfaceColors = p.surface(SurfaceRole::Primary);
        let sz: f32 = self.get_size();
        let Self { initials, .. } = self;
        let mut row_st: Style = Style::default();
        row_st
            .get_mut_layout()
            .set_flex_direction(FlexDirection::Row)
            .set_width(Length::Px(sz))
            .set_height(Length::Px(sz))
            .set_justify_content(JustifyContent::Center)
            .set_align_items(AlignItems::Center)
            .set_overflow(Overflow::Hidden);
        row_st
            .get_mut_paint()
            .set_background(Some(primary_surface.get_bg()))
            .set_radius(CornerRadius::all(RADIUS_PILL));
        let mut txt_st: Style = Style::default();
        txt_st
            .get_mut_text()
            .set_font_size((sz * 0.42).max(10.0))
            .set_weight(FontWeight::Bold)
            .set_color(primary_surface.get_fg())
            .set_align(TextAlign::Center);
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                let root: NodeId = tree.create_view(row_st);
                let txt_id: NodeId = tree.create_text(initials.clone(), txt_st);
                tree.append_child(root, txt_id);
                root
            },
            NodeId::default(),
        )
    }
}

/// Vector glyph constructor for `EuvIcon`.
impl EuvIcon {
    /// Creates a crisp native vector `EuvIcon` rendered directly via `DisplayList` primitives.
    ///
    /// # Arguments
    ///
    /// - `EuvIconName` - Built-in vector glyph variant.
    /// - `f32` - Square icon box size in logical pixels.
    /// - `Color` - Foreground stroke color.
    ///
    /// # Returns
    ///
    /// - `Self` - Vector icon descriptor.
    #[must_use]
    pub fn vector(icon: EuvIconName, size: f32, color: Color) -> Self {
        Self {
            symbol: String::new(),
            size,
            color,
            icon: Some(icon),
        }
    }
}

/// Declarative `#[component]` implementation for `EuvIcon`.
#[component]
/// Inherent implementation of [`EuvIcon`].
impl EuvIcon {
    /// Renders `EuvIcon` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let ctx: Context = current_context();
        let sz: f32 = self.get_size();
        let color: Color = self.get_color();
        let mount_tokens: ThemeTokens = live_tokens_untracked(ThemeTokens::default());
        if let Some(icon_name) = self.get_icon() {
            let paint_icon = move |bounds: Rect, dl: &mut DisplayList| {
                let live_tok: ThemeTokens = live_tokens_untracked(mount_tokens);
                let resolved_color: Color = remap_theme_color(color, mount_tokens, live_tok);
                draw_euv_icon(icon_name, bounds, dl, resolved_color);
            };
            return view! {
                canvas {
                    style: {
                        width: Length::Px(sz)
                        height: Length::Px(sz)
                    }
                    painter: paint_icon
                }
            };
        }
        let Self { symbol, .. } = self;
        let mut row_st: Style = Style::default();
        row_st
            .get_mut_layout()
            .set_flex_direction(FlexDirection::Row)
            .set_width(Length::Px(sz))
            .set_height(Length::Px(sz))
            .set_justify_content(JustifyContent::Center)
            .set_align_items(AlignItems::Center);
        let mut txt_st: Style = Style::default();
        txt_st
            .get_mut_text()
            .set_font_size(sz * 0.78)
            .set_weight(FontWeight::SemiBold)
            .set_color(color);
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                let root: NodeId = tree.create_view(row_st);
                let txt_id: NodeId = tree.create_text(symbol.clone(), txt_st);
                tree.append_child(root, txt_id);
                root
            },
            NodeId::default(),
        )
    }
}

/// Declarative `#[component]` implementation for `EuvKbd`.
#[component]
/// Inherent implementation of [`EuvKbd`].
impl EuvKbd {
    /// Renders `EuvKbd` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let ctx: Context = current_context();
        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let muted_surface: SurfaceColors = p.surface(SurfaceRole::Muted);
        let Self { key, .. } = self;
        let mut row_st: Style = Style::default();
        row_st
            .get_mut_layout()
            .set_flex_direction(FlexDirection::Row)
            .set_justify_content(JustifyContent::Center)
            .set_align_items(AlignItems::Center)
            .set_padding(Edges::symmetric(2.0, 6.0))
            .set_overflow(Overflow::Hidden);
        row_st
            .get_mut_paint()
            .set_background(Some(muted_surface.get_bg()))
            .set_border(Border::new(g.get_border_width().max(0.0), p.get_border()))
            .set_radius(CornerRadius::all(g.get_radius_sm().max(0.0)));
        let mut txt_st: Style = Style::default();
        txt_st
            .get_mut_text()
            .set_family(FontFamily::Monospace)
            .set_font_size(11.0)
            .set_color(muted_surface.get_fg())
            .set_align(TextAlign::Center)
            .set_overflow(TextOverflow::Clip);
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                let root: NodeId = tree.create_view(row_st);
                let txt_id: NodeId = tree.create_text(key.clone(), txt_st);
                tree.append_child(root, txt_id);
                root
            },
            NodeId::default(),
        )
    }
}

/// Declarative `#[component]` implementation for `EuvTypography`.
#[component]
/// Inherent implementation of [`EuvTypography`].
impl EuvTypography {
    /// Renders `EuvTypography` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let variant: EuvTypographyVariant = self.get_variant();
        let Self { text, .. } = self;
        let mut style: Style = Style::default();
        let ts: &mut TextStyle = style.get_mut_text();
        match variant {
            EuvTypographyVariant::H1 => {
                ts.set_font_size(g.get_font_title())
                    .set_weight(FontWeight::Bold)
                    .set_color(p.get_foreground());
            }
            EuvTypographyVariant::H2 => {
                ts.set_font_size(g.get_font_heading())
                    .set_weight(FontWeight::Bold)
                    .set_color(p.get_foreground());
            }
            EuvTypographyVariant::H3 => {
                ts.set_font_size(15.0)
                    .set_weight(FontWeight::SemiBold)
                    .set_color(p.get_foreground());
            }
            EuvTypographyVariant::Body => {
                ts.set_font_size(g.get_font_body())
                    .set_color(p.get_foreground());
            }
            EuvTypographyVariant::Caption => {
                ts.set_font_size(12.0).set_color(p.get_muted_foreground());
            }
        }
        view! {
            text {
                style: style
                { text.as_str() }
            }
        }
    }
}

/// Declarative `#[component]` implementation for `EuvEmpty`.
#[component]
/// Inherent implementation of [`EuvEmpty`].
impl EuvEmpty {
    /// Renders `EuvEmpty` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let Self {
            title, description, ..
        } = self;
        view! {
            column {
                style: {
                    width: Length::Percent(100.0)
                    align: AlignItems::Center
                    padding: Edges::all(SPACE_2XL)
                    gap: SPACE_SM
                    border: (g.get_border_width(), p.get_border())
                    radius: g.get_radius_lg()
                    overflow: Overflow::Hidden
                }
                text {
                    style: {
                        font_size: 20.0
                        color: p.get_muted_foreground()
                    }
                    { EMPTY_ICON_GLYPH }
                }
                text {
                    style: {
                        width: Length::Percent(100.0)
                        font_size: 15.0
                        font_weight: FontWeight::SemiBold
                        color: p.get_foreground()
                        text_align: TextAlign::Center
                    }
                    { title.as_str() }
                }
                text {
                    style: {
                        width: Length::Percent(100.0)
                        font_size: 13.0
                        color: p.get_muted_foreground()
                        text_align: TextAlign::Center
                    }
                    { description.as_str() }
                }
            }
        }
    }
}

/// Declarative `#[component]` implementation for `EuvSkeleton`.
#[component]
/// Inherent implementation of [`EuvSkeleton`].
impl EuvSkeleton {
    /// Renders `EuvSkeleton` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let live_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = live_tok.get_palette();
        let g: ThemeGeometry = live_tok.get_geometry();
        let w: f32 = self.get_width();
        let h: f32 = self.get_height();
        view! {
            view {
                style: {
                    width: Length::Px(w)
                    max_width: Length::Percent(100.0)
                    height: Length::Px(h)
                    background: p.get_secondary()
                    radius: g.get_radius_sm()
                }
            }
        }
    }
}

/// Declarative `#[component]` implementation for `EuvSpinner`.
#[component]
/// Inherent implementation of [`EuvSpinner`].
impl EuvSpinner {
    /// Renders `EuvSpinner` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let base_tokens: ThemeTokens = self.get_tokens();
        let sz: f32 = self.get_size();
        let paint_spinner = move |bounds: Rect, dl: &mut DisplayList| {
            let primary: Color = live_tokens_untracked(base_tokens)
                .get_palette()
                .get_primary();
            let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
            let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
            let outer_r: f32 = (bounds.get_width().min(bounds.get_height()) * 0.42).max(4.0);
            let inner_r: f32 = outer_r * 0.56;
            let stroke_w: f32 = (outer_r * 0.24).clamp(1.6, 3.2);
            for &(cos_a, sin_a, alpha) in SPINNER_SPOKES.iter() {
                dl.push(DrawCommand::Line {
                    from: Point::new(cx + cos_a * inner_r, cy + sin_a * inner_r),
                    to: Point::new(cx + cos_a * outer_r, cy + sin_a * outer_r),
                    color: primary.multiply_alpha(alpha),
                    width: stroke_w,
                });
            }
        };
        view! {
            canvas {
                style: {
                    width: Length::Px(sz)
                    height: Length::Px(sz)
                    radius: RADIUS_PILL
                }
                painter: paint_spinner
            }
        }
    }
}

/// Declarative `#[component]` implementation for `EuvTimeline`.
#[component]
/// Inherent implementation of [`EuvTimeline`].
impl EuvTimeline {
    /// Renders `EuvTimeline` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let p: ThemePalette = live_tokens_untracked(self.get_tokens()).get_palette();
        let Self { items, .. } = self;
        view! {
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_MD
                }
                for item in items.iter() {
                    row {
                        style: {
                            width: Length::Percent(100.0)
                            gap: SPACE_MD
                        }
                        view {
                            style: {
                                width: Length::Px(10.0)
                                height: Length::Px(10.0)
                                flex_shrink: 0.0
                                background: p.get_primary()
                                radius: RADIUS_PILL
                            }
                        }
                        column {
                            style: {
                                flex_grow: 1.0
                                flex_shrink: 1.0
                                min_width: Length::Px(0.0)
                                gap: 2.0
                            }
                            text {
                                style: {
                                    width: Length::Percent(100.0)
                                    font_size: 14.0
                                    font_weight: FontWeight::SemiBold
                                    color: p.get_foreground()
                                }
                                { item.get_title().as_str() }
                            }
                            text {
                                style: {
                                    width: Length::Percent(100.0)
                                    font_size: 11.0
                                    color: p.get_muted_foreground()
                                }
                                { item.get_timestamp().as_str() }
                            }
                            text {
                                style: {
                                    width: Length::Percent(100.0)
                                    font_size: 13.0
                                    color: p.get_muted_foreground()
                                }
                                { item.get_detail().as_str() }
                            }
                        }
                    }
                }
            }
        }
    }
}

/// Declarative `#[component]` implementation for `EuvList`.
#[component]
/// Inherent implementation of [`EuvList`].
impl EuvList {
    /// Renders `EuvList` into the ambient framework-managed `Context`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let Self { items, .. } = self;
        view! {
            column {
                style: {
                    width: Length::Percent(100.0)
                    background: p.get_card()
                    border: (g.get_border_width(), p.get_border())
                    radius: g.get_radius_md()
                    overflow: Overflow::Hidden
                }
                for (idx, item) in items.iter().enumerate() {
                    if idx > 0 {
                        view {
                            style: {
                                width: Length::Percent(100.0)
                                height: Length::Px(g.get_border_width().max(1.0))
                                background: p.get_border()
                            }
                        }
                    }
                    row {
                        style: {
                            width: Length::Percent(100.0)
                            padding: Edges::symmetric(SPACE_SM, SPACE_MD)
                            overflow: Overflow::Hidden
                        }
                        text {
                            style: {
                                width: Length::Percent(100.0)
                                font_size: 13.0
                                color: p.get_foreground()
                            }
                            { item.as_str() }
                        }
                    }
                }
            }
        }
    }
}

/// Builder, state-color helpers, and recursive rendering methods for `EuvTree`.
impl EuvTree {
    /// Resolves `(row_bg, label_fg)` colors for a tree row under `palette` and `is_selected`.
    ///
    /// # Arguments
    ///
    /// - `ThemePalette` - Live theme palette.
    /// - `bool` - Whether the tree row is selected.
    ///
    /// # Returns
    ///
    /// - `(Color, Color)` - Contrast-safe row background and label foreground colors.
    #[must_use]
    pub fn row_colors(palette: ThemePalette, is_selected: bool) -> (Color, Color) {
        if is_selected {
            let surface: SurfaceColors = palette.surface(SurfaceRole::Accent);
            (surface.get_bg(), surface.get_fg())
        } else {
            let card_surface: SurfaceColors = palette.surface(SurfaceRole::Card);
            (COLOR_TRANSPARENT, card_surface.get_fg())
        }
    }

    /// Binds an optional controlled signal receiving the most recently selected tree node label.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source tree component.
    /// - `Signal<Option<String>>` - Selected node label signal.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated interactive tree.
    #[must_use]
    pub fn selected(mut self, selected: Signal<Option<String>>) -> Self {
        self.set_selected(Some(selected));
        self
    }

    /// Recursively builds interactive indented tree row nodes for `nodes`.
    ///
    /// # Arguments
    ///
    /// - `&[EuvTreeNode]` - Sibling tree nodes.
    /// - `usize` - Current indentation depth.
    /// - `(ThemePalette, ThemeGeometry)` - Active theme palette and geometry.
    /// - `Option<Signal<Option<String>>>` - Optional active selection signal.
    /// - `Option<&str>` - Initial selected label snapshot for first-paint styling.
    /// - `&mut Vec<(NodeId, NodeId, String)>` - Collector of `(row_node, label_node, label)` tuples for O(1) selector binding.
    ///
    /// # Returns
    ///
    /// - `Vec<NodeId>` - Mounted sibling tree nodes ready for spread attachment.
    fn build_branch(
        nodes: &[EuvTreeNode],
        depth: usize,
        theme: (ThemePalette, ThemeGeometry),
        selected: Option<Signal<Option<String>>>,
        init_selected: Option<&str>,
        bound_rows: &mut Vec<(NodeId, NodeId, String)>,
    ) -> Vec<NodeId> {
        let (palette, geom): (ThemePalette, ThemeGeometry) = theme;
        let row_radius: f32 = concentric_radius(geom.get_radius_lg(), CONTROL_INSET);
        let mut out: Vec<NodeId> = Vec::with_capacity(nodes.len() * 2);
        for node in nodes.iter() {
            let has_children: bool = !node.get_children().is_empty();
            let expanded: Signal<bool> = Signal::new(true);
            let indent: f32 = (depth as f32) * 16.0;
            let label_str: &str = node.get_label().as_str();
            let lbl_click: String = node.get_label().clone();
            let is_init_sel: bool = init_selected == Some(label_str);
            let (init_bg, init_fg): (Color, Color) = Self::row_colors(palette, is_init_sel);
            let on_row_click = move |_: &UiEvent| {
                if has_children {
                    let _: bool = expanded.update(|v: &mut bool| *v = !*v);
                }
                if let Some(sel_sig) = selected {
                    let _: bool = sel_sig.set_if_changed(Some(lbl_click.clone()));
                }
            };
            let label_node: NodeId = if has_children {
                let lbl_for_txt: String = node.get_label().clone();
                let branch_label = move || -> String {
                    let pfx: &str = if expanded.get() {
                        TREE_EXPAND_PREFIX
                    } else {
                        TREE_COLLAPSED_PREFIX
                    };
                    format!("{pfx}{lbl_for_txt}")
                };
                view! {
                    text {
                        style: {
                            flex_grow: 1.0
                            flex_shrink: 1.0
                            min_width: Length::Px(0.0)
                            font_size: 13.0
                            font_weight: FontWeight::Medium
                            color: init_fg
                        }
                        { branch_label }
                    }
                }
            } else {
                let leaf_label: String = format!("{TREE_LEAF_PREFIX}{label_str}");
                view! {
                    text {
                        style: {
                            flex_grow: 1.0
                            flex_shrink: 1.0
                            min_width: Length::Px(0.0)
                            font_size: 13.0
                            color: init_fg
                        }
                        { leaf_label }
                    }
                }
            };
            let row: NodeId = view! {
                row {
                    style: {
                        width: Length::Percent(100.0)
                        min_height: Length::Px(geom.get_control_sm())
                        align: AlignItems::Center
                        padding: Edges::new(SPACE_XS, SPACE_SM, SPACE_XS, SPACE_SM + indent)
                        radius: row_radius
                        background: init_bg
                        overflow: Overflow::Hidden
                        cursor: CursorIcon::Pointer
                    }
                    on_click: on_row_click
                    { label_node }
                }
            };
            if selected.is_some() {
                bound_rows.push((row, label_node, node.get_label().clone()));
            }
            out.push(row);
            if has_children {
                let child_nodes: Vec<NodeId> = Self::build_branch(
                    node.get_children(),
                    depth + 1,
                    theme,
                    selected,
                    init_selected,
                    bound_rows,
                );
                let mut branch_base: Style = Style::default();
                branch_base
                    .get_mut_layout()
                    .set_flex_direction(FlexDirection::Column)
                    .set_width(Length::Percent(100.0))
                    .set_row_gap(CONTROL_INSET)
                    .set_column_gap(CONTROL_INSET);
                let branch_style = move || -> Style {
                    let mut st: Style = branch_base;
                    st.get_mut_layout().set_display(if expanded.get() {
                        Display::Flex
                    } else {
                        Display::None
                    });
                    st
                };
                let branch_box: NodeId = view! {
                    column {
                        bind_style: branch_style
                        ..child_nodes
                    }
                };
                out.push(branch_box);
            }
        }
        out
    }
}

/// Declarative `#[component]` implementation for `EuvTree`.
#[component]
/// Inherent implementation of [`EuvTree`].
impl EuvTree {
    /// Renders `EuvTree` into the ambient framework-managed `Context`.
    ///
    /// Selected rows and their labels are theme-owned and repainted from `use_live_tokens()` with contrast-safe
    /// `SurfaceRole::Accent` pairing so selection state stays crisp across live theme switches.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor reference.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let base_tokens: ThemeTokens = self.get_tokens();
        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
        let p: ThemePalette = init_tok.get_palette();
        let g: ThemeGeometry = init_tok.get_geometry();
        let Self {
            roots, selected, ..
        } = self;
        let init_selected: Option<String> =
            selected.and_then(|sig: Signal<Option<String>>| sig.get_untracked());
        let mut bound_rows: Vec<(NodeId, NodeId, String)> = Vec::new();
        let branch_nodes: Vec<NodeId> = Self::build_branch(
            roots,
            0,
            (p, g),
            *selected,
            init_selected.as_deref(),
            &mut bound_rows,
        );
        let root: NodeId = view! {
            column {
                style: {
                    width: Length::Percent(100.0)
                    padding: Edges::all(CONTROL_INSET)
                    gap: CONTROL_INSET
                    background: p.get_card()
                    border: (g.get_border_width(), p.get_border())
                    radius: g.get_radius_lg()
                    overflow: Overflow::Hidden
                }
                ..branch_nodes
            }
        };
        if let Some(sel_sig) = *selected
            && !bound_rows.is_empty()
        {
            let ctx: Context = current_context();
            let scene: SceneHandle = ctx.get_scene().clone();
            let owned_nodes: Vec<NodeId> = bound_rows
                .iter()
                .flat_map(|&(row_id, lbl_id, _): &(NodeId, NodeId, String)| [row_id, lbl_id])
                .collect();
            let init_key: ThemeKey = init_tok.key();
            let (tree_scope, _): (Scope, ()) = Scope::run(|_: Scope| {
                let sel: Rc<Selector<Option<String>>> =
                    Rc::new(Selector::new(move || sel_sig.get()));
                let sel_cleanup: Rc<Selector<Option<String>>> = Rc::clone(&sel);
                on_cleanup(move || {
                    sel_cleanup.dispose();
                });
                for (row_node, label_node, lbl_cmp) in bound_rows.into_iter() {
                    let sel_row: Rc<Selector<Option<String>>> = Rc::clone(&sel);
                    let scene_row: SceneHandle = scene.clone();
                    let init_is_sel: bool = init_selected.as_deref() == Some(lbl_cmp.as_str());
                    let prev_state: Cell<(bool, ThemeKey)> = Cell::new((init_is_sel, init_key));
                    let _: Effect = Effect::new(move || {
                        let is_sel: bool = sel_row.is_selected(Some(lbl_cmp.clone()));
                        let live_tok: ThemeTokens = use_live_tokens(base_tokens);
                        let (prev_sel, prev_key): (bool, ThemeKey) =
                            prev_state.replace((is_sel, live_tok.key()));
                        if prev_sel == is_sel && prev_key == live_tok.key() {
                            return;
                        }
                        let (bg, fg): (Color, Color) =
                            Self::row_colors(live_tok.get_palette(), is_sel);
                        scene_row.with_write(
                            |tree: &mut SceneTree| {
                                if let Some(node) = tree.get_node_mut(row_node) {
                                    node.get_mut_style()
                                        .get_mut_paint()
                                        .set_background(Some(bg));
                                    tree.mark_dirty(row_node, DIRTY_PAINT);
                                }
                                if let Some(node) = tree.get_node_mut(label_node) {
                                    node.get_mut_style().get_mut_text().set_color(fg);
                                    tree.mark_dirty(label_node, DIRTY_PAINT);
                                }
                            },
                            (),
                        );
                    });
                }
            });
            ctx.get_scene().with_write(
                |tree: &mut SceneTree| {
                    mark_theme_owned(tree, owned_nodes.as_slice());
                    tree.attach_scope(root, tree_scope);
                },
                (),
            );
        }
        root
    }
}