Skip to main content

euv_ui/component/data_display/
impl.rs

1use super::*;
2
3/// Declarative `#[component]` implementation for `EuvTag`.
4#[component]
5/// Inherent implementation of [`EuvTag`].
6impl EuvTag {
7    /// Renders `EuvTag` into the ambient framework-managed `Context`.
8    ///
9    /// # Arguments
10    ///
11    /// - `&Self` - Component descriptor reference.
12    ///
13    /// # Returns
14    ///
15    /// - `NodeId` - Mounted root scene node handle.
16    fn render(&self) -> NodeId {
17        let ctx: Context = current_context();
18        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
19        let p: ThemePalette = tokens.get_palette();
20        let g: ThemeGeometry = tokens.get_geometry();
21        let (accent, _): (Color, Color) = self.get_tone().colors(p);
22        let muted_surface: SurfaceColors = p.surface(SurfaceRole::Muted);
23        let border_col: Color = if self.get_tone() == EuvTone::Neutral {
24            p.get_border()
25        } else {
26            accent
27        };
28        let Self { label, .. } = self;
29        let mut row_st: Style = Style::default();
30        row_st
31            .get_mut_layout()
32            .set_flex_direction(FlexDirection::Row)
33            .set_height(Length::Px(24.0))
34            .set_justify_content(JustifyContent::Center)
35            .set_align_items(AlignItems::Center)
36            .set_padding(Edges::symmetric(0.0, SPACE_SM))
37            .set_overflow(Overflow::Hidden);
38        row_st
39            .get_mut_paint()
40            .set_background(Some(muted_surface.get_bg()))
41            .set_border(Border::new(g.get_border_width().max(0.0), border_col))
42            .set_radius(CornerRadius::all(RADIUS_PILL));
43        let mut txt_st: Style = Style::default();
44        txt_st
45            .get_mut_text()
46            .set_font_size(12.0)
47            .set_weight(FontWeight::Medium)
48            .set_color(muted_surface.get_fg())
49            .set_align(TextAlign::Center)
50            .set_overflow(TextOverflow::Ellipsis);
51        ctx.get_scene().with_write(
52            |tree: &mut SceneTree| {
53                let root: NodeId = tree.create_view(row_st);
54                let txt_id: NodeId = tree.create_text(label.clone(), txt_st);
55                tree.append_child(root, txt_id);
56                root
57            },
58            NodeId::default(),
59        )
60    }
61}
62
63/// Declarative `#[component]` implementation for `EuvAvatar`.
64#[component]
65/// Inherent implementation of [`EuvAvatar`].
66impl EuvAvatar {
67    /// Renders `EuvAvatar` into the ambient framework-managed `Context`.
68    ///
69    /// # Arguments
70    ///
71    /// - `&Self` - Component descriptor reference.
72    ///
73    /// # Returns
74    ///
75    /// - `NodeId` - Mounted root scene node handle.
76    fn render(&self) -> NodeId {
77        let ctx: Context = current_context();
78        let p: ThemePalette = live_tokens_untracked(self.get_tokens()).get_palette();
79        let primary_surface: SurfaceColors = p.surface(SurfaceRole::Primary);
80        let sz: f32 = self.get_size();
81        let Self { initials, .. } = self;
82        let mut row_st: Style = Style::default();
83        row_st
84            .get_mut_layout()
85            .set_flex_direction(FlexDirection::Row)
86            .set_width(Length::Px(sz))
87            .set_height(Length::Px(sz))
88            .set_justify_content(JustifyContent::Center)
89            .set_align_items(AlignItems::Center)
90            .set_overflow(Overflow::Hidden);
91        row_st
92            .get_mut_paint()
93            .set_background(Some(primary_surface.get_bg()))
94            .set_radius(CornerRadius::all(RADIUS_PILL));
95        let mut txt_st: Style = Style::default();
96        txt_st
97            .get_mut_text()
98            .set_font_size((sz * 0.42).max(10.0))
99            .set_weight(FontWeight::Bold)
100            .set_color(primary_surface.get_fg())
101            .set_align(TextAlign::Center);
102        ctx.get_scene().with_write(
103            |tree: &mut SceneTree| {
104                let root: NodeId = tree.create_view(row_st);
105                let txt_id: NodeId = tree.create_text(initials.clone(), txt_st);
106                tree.append_child(root, txt_id);
107                root
108            },
109            NodeId::default(),
110        )
111    }
112}
113
114/// Vector glyph constructor for `EuvIcon`.
115impl EuvIcon {
116    /// Creates a crisp native vector `EuvIcon` rendered directly via `DisplayList` primitives.
117    ///
118    /// # Arguments
119    ///
120    /// - `EuvIconName` - Built-in vector glyph variant.
121    /// - `f32` - Square icon box size in logical pixels.
122    /// - `Color` - Foreground stroke color.
123    ///
124    /// # Returns
125    ///
126    /// - `Self` - Vector icon descriptor.
127    #[must_use]
128    pub fn vector(icon: EuvIconName, size: f32, color: Color) -> Self {
129        Self {
130            symbol: String::new(),
131            size,
132            style: Some(Style::default().color(color)),
133            icon: Some(icon),
134        }
135    }
136}
137
138/// Declarative `#[component]` implementation for `EuvIcon`.
139#[component]
140/// Inherent implementation of [`EuvIcon`].
141impl EuvIcon {
142    /// Renders `EuvIcon` into the ambient framework-managed `Context`.
143    ///
144    /// # Arguments
145    ///
146    /// - `&Self` - Component descriptor reference.
147    ///
148    /// # Returns
149    ///
150    /// - `NodeId` - Mounted root scene node handle.
151    fn render(&self) -> NodeId {
152        let ctx: Context = current_context();
153        let sz: f32 = self.get_size();
154        let mount_tokens: ThemeTokens = live_tokens_untracked(ThemeTokens::default());
155        let user_style: Option<Style> = self.get_style();
156        let color: Color = user_style
157            .map(|s: Style| s.get_text().get_color())
158            .unwrap_or_else(|| mount_tokens.get_palette().get_foreground());
159        if let Some(icon_name) = self.get_icon() {
160            let paint_icon = move |bounds: Rect, dl: &mut DisplayList| {
161                let live_tok: ThemeTokens = live_tokens_untracked(mount_tokens);
162                let resolved_color: Color = remap_theme_color(color, mount_tokens, live_tok);
163                draw_euv_icon(icon_name, bounds, dl, resolved_color);
164            };
165            let canvas_st: Style = style! {
166                width: Length::Px(sz)
167                height: Length::Px(sz)
168            }
169            .with_overrides(user_style);
170            return view! {
171                canvas {
172                    style: canvas_st
173                    painter: paint_icon
174                }
175            };
176        }
177        let Self { symbol, .. } = self;
178        let mut row_st: Style = Style::default();
179        row_st
180            .get_mut_layout()
181            .set_flex_direction(FlexDirection::Row)
182            .set_width(Length::Px(sz))
183            .set_height(Length::Px(sz))
184            .set_justify_content(JustifyContent::Center)
185            .set_align_items(AlignItems::Center);
186        row_st = row_st.with_overrides(user_style);
187        let mut txt_st: Style = Style::default();
188        txt_st
189            .get_mut_text()
190            .set_font_size(sz * 0.78)
191            .set_weight(FontWeight::SemiBold)
192            .set_color(color);
193        ctx.get_scene().with_write(
194            |tree: &mut SceneTree| {
195                let root: NodeId = tree.create_view(row_st);
196                let txt_id: NodeId = tree.create_text(symbol.clone(), txt_st);
197                tree.append_child(root, txt_id);
198                root
199            },
200            NodeId::default(),
201        )
202    }
203}
204
205/// Declarative `#[component]` implementation for `EuvKbd`.
206#[component]
207/// Inherent implementation of [`EuvKbd`].
208impl EuvKbd {
209    /// Renders `EuvKbd` into the ambient framework-managed `Context`.
210    ///
211    /// # Arguments
212    ///
213    /// - `&Self` - Component descriptor reference.
214    ///
215    /// # Returns
216    ///
217    /// - `NodeId` - Mounted root scene node handle.
218    fn render(&self) -> NodeId {
219        let ctx: Context = current_context();
220        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
221        let p: ThemePalette = tokens.get_palette();
222        let g: ThemeGeometry = tokens.get_geometry();
223        let muted_surface: SurfaceColors = p.surface(SurfaceRole::Muted);
224        let Self { key, .. } = self;
225        let mut row_st: Style = Style::default();
226        row_st
227            .get_mut_layout()
228            .set_flex_direction(FlexDirection::Row)
229            .set_justify_content(JustifyContent::Center)
230            .set_align_items(AlignItems::Center)
231            .set_padding(Edges::symmetric(2.0, 6.0))
232            .set_overflow(Overflow::Hidden);
233        row_st
234            .get_mut_paint()
235            .set_background(Some(muted_surface.get_bg()))
236            .set_border(Border::new(g.get_border_width().max(0.0), p.get_border()))
237            .set_radius(CornerRadius::all(g.get_radius_sm().max(0.0)));
238        let mut txt_st: Style = Style::default();
239        txt_st
240            .get_mut_text()
241            .set_family(FontFamily::Monospace)
242            .set_font_size(11.0)
243            .set_color(muted_surface.get_fg())
244            .set_align(TextAlign::Center)
245            .set_overflow(TextOverflow::Clip);
246        ctx.get_scene().with_write(
247            |tree: &mut SceneTree| {
248                let root: NodeId = tree.create_view(row_st);
249                let txt_id: NodeId = tree.create_text(key.clone(), txt_st);
250                tree.append_child(root, txt_id);
251                root
252            },
253            NodeId::default(),
254        )
255    }
256}
257
258/// Declarative `#[component]` implementation for `EuvTypography`.
259#[component]
260/// Inherent implementation of [`EuvTypography`].
261impl EuvTypography {
262    /// Renders `EuvTypography` into the ambient framework-managed `Context`.
263    ///
264    /// # Arguments
265    ///
266    /// - `&Self` - Component descriptor reference.
267    ///
268    /// # Returns
269    ///
270    /// - `NodeId` - Mounted root scene node handle.
271    fn render(&self) -> NodeId {
272        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
273        let p: ThemePalette = tokens.get_palette();
274        let g: ThemeGeometry = tokens.get_geometry();
275        let variant: EuvTypographyVariant = self.get_variant();
276        let Self { text, .. } = self;
277        let mut style: Style = Style::default();
278        let ts: &mut TextStyle = style.get_mut_text();
279        match variant {
280            EuvTypographyVariant::H1 => {
281                ts.set_font_size(g.get_font_title())
282                    .set_weight(FontWeight::Bold)
283                    .set_color(p.get_foreground());
284            }
285            EuvTypographyVariant::H2 => {
286                ts.set_font_size(g.get_font_heading())
287                    .set_weight(FontWeight::Bold)
288                    .set_color(p.get_foreground());
289            }
290            EuvTypographyVariant::H3 => {
291                ts.set_font_size(15.0)
292                    .set_weight(FontWeight::SemiBold)
293                    .set_color(p.get_foreground());
294            }
295            EuvTypographyVariant::Body => {
296                ts.set_font_size(g.get_font_body())
297                    .set_color(p.get_foreground());
298            }
299            EuvTypographyVariant::Caption => {
300                ts.set_font_size(12.0).set_color(p.get_muted_foreground());
301            }
302        }
303        view! {
304            text {
305                style: style
306                { text.as_str() }
307            }
308        }
309    }
310}
311
312/// Declarative `#[component]` implementation for `EuvEmpty`.
313#[component]
314/// Inherent implementation of [`EuvEmpty`].
315impl EuvEmpty {
316    /// Renders `EuvEmpty` into the ambient framework-managed `Context`.
317    ///
318    /// # Arguments
319    ///
320    /// - `&Self` - Component descriptor reference.
321    ///
322    /// # Returns
323    ///
324    /// - `NodeId` - Mounted root scene node handle.
325    fn render(&self) -> NodeId {
326        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
327        let p: ThemePalette = tokens.get_palette();
328        let g: ThemeGeometry = tokens.get_geometry();
329        let Self {
330            title, description, ..
331        } = self;
332        view! {
333            column {
334                style: {
335                    width: Length::Percent(100.0)
336                    align: AlignItems::Center
337                    padding: Edges::all(SPACE_2XL)
338                    gap: SPACE_SM
339                    border: (g.get_border_width(), p.get_border())
340                    radius: g.get_radius_lg()
341                    overflow: Overflow::Hidden
342                }
343                text {
344                    style: {
345                        font_size: 20.0
346                        color: p.get_muted_foreground()
347                    }
348                    { EMPTY_ICON_GLYPH }
349                }
350                text {
351                    style: {
352                        width: Length::Percent(100.0)
353                        font_size: 15.0
354                        font_weight: FontWeight::SemiBold
355                        color: p.get_foreground()
356                        text_align: TextAlign::Center
357                    }
358                    { title.as_str() }
359                }
360                text {
361                    style: {
362                        width: Length::Percent(100.0)
363                        font_size: 13.0
364                        color: p.get_muted_foreground()
365                        text_align: TextAlign::Center
366                    }
367                    { description.as_str() }
368                }
369            }
370        }
371    }
372}
373
374/// Declarative `#[component]` implementation for `EuvSkeleton`.
375#[component]
376/// Inherent implementation of [`EuvSkeleton`].
377impl EuvSkeleton {
378    /// Renders `EuvSkeleton` into the ambient framework-managed `Context`.
379    ///
380    /// # Arguments
381    ///
382    /// - `&Self` - Component descriptor reference.
383    ///
384    /// # Returns
385    ///
386    /// - `NodeId` - Mounted root scene node handle.
387    fn render(&self) -> NodeId {
388        let live_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
389        let p: ThemePalette = live_tok.get_palette();
390        let g: ThemeGeometry = live_tok.get_geometry();
391        let box_st: Style = style! {
392            width: Length::Percent(100.0)
393            max_width: Length::Percent(100.0)
394            height: Length::Px(16.0)
395            background: p.get_secondary()
396            radius: g.get_radius_sm()
397        }
398        .with_overrides(self.get_style());
399        view! {
400            view {
401                style: box_st
402            }
403        }
404    }
405}
406
407/// Declarative `#[component]` implementation for `EuvSpinner`.
408#[component]
409/// Inherent implementation of [`EuvSpinner`].
410impl EuvSpinner {
411    /// Renders `EuvSpinner` into the ambient framework-managed `Context`.
412    ///
413    /// # Arguments
414    ///
415    /// - `&Self` - Component descriptor reference.
416    ///
417    /// # Returns
418    ///
419    /// - `NodeId` - Mounted root scene node handle.
420    fn render(&self) -> NodeId {
421        let base_tokens: ThemeTokens = self.get_tokens();
422        let sz: f32 = self.get_size();
423        let paint_spinner = move |bounds: Rect, dl: &mut DisplayList| {
424            let primary: Color = live_tokens_untracked(base_tokens)
425                .get_palette()
426                .get_primary();
427            let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
428            let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
429            let outer_r: f32 = (bounds.get_width().min(bounds.get_height()) * 0.42).max(4.0);
430            let inner_r: f32 = outer_r * 0.56;
431            let stroke_w: f32 = (outer_r * 0.24).clamp(1.6, 3.2);
432            for &(cos_a, sin_a, alpha) in SPINNER_SPOKES.iter() {
433                dl.push(DrawCommand::Line {
434                    from: Point::new(cx + cos_a * inner_r, cy + sin_a * inner_r),
435                    to: Point::new(cx + cos_a * outer_r, cy + sin_a * outer_r),
436                    color: primary.multiply_alpha(alpha),
437                    width: stroke_w,
438                });
439            }
440        };
441        view! {
442            canvas {
443                style: {
444                    width: Length::Px(sz)
445                    height: Length::Px(sz)
446                    radius: RADIUS_PILL
447                }
448                painter: paint_spinner
449            }
450        }
451    }
452}
453
454/// Declarative `#[component]` implementation for `EuvTimeline`.
455#[component]
456/// Inherent implementation of [`EuvTimeline`].
457impl EuvTimeline {
458    /// Renders `EuvTimeline` into the ambient framework-managed `Context`.
459    ///
460    /// # Arguments
461    ///
462    /// - `&Self` - Component descriptor reference.
463    ///
464    /// # Returns
465    ///
466    /// - `NodeId` - Mounted root scene node handle.
467    fn render(&self) -> NodeId {
468        let p: ThemePalette = live_tokens_untracked(self.get_tokens()).get_palette();
469        let Self { items, .. } = self;
470        view! {
471            column {
472                style: {
473                    width: Length::Percent(100.0)
474                    gap: SPACE_MD
475                }
476                for item in items.iter() {
477                    row {
478                        style: {
479                            width: Length::Percent(100.0)
480                            gap: SPACE_MD
481                        }
482                        view {
483                            style: {
484                                width: Length::Px(10.0)
485                                height: Length::Px(10.0)
486                                flex_shrink: 0.0
487                                background: p.get_primary()
488                                radius: RADIUS_PILL
489                            }
490                        }
491                        column {
492                            style: {
493                                flex_grow: 1.0
494                                flex_shrink: 1.0
495                                min_width: Length::Px(0.0)
496                                gap: 2.0
497                            }
498                            text {
499                                style: {
500                                    width: Length::Percent(100.0)
501                                    font_size: 14.0
502                                    font_weight: FontWeight::SemiBold
503                                    color: p.get_foreground()
504                                }
505                                { item.get_title().as_str() }
506                            }
507                            text {
508                                style: {
509                                    width: Length::Percent(100.0)
510                                    font_size: 11.0
511                                    color: p.get_muted_foreground()
512                                }
513                                { item.get_timestamp().as_str() }
514                            }
515                            text {
516                                style: {
517                                    width: Length::Percent(100.0)
518                                    font_size: 13.0
519                                    color: p.get_muted_foreground()
520                                }
521                                { item.get_detail().as_str() }
522                            }
523                        }
524                    }
525                }
526            }
527        }
528    }
529}
530
531/// Declarative `#[component]` implementation for `EuvList`.
532#[component]
533/// Inherent implementation of [`EuvList`].
534impl EuvList {
535    /// Renders `EuvList` into the ambient framework-managed `Context`.
536    ///
537    /// # Arguments
538    ///
539    /// - `&Self` - Component descriptor reference.
540    ///
541    /// # Returns
542    ///
543    /// - `NodeId` - Mounted root scene node handle.
544    fn render(&self) -> NodeId {
545        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
546        let p: ThemePalette = tokens.get_palette();
547        let g: ThemeGeometry = tokens.get_geometry();
548        let Self { items, .. } = self;
549        view! {
550            column {
551                style: {
552                    width: Length::Percent(100.0)
553                    background: p.get_card()
554                    border: (g.get_border_width(), p.get_border())
555                    radius: g.get_radius_md()
556                    overflow: Overflow::Hidden
557                }
558                for (idx, item) in items.iter().enumerate() {
559                    if idx > 0 {
560                        view {
561                            style: {
562                                width: Length::Percent(100.0)
563                                height: Length::Px(g.get_border_width().max(1.0))
564                                background: p.get_border()
565                            }
566                        }
567                    }
568                    row {
569                        style: {
570                            width: Length::Percent(100.0)
571                            padding: Edges::symmetric(SPACE_SM, SPACE_MD)
572                            overflow: Overflow::Hidden
573                        }
574                        text {
575                            style: {
576                                width: Length::Percent(100.0)
577                                font_size: 13.0
578                                color: p.get_foreground()
579                            }
580                            { item.as_str() }
581                        }
582                    }
583                }
584            }
585        }
586    }
587}
588
589/// Builder, state-color helpers, and recursive rendering methods for `EuvTree`.
590impl EuvTree {
591    /// Resolves `(row_bg, label_fg)` colors for a tree row under `palette` and `is_selected`.
592    ///
593    /// # Arguments
594    ///
595    /// - `ThemePalette` - Live theme palette.
596    /// - `bool` - Whether the tree row is selected.
597    ///
598    /// # Returns
599    ///
600    /// - `(Color, Color)` - Contrast-safe row background and label foreground colors.
601    #[must_use]
602    pub fn row_colors(palette: ThemePalette, is_selected: bool) -> (Color, Color) {
603        if is_selected {
604            let surface: SurfaceColors = palette.surface(SurfaceRole::Accent);
605            (surface.get_bg(), surface.get_fg())
606        } else {
607            let card_surface: SurfaceColors = palette.surface(SurfaceRole::Card);
608            (COLOR_TRANSPARENT, card_surface.get_fg())
609        }
610    }
611
612    /// Binds an optional controlled signal receiving the most recently selected tree node label.
613    ///
614    /// # Arguments
615    ///
616    /// - `Self` - Source tree component.
617    /// - `Signal<Option<String>>` - Selected node label signal.
618    ///
619    /// # Returns
620    ///
621    /// - `Self` - Updated interactive tree.
622    #[must_use]
623    pub fn selected(mut self, selected: Signal<Option<String>>) -> Self {
624        self.set_selected(Some(selected));
625        self
626    }
627
628    /// Recursively builds interactive indented tree row nodes for `nodes`.
629    ///
630    /// # Arguments
631    ///
632    /// - `&[EuvTreeNode]` - Sibling tree nodes.
633    /// - `usize` - Current indentation depth.
634    /// - `(ThemePalette, ThemeGeometry)` - Active theme palette and geometry.
635    /// - `Option<Signal<Option<String>>>` - Optional active selection signal.
636    /// - `Option<&str>` - Initial selected label snapshot for first-paint styling.
637    /// - `&mut Vec<(NodeId, NodeId, String)>` - Collector of `(row_node, label_node, label)` tuples for O(1) selector binding.
638    ///
639    /// # Returns
640    ///
641    /// - `Vec<NodeId>` - Mounted sibling tree nodes ready for spread attachment.
642    fn build_branch(
643        nodes: &[EuvTreeNode],
644        depth: usize,
645        theme: (ThemePalette, ThemeGeometry),
646        selected: Option<Signal<Option<String>>>,
647        init_selected: Option<&str>,
648        bound_rows: &mut Vec<(NodeId, NodeId, String)>,
649    ) -> Vec<NodeId> {
650        let (palette, geom): (ThemePalette, ThemeGeometry) = theme;
651        let row_radius: f32 = concentric_radius(geom.get_radius_lg(), CONTROL_INSET);
652        let mut out: Vec<NodeId> = Vec::with_capacity(nodes.len() * 2);
653        for node in nodes.iter() {
654            let has_children: bool = !node.get_children().is_empty();
655            let expanded: Signal<bool> = Signal::new(true);
656            let indent: f32 = (depth as f32) * 16.0;
657            let label_str: &str = node.get_label().as_str();
658            let lbl_click: String = node.get_label().clone();
659            let is_init_sel: bool = init_selected == Some(label_str);
660            let (init_bg, init_fg): (Color, Color) = Self::row_colors(palette, is_init_sel);
661            let on_row_click = move |_: &UiEvent| {
662                if has_children {
663                    let _: bool = expanded.update(|v: &mut bool| *v = !*v);
664                }
665                if let Some(sel_sig) = selected {
666                    let _: bool = sel_sig.set_if_changed(Some(lbl_click.clone()));
667                }
668            };
669            let label_node: NodeId = if has_children {
670                let lbl_for_txt: String = node.get_label().clone();
671                let branch_label = move || -> String {
672                    let pfx: &str = if expanded.get() {
673                        TREE_EXPAND_PREFIX
674                    } else {
675                        TREE_COLLAPSED_PREFIX
676                    };
677                    format!("{pfx}{lbl_for_txt}")
678                };
679                view! {
680                    text {
681                        style: {
682                            flex_grow: 1.0
683                            flex_shrink: 1.0
684                            min_width: Length::Px(0.0)
685                            font_size: 13.0
686                            font_weight: FontWeight::Medium
687                            color: init_fg
688                        }
689                        { branch_label }
690                    }
691                }
692            } else {
693                let leaf_label: String = format!("{TREE_LEAF_PREFIX}{label_str}");
694                view! {
695                    text {
696                        style: {
697                            flex_grow: 1.0
698                            flex_shrink: 1.0
699                            min_width: Length::Px(0.0)
700                            font_size: 13.0
701                            color: init_fg
702                        }
703                        { leaf_label }
704                    }
705                }
706            };
707            let row: NodeId = view! {
708                row {
709                    style: {
710                        width: Length::Percent(100.0)
711                        min_height: Length::Px(geom.get_control_sm())
712                        align: AlignItems::Center
713                        padding: Edges::new(SPACE_XS, SPACE_SM, SPACE_XS, SPACE_SM + indent)
714                        radius: row_radius
715                        background: init_bg
716                        overflow: Overflow::Hidden
717                        cursor: CursorIcon::Pointer
718                    }
719                    on_click: on_row_click
720                    { label_node }
721                }
722            };
723            if selected.is_some() {
724                bound_rows.push((row, label_node, node.get_label().clone()));
725            }
726            out.push(row);
727            if has_children {
728                let child_nodes: Vec<NodeId> = Self::build_branch(
729                    node.get_children(),
730                    depth + 1,
731                    theme,
732                    selected,
733                    init_selected,
734                    bound_rows,
735                );
736                let mut branch_base: Style = Style::default();
737                branch_base
738                    .get_mut_layout()
739                    .set_flex_direction(FlexDirection::Column)
740                    .set_width(Length::Percent(100.0))
741                    .set_row_gap(CONTROL_INSET)
742                    .set_column_gap(CONTROL_INSET);
743                let branch_style = move || -> Style {
744                    let mut st: Style = branch_base;
745                    st.get_mut_layout().set_display(if expanded.get() {
746                        Display::Flex
747                    } else {
748                        Display::None
749                    });
750                    st
751                };
752                let branch_box: NodeId = view! {
753                    column {
754                        bind_style: branch_style
755                        ..child_nodes
756                    }
757                };
758                out.push(branch_box);
759            }
760        }
761        out
762    }
763}
764
765/// Declarative `#[component]` implementation for `EuvTree`.
766#[component]
767/// Inherent implementation of [`EuvTree`].
768impl EuvTree {
769    /// Renders `EuvTree` into the ambient framework-managed `Context`.
770    ///
771    /// Selected rows and their labels are theme-owned and repainted from `use_live_tokens()` with contrast-safe
772    /// `SurfaceRole::Accent` pairing so selection state stays crisp across live theme switches.
773    ///
774    /// # Arguments
775    ///
776    /// - `&Self` - Component descriptor reference.
777    ///
778    /// # Returns
779    ///
780    /// - `NodeId` - Mounted root scene node handle.
781    fn render(&self) -> NodeId {
782        let base_tokens: ThemeTokens = self.get_tokens();
783        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
784        let p: ThemePalette = init_tok.get_palette();
785        let g: ThemeGeometry = init_tok.get_geometry();
786        let Self {
787            roots, selected, ..
788        } = self;
789        let init_selected: Option<String> =
790            selected.and_then(|sig: Signal<Option<String>>| sig.get_untracked());
791        let mut bound_rows: Vec<(NodeId, NodeId, String)> = Vec::new();
792        let branch_nodes: Vec<NodeId> = Self::build_branch(
793            roots,
794            0,
795            (p, g),
796            *selected,
797            init_selected.as_deref(),
798            &mut bound_rows,
799        );
800        let root: NodeId = view! {
801            column {
802                style: {
803                    width: Length::Percent(100.0)
804                    padding: Edges::all(CONTROL_INSET)
805                    gap: CONTROL_INSET
806                    background: p.get_card()
807                    border: (g.get_border_width(), p.get_border())
808                    radius: g.get_radius_lg()
809                    overflow: Overflow::Hidden
810                }
811                ..branch_nodes
812            }
813        };
814        if let Some(sel_sig) = *selected
815            && !bound_rows.is_empty()
816        {
817            let ctx: Context = current_context();
818            let scene: SceneHandle = ctx.get_scene().clone();
819            let owned_nodes: Vec<NodeId> = bound_rows
820                .iter()
821                .flat_map(|&(row_id, lbl_id, _): &(NodeId, NodeId, String)| [row_id, lbl_id])
822                .collect();
823            let init_key: ThemeKey = init_tok.key();
824            let (tree_scope, _): (Scope, ()) = Scope::run(|_: Scope| {
825                let sel: Rc<Selector<Option<String>>> =
826                    Rc::new(Selector::new(move || sel_sig.get()));
827                let sel_cleanup: Rc<Selector<Option<String>>> = Rc::clone(&sel);
828                on_cleanup(move || {
829                    sel_cleanup.dispose();
830                });
831                for (row_node, label_node, lbl_cmp) in bound_rows.into_iter() {
832                    let sel_row: Rc<Selector<Option<String>>> = Rc::clone(&sel);
833                    let scene_row: SceneHandle = scene.clone();
834                    let init_is_sel: bool = init_selected.as_deref() == Some(lbl_cmp.as_str());
835                    let prev_state: Cell<(bool, ThemeKey)> = Cell::new((init_is_sel, init_key));
836                    let _: Effect = Effect::new(move || {
837                        let is_sel: bool = sel_row.is_selected(Some(lbl_cmp.clone()));
838                        let live_tok: ThemeTokens = use_live_tokens(base_tokens);
839                        let (prev_sel, prev_key): (bool, ThemeKey) =
840                            prev_state.replace((is_sel, live_tok.key()));
841                        if prev_sel == is_sel && prev_key == live_tok.key() {
842                            return;
843                        }
844                        let (bg, fg): (Color, Color) =
845                            Self::row_colors(live_tok.get_palette(), is_sel);
846                        scene_row.with_write(
847                            |tree: &mut SceneTree| {
848                                if let Some(node) = tree.get_node_mut(row_node) {
849                                    node.get_mut_style()
850                                        .get_mut_paint()
851                                        .set_background(Some(bg));
852                                    tree.mark_dirty(row_node, DIRTY_PAINT);
853                                }
854                                if let Some(node) = tree.get_node_mut(label_node) {
855                                    node.get_mut_style().get_mut_text().set_color(fg);
856                                    tree.mark_dirty(label_node, DIRTY_PAINT);
857                                }
858                            },
859                            (),
860                        );
861                    });
862                }
863            });
864            ctx.get_scene().with_write(
865                |tree: &mut SceneTree| {
866                    mark_theme_owned(tree, owned_nodes.as_slice());
867                    tree.attach_scope(root, tree_scope);
868                },
869                (),
870            );
871        }
872        root
873    }
874}