Skip to main content

euv_ui/component/form_extra/
impl.rs

1use super::*;
2
3/// Declarative `#[component]` implementation for `EuvLabel`.
4#[component]
5/// Inherent implementation of [`EuvLabel`].
6impl EuvLabel {
7    /// Renders `EuvLabel` 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 tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
18        let theme_palette: ThemePalette = tok.get_palette();
19        let bg_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Background);
20        let required: bool = self.get_required();
21        let Self { text, .. } = self;
22        let row_nineteenth_style: Style = style! {
23            AlignItems::Center
24            Gap(SPACE_XS)
25        };
26        let text_tenth_style: Style = style! {
27            FlexShrink(1.0)
28            MinWidth(Length::Px(0.0))
29            FontSize(13.0)
30            FontWeight::Medium
31            TextColor(bg_surface.get_fg())
32        };
33        let text_eleventh_style: Style = style! {
34            FlexShrink(0.0)
35            FontSize(13.0)
36            FontWeight::Bold
37            TextColor(theme_palette.get_destructive())
38        };
39        view! {
40            row {
41                style: row_nineteenth_style
42                text {
43                    style: text_tenth_style
44                    { text.clone() }
45                }
46                if required {
47                    text {
48                        style: text_eleventh_style
49                        { STAR_FILLED }
50                    }
51                }
52            }
53        }
54    }
55}
56
57/// Builder methods for `EuvForm`.
58impl EuvForm {
59    /// Appends a mounted field node to the form.
60    ///
61    /// # Arguments
62    ///
63    /// - `Self` - Source form.
64    /// - `NodeId` - Field node handle.
65    ///
66    /// # Returns
67    ///
68    /// - `Self` - Updated form.
69    #[must_use]
70    pub fn field(mut self, node: NodeId) -> Self {
71        self.get_mut_fields().push(node);
72        self
73    }
74}
75
76/// Declarative `#[component]` implementation for `EuvForm`.
77#[component]
78/// Inherent implementation of [`EuvForm`].
79impl EuvForm {
80    /// Renders `EuvForm` into the ambient framework-managed `Context`.
81    ///
82    /// # Arguments
83    ///
84    /// - `&Self` - Component descriptor reference.
85    ///
86    /// # Returns
87    ///
88    /// - `NodeId` - Mounted root scene node handle.
89    fn render(&self) -> NodeId {
90        let mut ctx: Context = current_context();
91        let Self { fields, .. } = self;
92        let column_eighth_style: Style = style! {
93            Width(Length::Percent(100.0))
94            Gap(SPACE_MD)
95        };
96        let root: NodeId = view! {
97            column {
98                style: column_eighth_style
99            }
100        };
101        if !fields.is_empty() {
102            ctx.append_many(root, fields.as_slice());
103        }
104        root
105    }
106}
107
108/// Declarative `#[component]` implementation for `EuvTextarea`.
109#[component]
110/// Inherent implementation of [`EuvTextarea`].
111impl EuvTextarea {
112    /// Renders `EuvTextarea` into the ambient framework-managed `Context`.
113    ///
114    /// # Arguments
115    ///
116    /// - `&Self` - Component descriptor reference.
117    ///
118    /// # Returns
119    ///
120    /// - `NodeId` - Mounted root scene node handle.
121    fn render(&self) -> NodeId {
122        let ctx: Context = current_context();
123        let tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
124        let theme_palette: ThemePalette = tok.get_palette();
125        let geometry: ThemeGeometry = tok.get_geometry();
126        let card_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
127        let sig: Signal<String> = self.get_value();
128        let initial: String = sig.get_untracked();
129        let caret: usize = initial.len();
130        let Self { placeholder, .. } = self;
131        let placeholder_owned: String = placeholder.clone();
132        let a11y_label: String = placeholder_owned.clone();
133        let on_change_cb = move |ui_event: &UiEvent| {
134            if let UiEventKind::Change(val) = ui_event.get_kind() {
135                let _: bool = sig.set_if_changed(val.clone());
136            }
137        };
138        let input_st: Style = style! {
139            Width(Length::Percent(100.0))
140            Height(Length::Px(96.0))
141            Padding(Edges::all(SPACE_SM))
142            Background(card_surface.get_bg())
143            Border::new(geometry.get_border_width(), card_surface.get_border())
144            Radius(geometry.get_radius_md())
145            Overflow::Hidden
146            TextColor(card_surface.get_fg())
147            FontSize(geometry.get_font_body())
148        }
149        .with_overrides(self.get_style());
150        let node: NodeId = view! {
151            input {
152                value: initial.clone()
153                placeholder: placeholder_owned
154                caret: caret
155                multiline: true
156                style: input_st
157                role: A11yRole::TextInput
158                a11y_label: a11y_label.clone()
159                a11y_value: initial
160                on_change: on_change_cb
161            }
162        };
163        let handle: SceneHandle = ctx.get_scene().clone();
164        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
165            Effect::new(move || {
166                let next_val: String = sig.get();
167                handle.with_write(
168                    |tree: &mut SceneTree| {
169                        let mut changed: bool = false;
170                        if let Some(item_count) = tree.get_node_mut(node) {
171                            if let NodeKind::Input(input_state) = item_count.get_mut_kind()
172                                && input_state.get_value() != &next_val
173                            {
174                                let len: usize = next_val.len();
175                                let _: &mut InputNodeState =
176                                    input_state.set_value(next_val.clone());
177                                let _: &mut InputNodeState = input_state.set_caret(len);
178                                changed = true;
179                            }
180                            if let Some(a11y) = item_count.get_mut_a11y().as_mut() {
181                                let _: &mut A11yProps = a11y.set_value(next_val);
182                            } else {
183                                let mut next_a11y: A11yProps =
184                                    A11yProps::new(A11yRole::TextInput, a11y_label.clone());
185                                let _: &mut A11yProps = next_a11y.set_value(next_val);
186                                let _: &mut SceneNode = item_count.set_a11y(Some(next_a11y));
187                            }
188                        }
189                        if changed {
190                            tree.mark_dirty(node, DIRTY_PAINT);
191                        }
192                    },
193                    (),
194                );
195            })
196        });
197        ctx.get_scene().with_write(
198            |tree: &mut SceneTree| {
199                tree.attach_scope(node, scope);
200            },
201            (),
202        );
203        node
204    }
205}
206
207/// Fluent range and step builders for `EuvNumberInput`.
208impl EuvNumberInput {
209    /// Configures inclusive `[min, max]` clamp bounds fluently.
210    ///
211    /// # Arguments
212    ///
213    /// - `Self` - Source number input.
214    /// - `i64` - Inclusive minimum value.
215    /// - `i64` - Inclusive maximum value.
216    ///
217    /// # Returns
218    ///
219    /// - `Self` - Updated number input.
220    #[must_use]
221    pub fn range(mut self, min: i64, max: i64) -> Self {
222        self.set_min(Some(min));
223        self.set_max(Some(max));
224        self
225    }
226
227    /// Configures the increment/decrement step size fluently.
228    ///
229    /// # Arguments
230    ///
231    /// - `Self` - Source number input.
232    /// - `i64` - Positive step delta.
233    ///
234    /// # Returns
235    ///
236    /// - `Self` - Updated number input.
237    #[must_use]
238    pub fn step(mut self, step: i64) -> Self {
239        self.set_step(step.max(1));
240        self
241    }
242}
243
244/// Declarative `#[component]` implementation for `EuvNumberInput`.
245#[component]
246/// Inherent implementation of [`EuvNumberInput`].
247impl EuvNumberInput {
248    /// Renders `EuvNumberInput` into the ambient framework-managed `Context`.
249    ///
250    /// # Arguments
251    ///
252    /// - `&Self` - Component descriptor reference.
253    ///
254    /// # Returns
255    ///
256    /// - `NodeId` - Mounted root scene node handle.
257    fn render(&self) -> NodeId {
258        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
259        let theme_palette: ThemePalette = tokens.get_palette();
260        let geometry: ThemeGeometry = tokens.get_geometry();
261        let card_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
262        let sig: Signal<i64> = self.get_value();
263        let step_v: i64 = if self.get_step() > 0 {
264            self.get_step()
265        } else {
266            1
267        };
268        let Self { min, max, .. } = self;
269        let raw_min: i64 = min.unwrap_or(i64::MIN / 2);
270        let raw_max: i64 = max.unwrap_or(i64::MAX / 2);
271        let (min_v, max_v): (i64, i64) = if raw_min <= raw_max {
272            (raw_min, raw_max)
273        } else {
274            (raw_max, raw_min)
275        };
276        let on_dec = move |_: &UiEvent| {
277            let _: bool = {
278                if let Some(mut updated_value) = sig.try_get_untracked() {
279                    {
280                        let item_val: &mut i64 = &mut updated_value;
281                        *item_val = item_val.saturating_sub(step_v).clamp(min_v, max_v)
282                    }
283                    sig.set(updated_value)
284                } else {
285                    false
286                }
287            };
288        };
289        let on_inc = move |_: &UiEvent| {
290            let _: bool = {
291                if let Some(mut updated_value) = sig.try_get_untracked() {
292                    {
293                        let tex_v: &mut i64 = &mut updated_value;
294                        *tex_v = tex_v.saturating_add(step_v).clamp(min_v, max_v);
295                    }
296                    sig.set(updated_value)
297                } else {
298                    false
299                }
300            };
301        };
302        let value_text = move || -> String { sig.get().to_string() };
303        let row_seventeenth_style: Style = style! {
304            AlignItems::Center
305            Gap(SPACE_SM)
306        };
307        let row_eighteenth_style: Style = style! {
308            Width(Length::Px(72.0))
309            Height(Length::Px(geometry.get_control_sm()))
310            JustifyContent::Center
311            AlignItems::Center
312            Background(card_surface.get_bg())
313            Border::new(geometry.get_border_width(), card_surface.get_border())
314            Radius(geometry.get_radius_sm())
315            Overflow::Hidden
316        };
317        let text_ninth_style: Style = style! {
318            FontSize(14.0)
319            FontWeight::Medium
320            TextColor(card_surface.get_fg())
321            TextAlign::Center
322        };
323        view! {
324            row {
325                style: row_seventeenth_style
326                EuvButton {
327                    label: STEP_MINUS.to_string()
328                    tokens: tokens
329                    outline()
330                    small()
331                    on_click: on_dec
332                }
333                row {
334                    style: row_eighteenth_style
335                    text {
336                        style: text_ninth_style
337                        { value_text }
338                    }
339                }
340                EuvButton {
341                    label: STEP_PLUS.to_string()
342                    tokens: tokens
343                    outline()
344                    small()
345                    on_click: on_inc
346                }
347            }
348        }
349    }
350}
351
352/// State-dependent palette helpers for `EuvRadioGroup`.
353impl EuvRadioGroup {
354    /// Resolves `(ring_bg, ring_border, dot_bg)` colors for the given active radio state.
355    ///
356    /// # Arguments
357    ///
358    /// - `ThemePalette` - Live theme palette.
359    /// - `bool` - Whether this radio option is selected.
360    ///
361    /// # Returns
362    ///
363    /// - `(Color, Color, Color)` - Ring background, ring border, and center dot fill colors.
364    #[must_use]
365    pub fn state_colors(palette: ThemePalette, active: bool) -> (Color, Color, Color) {
366        if active {
367            let color_value: SurfaceColors = palette.surface(SurfaceRole::Primary);
368            (
369                color_value.get_bg(),
370                color_value.get_border(),
371                color_value.get_fg(),
372            )
373        } else {
374            let tint_color: SurfaceColors = palette.surface(SurfaceRole::Card);
375            (tint_color.get_bg(), palette.get_border(), COLOR_TRANSPARENT)
376        }
377    }
378}
379
380/// Declarative `#[component]` implementation for `EuvRadioGroup`.
381#[component]
382/// Inherent implementation of [`EuvRadioGroup`].
383impl EuvRadioGroup {
384    /// Renders `EuvRadioGroup` into the ambient framework-managed `Context`.
385    ///
386    /// Both the outer radio ring and inner selection dot use `RADIUS_PILL`, and their state-dependent colors are
387    /// owned by a reactive `Effect` tracking both `selected` and the live ambient theme.
388    ///
389    /// # Arguments
390    ///
391    /// - `&Self` - Component descriptor reference.
392    ///
393    /// # Returns
394    ///
395    /// - `NodeId` - Mounted root scene node handle.
396    fn render(&self) -> NodeId {
397        let mut ctx: Context = current_context();
398        let base_tokens: ThemeTokens = self.get_tokens();
399        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
400        let theme_palette: ThemePalette = init_tok.get_palette();
401        let geometry: ThemeGeometry = init_tok.get_geometry();
402        let bg_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Background);
403        let selected: Signal<usize> = self.get_selected();
404        let Self { options, .. } = self;
405        let init_sel: usize = selected.get_untracked();
406        let mut ring_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
407        let mut dot_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
408        let mut row_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
409        let option_labels: Vec<String> = options.clone();
410        for (idx, opt) in options.iter().enumerate() {
411            let active: bool = init_sel == idx;
412            let (ring_bg, ring_border, dot_bg): (Color, Color, Color) =
413                Self::state_colors(theme_palette, active);
414            let mut ring: NodeId = NodeId::default();
415            let mut dot: NodeId = NodeId::default();
416            let on_pick = move |_: &UiEvent| {
417                let _: bool = selected.set_if_changed(idx);
418            };
419            let row_fifteenth_style: Style = style! {
420                AlignItems::Center
421                Padding(Edges::symmetric(SPACE_XS, SPACE_SM))
422                Radius(geometry.get_radius_sm())
423                Gap(SPACE_SM)
424                CursorIcon::Pointer
425            };
426            let row_sixteenth_style: Style = style! {
427                Width(Length::Px(RADIO_RING_SIZE))
428                Height(Length::Px(RADIO_RING_SIZE))
429                FlexShrink(0.0)
430                JustifyContent::Center
431                AlignItems::Center
432                Radius(RADIUS_PILL)
433                Overflow::Hidden
434                Border::new(RADIO_RING_BORDER_WIDTH, ring_border)
435                Background(ring_bg)
436            };
437            let view_tertiary_style: Style = style! {
438                Width(Length::Px(RADIO_DOT_SIZE))
439                Height(Length::Px(RADIO_DOT_SIZE))
440                Radius(RADIUS_PILL)
441                Background(dot_bg)
442            };
443            let text_eighth_style: Style = style! {
444                FlexGrow(1.0)
445                FlexShrink(1.0)
446                MinWidth(Length::Px(0.0))
447                FontSize(14.0)
448                TextColor(bg_surface.get_fg())
449            };
450            let item: NodeId = view! {
451                row {
452                    style: row_fifteenth_style
453                    on_click: on_pick
454                    row {
455                        node_ref: ring
456                        style: row_sixteenth_style
457                        view {
458                            node_ref: dot
459                            style: view_tertiary_style
460                        }
461                    }
462                    text {
463                        style: text_eighth_style
464                        { opt.clone() }
465                    }
466                }
467            };
468            ring_nodes.push(ring);
469            dot_nodes.push(dot);
470            row_nodes.push(item);
471        }
472        let column_seventh_style: Style = style! {
473            Gap(SPACE_SM)
474        };
475        let root: NodeId = view! {
476            column {
477                style: column_seventh_style
478            }
479        };
480        if !row_nodes.is_empty() {
481            ctx.append_many(root, row_nodes.as_slice());
482        }
483        let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(ring_nodes.len() + dot_nodes.len());
484        owned_nodes.extend(ring_nodes.iter().copied());
485        owned_nodes.extend(dot_nodes.iter().copied());
486        let init_rows: Vec<NodeId> = row_nodes.clone();
487        let init_labels: Vec<String> = option_labels.clone();
488        let handle: SceneHandle = ctx.get_scene().clone();
489        let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_sel, init_tok.key()));
490        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
491            Effect::new(move || {
492                let next_sel: usize = selected.get();
493                let tok: ThemeTokens = use_live_tokens(base_tokens);
494                let (old_sel, old_key): (usize, ThemeKey) =
495                    prev_state.replace((next_sel, tok.key()));
496                if old_sel == next_sel && old_key == tok.key() {
497                    return;
498                }
499                let live_p: ThemePalette = tok.get_palette();
500                handle.with_write(
501                    |tree: &mut SceneTree| {
502                        for (idx, (&ring_id, &dot_id)) in
503                            ring_nodes.iter().zip(dot_nodes.iter()).enumerate()
504                        {
505                            let is_active: bool = idx == next_sel;
506                            let (ring_bg, ring_border, dot_bg): (Color, Color, Color) =
507                                Self::state_colors(live_p, is_active);
508                            if let Some(item_count) = tree.get_node_mut(ring_id) {
509                                let _: &mut PaintStyle = item_count
510                                    .get_mut_style()
511                                    .get_mut_paint()
512                                    .set_background(Some(ring_bg))
513                                    .set_border(Border::new(RADIO_RING_BORDER_WIDTH, ring_border));
514                                tree.mark_dirty(ring_id, DIRTY_PAINT);
515                            }
516                            if let Some(node_entry) = tree.get_node_mut(dot_id) {
517                                let _: &mut PaintStyle = node_entry
518                                    .get_mut_style()
519                                    .get_mut_paint()
520                                    .set_background(Some(dot_bg));
521                                tree.mark_dirty(dot_id, DIRTY_PAINT);
522                            }
523                            if let Some(&row_id) = row_nodes.get(idx)
524                                && let Some(normal_vec) = tree.get_node_mut(row_id)
525                            {
526                                if let Some(a11y) = normal_vec.get_mut_a11y().as_mut() {
527                                    let _: &mut A11yProps = a11y.set_checked(Some(is_active));
528                                } else if let Some(label_text) = option_labels.get(idx) {
529                                    let mut a11y: A11yProps =
530                                        A11yProps::new(A11yRole::Checkbox, label_text.clone());
531                                    let _: &mut A11yProps = a11y.set_checked(Some(is_active));
532                                    let _: &mut SceneNode = normal_vec.set_a11y(Some(a11y));
533                                }
534                            }
535                        }
536                    },
537                    (),
538                );
539            })
540        });
541        ctx.get_scene().with_write(
542            |tree: &mut SceneTree| {
543                for (idx, &row_id) in init_rows.iter().enumerate() {
544                    if let Some(total_len) = tree.get_node_mut(row_id)
545                        && let Some(caption_label) = init_labels.get(idx)
546                    {
547                        let mut a11y: A11yProps =
548                            A11yProps::new(A11yRole::Checkbox, caption_label.clone());
549                        let _: &mut A11yProps = a11y.set_checked(Some(idx == init_sel));
550                        let _: &mut SceneNode = total_len.set_a11y(Some(a11y));
551                    }
552                }
553                mark_theme_owned(tree, owned_nodes.as_slice());
554                tree.attach_scope(root, scope);
555            },
556            (),
557        );
558        root
559    }
560}
561
562/// Palette helpers for `EuvSlider`.
563impl EuvSlider {
564    /// Resolves `(track_color, fill_color, thumb_fill, thumb_ring)` colors from `palette` with guaranteed thumb
565    /// ring-to-center contrast across all 34 themes (including Monochrome).
566    ///
567    /// # Arguments
568    ///
569    /// - `ThemePalette` - Live theme palette.
570    ///
571    /// # Returns
572    ///
573    /// - `(Color, Color, Color, Color)` - Track, fill, thumb center fill, and thumb ring colors.
574    #[must_use]
575    pub fn palette_colors(palette: ThemePalette) -> (Color, Color, Color, Color) {
576        let track_color: Color = palette.get_switch_track_off();
577        let primary_surface: SurfaceColors = palette.surface(SurfaceRole::Primary);
578        let fill_color: Color = primary_surface.get_bg();
579        let thumb_ring: Color = primary_surface.get_bg();
580        let thumb_fill: Color = primary_surface.get_fg();
581        (track_color, fill_color, thumb_fill, thumb_ring)
582    }
583}
584
585/// Declarative `#[component]` implementation for `EuvSlider`.
586#[component]
587/// Inherent implementation of [`EuvSlider`].
588impl EuvSlider {
589    /// Renders `EuvSlider` into the ambient framework-managed `Context`.
590    ///
591    /// Reads live theme tokens inside the canvas painter, draws crisp pill end caps with zero track-under-fill
592    /// overlap or AA fringe (including 1-2% fill), and renders a circular `RADIUS_PILL` thumb with a contrast-safe
593    /// ring across all 34 themes.
594    ///
595    /// # Arguments
596    ///
597    /// - `&Self` - Component descriptor reference.
598    ///
599    /// # Returns
600    ///
601    /// - `NodeId` - Mounted root scene node handle.
602    fn render(&self) -> NodeId {
603        let mut ctx: Context = current_context();
604        let base_tokens: ThemeTokens = self.get_tokens();
605        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
606        let theme_palette: ThemePalette = init_tok.get_palette();
607        let value: Signal<f32> = self.get_value();
608        let min_v: f32 = self.get_min();
609        let max_v: f32 = self.get_max();
610        let span: f32 = (max_v - min_v).max(0.001);
611        let init_val: f32 = value.get_untracked();
612        let mut track: NodeId = NodeId::default();
613        let paint_slider = move |bounds: Rect, display_list: &mut DisplayList| {
614            let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
615            let (track_color, fill_color, thumb_fill, thumb_ring): (Color, Color, Color, Color) =
616                Self::palette_colors(live_p);
617            let pct: f32 = ((value.get_untracked() - min_v) / span).clamp(0.0, 1.0);
618            let track_h: f32 = SLIDER_TRACK_HEIGHT;
619            let track_y: f32 = bounds.get_y() + (bounds.get_height() - track_h) * 0.5;
620            let pad_x: f32 = SLIDER_THUMB_RADIUS;
621            let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(8.0);
622            let track_x: f32 = bounds.get_x() + pad_x;
623            let track_rect: Rect = Rect::new(track_x, track_y, track_w, track_h);
624            let pill_radius: CornerRadius = CornerRadius::all(RADIUS_PILL);
625            let fill_w: f32 = (track_w * pct).clamp(0.0, track_w);
626            let thumb_cx: f32 = track_x + fill_w;
627            let thumb_cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
628            if pct <= SLIDER_PCT_EPS {
629                display_list.push(DrawCommand::FillRoundedRect {
630                    rect: track_rect,
631                    color: track_color,
632                    radius: pill_radius,
633                    border: Border::default(),
634                });
635            } else if pct >= 1.0 - SLIDER_PCT_EPS {
636                display_list.push(DrawCommand::FillRoundedRect {
637                    rect: track_rect,
638                    color: fill_color,
639                    radius: pill_radius,
640                    border: Border::default(),
641                });
642            } else {
643                let split_x: f32 = thumb_cx.clamp(track_x, track_rect.right());
644                let left_w: f32 = (split_x - track_x).max(0.0);
645                let right_w: f32 = (track_rect.right() - split_x).max(0.0);
646                display_list.push(DrawCommand::PushRoundedClip {
647                    rect: track_rect,
648                    radius: pill_radius,
649                });
650                if left_w > 0.0 {
651                    display_list.push(DrawCommand::FillRoundedRect {
652                        rect: Rect::new(track_x, track_y, left_w, track_h),
653                        color: fill_color,
654                        radius: CornerRadius::all(0.0),
655                        border: Border::default(),
656                    });
657                }
658                if right_w > 0.0 {
659                    display_list.push(DrawCommand::FillRoundedRect {
660                        rect: Rect::new(split_x, track_y, right_w, track_h),
661                        color: track_color,
662                        radius: CornerRadius::all(0.0),
663                        border: Border::default(),
664                    });
665                }
666                display_list.push(DrawCommand::PopClip);
667            }
668            let thumb_d: f32 = SLIDER_THUMB_RADIUS * 2.0;
669            display_list.push(DrawCommand::FillRoundedRect {
670                rect: Rect::new(
671                    thumb_cx - SLIDER_THUMB_RADIUS,
672                    thumb_cy - SLIDER_THUMB_RADIUS,
673                    thumb_d,
674                    thumb_d,
675                ),
676                color: thumb_fill,
677                radius: pill_radius,
678                border: Border::new(SLIDER_THUMB_RING_WIDTH, thumb_ring),
679            });
680        };
681        let value_text = move || -> String { format!("{:.1}", value.get()) };
682        let row_thirteenth_style: Style = style! {
683            Width(Length::Percent(100.0))
684            Height(Length::Px(42.0))
685            AlignItems::Center
686            Gap(SPACE_SM)
687            StopEventPropagation(true)
688        };
689        let canvas_tertiary_style: Style = style! {
690            FlexGrow(1.0)
691            Height(Length::Px(42.0))
692            StopEventPropagation(true)
693            CursorIcon::Pointer
694        };
695        let row_fourteenth_style: Style = style! {
696            Width(Length::Px(40.0))
697            JustifyContent::End
698            AlignItems::Center
699        };
700        let text_seventh_style: Style = style! {
701            FontSize(12.0)
702            FontWeight::Medium
703            TextColor(theme_palette.get_muted_foreground())
704        };
705        let row: NodeId = view! {
706            row {
707                style: row_thirteenth_style
708                canvas {
709                    node_ref: track
710                    style: canvas_tertiary_style
711                    painter: paint_slider
712                }
713                row {
714                    style: row_fourteenth_style
715                    text {
716                        style: text_seventh_style
717                        { value_text }
718                    }
719                }
720            }
721        };
722        let dragging: Rc<Cell<bool>> = Rc::new(Cell::new(false));
723        let scene_down: SceneHandle = ctx.get_scene().clone();
724        let drag_down: Rc<Cell<bool>> = dragging.clone();
725        ctx.on_pointer_down(track, move |ui_event: &UiEvent| {
726            drag_down.set(true);
727            if let UiEventKind::PointerDown(pos) = ui_event.get_kind()
728                && let Some(bounds) = scene_down.node_screen_bounds(track)
729            {
730                let pad_x: f32 = SLIDER_THUMB_RADIUS;
731                let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(1.0);
732                let frac: f32 =
733                    ((pos.get_x() - (bounds.get_x() + pad_x)) / track_w).clamp(0.0, 1.0);
734                let next: f32 = (min_v + frac * span).clamp(min_v, max_v);
735                let _: bool = value.set_if_changed(next);
736            }
737        });
738        let scene_move: SceneHandle = ctx.get_scene().clone();
739        let drag_move: Rc<Cell<bool>> = dragging.clone();
740        ctx.on_pointer_move(track, move |interaction_event: &UiEvent| {
741            if !drag_move.get() {
742                return;
743            }
744            if let UiEventKind::PointerMove(pos) = interaction_event.get_kind()
745                && let Some(bounds) = scene_move.node_screen_bounds(track)
746            {
747                let pad_x: f32 = SLIDER_THUMB_RADIUS;
748                let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(1.0);
749                let frac: f32 =
750                    ((pos.get_x() - (bounds.get_x() + pad_x)) / track_w).clamp(0.0, 1.0);
751                let next: f32 = (min_v + frac * span).clamp(min_v, max_v);
752                let _: bool = value.set_if_changed(next);
753            }
754        });
755        let drag_up: Rc<Cell<bool>> = dragging.clone();
756        ctx.on_pointer_up(track, move |_: &UiEvent| {
757            drag_up.set(false);
758        });
759        let drag_cancel: Rc<Cell<bool>> = dragging.clone();
760        ctx.on_pointer_cancel(track, move |_: &UiEvent| {
761            drag_cancel.set(false);
762        });
763        let drag_state: Rc<Cell<bool>> = dragging.clone();
764        let app_state_sig: Signal<AppState> = ctx.get_app_state();
765        let scene_watch: SceneHandle = ctx.get_scene().clone();
766        let prev_state: Cell<(f32, ThemeKey)> = Cell::new((init_val, init_tok.key()));
767        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
768            let _: Effect = Effect::new(move || {
769                if app_state_sig.get() != AppState::Active {
770                    drag_state.set(false);
771                }
772            });
773            Effect::new(move || {
774                let next_val: f32 = value.get();
775                let tok: ThemeTokens = use_live_tokens(base_tokens);
776                let (old_val, old_key): (f32, ThemeKey) = prev_state.replace((next_val, tok.key()));
777                if old_val.to_bits() == next_val.to_bits() && old_key == tok.key() {
778                    return;
779                }
780                scene_watch.with_write(
781                    |tree: &mut SceneTree| {
782                        if let Some(item_count) = tree.get_node_mut(track)
783                            && let Some(a11y) = item_count.get_mut_a11y().as_mut()
784                        {
785                            let _: &mut A11yProps = a11y.set_value(format!("{next_val:.1}"));
786                        }
787                        tree.mark_dirty(track, DIRTY_PAINT);
788                    },
789                    (),
790                );
791            })
792        });
793        ctx.get_scene().with_write(
794            |tree: &mut SceneTree| {
795                if let Some(node_entry) = tree.get_node_mut(track) {
796                    let mut a11y: A11yProps =
797                        A11yProps::new(A11yRole::Slider, SLIDER_A11Y_LABEL.to_string());
798                    let _: &mut A11yProps = a11y.set_value(format!("{init_val:.1}"));
799                    let _: &mut SceneNode = node_entry.set_a11y(Some(a11y));
800                }
801                mark_theme_owned(tree, &[track]);
802                tree.attach_scope(track, scope);
803            },
804            (),
805        );
806        row
807    }
808}
809
810/// State-dependent palette helpers for `EuvSelect`.
811impl EuvSelect {
812    /// Resolves contrast-safe `(row_bg, text_fg)` colors for a dropdown option row.
813    ///
814    /// # Arguments
815    ///
816    /// - `ThemePalette` - Live theme palette.
817    /// - `bool` - Whether the option is currently selected.
818    /// - `bool` - Whether the pointer hovers this option.
819    ///
820    /// # Returns
821    ///
822    /// - `(Color, Color)` - Option row background and paired foreground text color.
823    #[must_use]
824    pub fn option_colors(palette: ThemePalette, selected: bool, hovered: bool) -> (Color, Color) {
825        let surface: SurfaceColors =
826            palette.interaction_colors(InteractionRole::OptionItem, selected, hovered, false);
827        (surface.get_bg(), surface.get_fg())
828    }
829}
830
831/// Declarative `#[component]` implementation for `EuvSelect`.
832#[component]
833/// Inherent implementation of [`EuvSelect`].
834impl EuvSelect {
835    /// Renders `EuvSelect` into the ambient framework-managed `Context`.
836    ///
837    /// Trigger and popup menu align 1:1 in width; the menu obeys Equal-Inset + Equal-Gap (`CONTROL_INSET`) with
838    /// concentric item radii, live-token chevron painting, owned selected/hovered option surfaces, and symmetric
839    /// animated open/close transitions.
840    ///
841    /// # Arguments
842    ///
843    /// - `&Self` - Component descriptor reference.
844    ///
845    /// # Returns
846    ///
847    /// - `NodeId` - Mounted root scene node handle.
848    fn render(&self) -> NodeId {
849        let mut ctx: Context = current_context();
850        let base_tokens: ThemeTokens = self.get_tokens();
851        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
852        let theme_palette: ThemePalette = init_tok.get_palette();
853        let geometry: ThemeGeometry = init_tok.get_geometry();
854        let bg_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Background);
855        let card_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
856        let selected: Signal<usize> = self.get_selected();
857        let open: Signal<bool> = self.get_open();
858        let hovered_idx: Signal<Option<usize>> = Signal::new(None);
859        let Self { options, .. } = self;
860        let opts_for_label: Rc<[String]> = Rc::from(options.as_slice());
861        let init_sel: usize = selected.get_untracked();
862        let init_open: bool = open.get_untracked();
863        let menu_radius: f32 = geometry.get_radius_lg();
864        let item_radius: f32 = concentric_radius(menu_radius, CONTROL_INSET);
865        let mut menu: NodeId = NodeId::default();
866        let mut chevron: NodeId = NodeId::default();
867        let on_toggle = move |_: &UiEvent| {
868            let _: bool = open.set(!open.get_untracked());
869        };
870        let selected_text = move || -> String {
871            let idx: usize = selected.get();
872            opts_for_label.get(idx).cloned().unwrap_or_default()
873        };
874        let paint_chevron = move |bounds: Rect, display_list: &mut DisplayList| {
875            let chevron_color: Color = live_tokens_untracked(base_tokens)
876                .get_palette()
877                .get_muted_foreground();
878            let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
879            let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
880            display_list.push(DrawCommand::Line {
881                from: Point::new(cx - 4.0, cy - 2.0),
882                to: Point::new(cx, cy + 2.5),
883                color: chevron_color,
884                width: 1.6,
885            });
886            display_list.push(DrawCommand::Line {
887                from: Point::new(cx, cy + 2.5),
888                to: Point::new(cx + 4.0, cy - 2.0),
889                color: chevron_color,
890                width: 1.6,
891            });
892        };
893        let mut option_rows: Vec<NodeId> = Vec::with_capacity(options.len());
894        let mut option_texts: Vec<NodeId> = Vec::with_capacity(options.len());
895        for (idx, opt) in options.iter().enumerate() {
896            let is_sel: bool = init_sel == idx;
897            let (row_bg, txt_fg): (Color, Color) =
898                Self::option_colors(theme_palette, is_sel, false);
899            let mut txt_id: NodeId = NodeId::default();
900            let on_pick = move |_: &UiEvent| {
901                let _: bool = selected.set_if_changed(idx);
902                let _: bool = open.set_if_changed(false);
903            };
904            let row_twelfth_style: Style = style! {
905                Width(Length::Percent(100.0))
906                Height(Length::Px(geometry.get_control_sm()))
907                Padding(Edges::symmetric(0.0, SPACE_MD))
908                AlignItems::Center
909                Background(row_bg)
910                Radius(item_radius)
911                Overflow::Hidden
912                CursorIcon::Pointer
913            };
914            let text_sixth_style: Style = style! {
915                Width(Length::Percent(100.0))
916                FontSize(13.0)
917                if is_sel { FontWeight::Medium } else { FontWeight::Normal }
918                TextColor(txt_fg)
919                TextOverflow::Ellipsis
920            };
921            let opt_row: NodeId = view! {
922                row {
923                    style: row_twelfth_style
924                    role: A11yRole::ListItem
925                    a11y_label: opt.clone()
926                    on_click: on_pick
927                    text {
928                        node_ref: txt_id
929                        style: text_sixth_style
930                        { opt.clone() }
931                    }
932                }
933            };
934            ctx.on_hover(opt_row, move |ui_event: &UiEvent| {
935                match ui_event.get_kind() {
936                    UiEventKind::PointerEnter => {
937                        let _: bool = hovered_idx.set_if_changed(Some(idx));
938                    }
939                    UiEventKind::PointerLeave => {
940                        let _: bool = {
941                            if let Some(mut updated_value) = hovered_idx.try_get_untracked() {
942                                {
943                                    let cur: &mut Option<usize> = &mut updated_value;
944                                    if *cur == Some(idx) {
945                                        *cur = None;
946                                    }
947                                }
948                                hovered_idx.set(updated_value)
949                            } else {
950                                false
951                            }
952                        };
953                    }
954                    _ => {}
955                }
956            });
957            option_rows.push(opt_row);
958            option_texts.push(txt_id);
959        }
960        let option_rows_for_menu: Vec<NodeId> = option_rows.clone();
961        let column_fifth_style: Style = style! {
962            Width(Length::Percent(100.0))
963            Gap(SPACE_XS)
964        };
965        let row_eleventh_style: Style = style! {
966            Width(Length::Percent(100.0))
967            Height(Length::Px(geometry.get_control_md()))
968            Padding(Edges::symmetric(0.0, SPACE_MD))
969            JustifyContent::SpaceBetween
970            AlignItems::Center
971            Gap(SPACE_SM)
972            Background(bg_surface.get_bg())
973            Border::new(geometry.get_border_width(), bg_surface.get_border())
974            Radius(geometry.get_radius_md())
975            Overflow::Hidden
976            CursorIcon::Pointer
977        };
978        let text_fifth_style: Style = style! {
979            FlexGrow(1.0)
980            FlexShrink(1.0)
981            MinWidth(Length::Px(0.0))
982            FontSize(14.0)
983            TextColor(bg_surface.get_fg())
984            TextOverflow::Ellipsis
985        };
986        let canvas_secondary_style: Style = style! {
987            Width(Length::Px(12.0))
988            Height(Length::Px(12.0))
989            FlexShrink(0.0)
990        };
991        let column_sixth_style: Style = style! {
992            if init_open { Display::Flex } else { Display::None }
993            if init_open { PointerEvents::Auto } else { PointerEvents::None }
994            Width(Length::Percent(100.0))
995            Padding(Edges::all(CONTROL_INSET))
996            Gap(CONTROL_INSET)
997            Background(card_surface.get_bg())
998            Border::new(geometry.get_border_width(), card_surface.get_border())
999            Radius(menu_radius)
1000            geometry.get_shadow_md()
1001            Overflow::Hidden
1002            ZIndex(Z_INDEX_FLOATING)
1003        };
1004        let wrapper: NodeId = view! {
1005            column {
1006                style: column_fifth_style
1007                row {
1008                    style: row_eleventh_style
1009                    on_click: on_toggle
1010                    text {
1011                        style: text_fifth_style
1012                        { selected_text }
1013                    }
1014                    canvas {
1015                        node_ref: chevron
1016                        style: canvas_secondary_style
1017                        painter: paint_chevron
1018                    }
1019                }
1020                column {
1021                    node_ref: menu
1022                    style: column_sixth_style
1023                    ..option_rows_for_menu
1024                }
1025            }
1026        };
1027        let mut owned_nodes: Vec<NodeId> =
1028            Vec::with_capacity(option_rows.len() + option_texts.len() + 1);
1029        owned_nodes.push(chevron);
1030        owned_nodes.extend(option_rows.iter().copied());
1031        owned_nodes.extend(option_texts.iter().copied());
1032        let handle_open: SceneHandle = ctx.get_scene().clone();
1033        let handle_paint: SceneHandle = ctx.get_scene().clone();
1034        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(init_open));
1035        let prev_paint: Cell<(usize, Option<usize>, ThemeKey)> =
1036            Cell::new((init_sel, None, init_tok.key()));
1037        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1038            let _: Effect =
1039                EuvOverlayStack::bind_signal(open, SELECT_OVERLAY_NAME, Z_INDEX_DRAWER - 10);
1040            let _: Effect = Effect::new(move || {
1041                let cur_sel: usize = selected.get();
1042                let cur_hov: Option<usize> = hovered_idx.get();
1043                let tok: ThemeTokens = use_live_tokens(base_tokens);
1044                let (old_sel, old_hov, old_key): (usize, Option<usize>, ThemeKey) =
1045                    prev_paint.replace((cur_sel, cur_hov, tok.key()));
1046                if old_sel == cur_sel && old_hov == cur_hov && old_key == tok.key() {
1047                    return;
1048                }
1049                let live_p: ThemePalette = tok.get_palette();
1050                handle_paint.with_write(
1051                    |tree: &mut SceneTree| {
1052                        for (idx, (&row_id, &txt_id)) in
1053                            option_rows.iter().zip(option_texts.iter()).enumerate()
1054                        {
1055                            let is_sel: bool = idx == cur_sel;
1056                            let is_hov: bool = cur_hov == Some(idx);
1057                            let (row_bg, txt_fg): (Color, Color) =
1058                                Self::option_colors(live_p, is_sel, is_hov);
1059                            let (hov_bg, _): (Color, Color) =
1060                                Self::option_colors(live_p, is_sel, true);
1061                            if let Some(item_count) = tree.get_node_mut(row_id) {
1062                                let paint: &mut PaintStyle =
1063                                    item_count.get_mut_style().get_mut_paint();
1064                                let _: &mut PaintStyle = paint.set_background(Some(row_bg));
1065                                let mut hover_p: PaintStyle = *paint;
1066                                let _: &mut PaintStyle = hover_p.set_background(Some(hov_bg));
1067                                let _: &mut SceneNode = item_count.set_hover_style(Some(hover_p));
1068                                tree.mark_dirty(row_id, DIRTY_PAINT);
1069                            }
1070                            if let Some(node_entry) = tree.get_node_mut(txt_id) {
1071                                let _: &mut TextStyle = node_entry
1072                                    .get_mut_style()
1073                                    .get_mut_text()
1074                                    .set_color(txt_fg)
1075                                    .set_weight(if is_sel {
1076                                        FontWeight::Medium
1077                                    } else {
1078                                        FontWeight::Normal
1079                                    });
1080                                let mut dirty_txt: u16 = DIRTY_LAYOUT | DIRTY_TEXT;
1081                                dirty_txt |= DIRTY_PAINT;
1082                                tree.mark_dirty(txt_id, dirty_txt);
1083                            }
1084                        }
1085                        if old_key != tok.key() {
1086                            tree.mark_dirty(chevron, DIRTY_PAINT);
1087                        }
1088                    },
1089                    (),
1090                );
1091            });
1092            Effect::new(move || {
1093                let is_open: bool = open.get();
1094                let was_open: bool = prev_open.replace(is_open);
1095                if is_open == was_open {
1096                    return;
1097                }
1098                if is_open {
1099                    handle_open.with_write(
1100                        |tree: &mut SceneTree| {
1101                            tree.cancel_subtree_transitions(menu);
1102                            let (from_opacity, from_tx, from_ty, from_scale): (f32, f32, f32, f32) =
1103                                tree.get_node(menu)
1104                                    .map(|scene_node: &SceneNode| {
1105                                        let computed_style: &Style = scene_node.style_ref();
1106                                        if computed_style.get_layout().get_display()
1107                                            == Display::Flex
1108                                        {
1109                                            let transform_val: Transform2D =
1110                                                computed_style.get_paint().get_transform();
1111                                            (
1112                                                computed_style
1113                                                    .get_paint()
1114                                                    .get_opacity()
1115                                                    .clamp(0.0, 1.0),
1116                                                transform_val.get_translate_x(),
1117                                                transform_val.get_translate_y(),
1118                                                transform_val.get_scale_x().clamp(0.5, 1.0),
1119                                            )
1120                                        } else {
1121                                            (0.0, 0.0, -SELECT_SLIDE_OFFSET_Y, SELECT_CLOSED_SCALE)
1122                                        }
1123                                    })
1124                                    .unwrap_or((
1125                                        0.0,
1126                                        0.0,
1127                                        -SELECT_SLIDE_OFFSET_Y,
1128                                        SELECT_CLOSED_SCALE,
1129                                    ));
1130                            if let Some(normal_vec) = tree.get_node_mut(menu) {
1131                                let element_style: &mut Style = normal_vec.get_mut_style();
1132                                let _: &mut LayoutStyle =
1133                                    element_style.get_mut_layout().set_display(Display::Flex);
1134                                let _: &mut PaintStyle = element_style
1135                                    .get_mut_paint()
1136                                    .set_pointer_events(PointerEvents::Auto);
1137                            }
1138                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1139                            tree.mark_dirty(menu, dirty_l | DIRTY_PAINT);
1140                            tree.start_transition(
1141                                NodeTransition::slide_fade(
1142                                    menu,
1143                                    Point::new(from_tx, from_ty),
1144                                    Point::new(0.0, 0.0),
1145                                    from_opacity,
1146                                    1.0,
1147                                    motion_duration(MOTION_STANDARD_SECS),
1148                                    false,
1149                                )
1150                                .with_scale(from_scale, 1.0)
1151                                .with_easing(MOTION_EASE_ENTER),
1152                            );
1153                        },
1154                        (),
1155                    );
1156                } else {
1157                    let _: bool = hovered_idx.set_if_changed(None);
1158                    handle_open.with_write(
1159                        |tree: &mut SceneTree| {
1160                            tree.cancel_subtree_transitions(menu);
1161                            let (cur_opacity, cur_tx, cur_ty, cur_scale): (f32, f32, f32, f32) =
1162                                tree.get_node(menu)
1163                                    .map(|target_node: &SceneNode| {
1164                                        let paint: PaintStyle = target_node.style_ref().get_paint();
1165                                        let object_transform: Transform2D = paint.get_transform();
1166                                        (
1167                                            paint.get_opacity().clamp(0.0, 1.0),
1168                                            object_transform.get_translate_x(),
1169                                            object_transform.get_translate_y(),
1170                                            object_transform.get_scale_x().clamp(0.5, 1.0),
1171                                        )
1172                                    })
1173                                    .unwrap_or((1.0, 0.0, 0.0, 1.0));
1174                            if let Some(total_len) = tree.get_node_mut(menu) {
1175                                let _: &mut PaintStyle = total_len
1176                                    .get_mut_style()
1177                                    .get_mut_paint()
1178                                    .set_pointer_events(PointerEvents::None);
1179                            }
1180                            tree.mark_dirty(menu, DIRTY_PAINT);
1181                            tree.start_transition(
1182                                NodeTransition::slide_fade(
1183                                    menu,
1184                                    Point::new(cur_tx, cur_ty),
1185                                    Point::new(0.0, -SELECT_SLIDE_OFFSET_Y),
1186                                    cur_opacity,
1187                                    0.0,
1188                                    motion_duration(MOTION_STANDARD_SECS),
1189                                    true,
1190                                )
1191                                .with_scale(cur_scale, SELECT_CLOSED_SCALE)
1192                                .with_easing(MOTION_EASE_EXIT),
1193                            );
1194                        },
1195                        (),
1196                    );
1197                }
1198            })
1199        });
1200        ctx.get_scene().with_write(
1201            |tree: &mut SceneTree| {
1202                for (idx, &row_id) in owned_nodes.iter().skip(1).take(options.len()).enumerate() {
1203                    let (hov_bg, _): (Color, Color) =
1204                        Self::option_colors(theme_palette, idx == init_sel, true);
1205                    if let Some(item_count_primary) = tree.get_node_mut(row_id) {
1206                        let mut hover_p: PaintStyle = item_count_primary.style_ref().get_paint();
1207                        let _: &mut PaintStyle = hover_p.set_background(Some(hov_bg));
1208                        let _: &mut SceneNode = item_count_primary.set_hover_style(Some(hover_p));
1209                    }
1210                }
1211                mark_theme_owned(tree, owned_nodes.as_slice());
1212                tree.attach_scope(menu, scope);
1213            },
1214            (),
1215        );
1216        wrapper
1217    }
1218}
1219
1220/// Declarative `#[component]` implementation for `EuvRating`.
1221#[component]
1222/// Inherent implementation of [`EuvRating`].
1223impl EuvRating {
1224    /// Renders `EuvRating` into the ambient framework-managed `Context`.
1225    ///
1226    /// Star canvases read live theme tokens inside their painter and track both `value` and the ambient theme so
1227    /// switching themes repaints stars without stale colors.
1228    ///
1229    /// # Arguments
1230    ///
1231    /// - `&Self` - Component descriptor reference.
1232    ///
1233    /// # Returns
1234    ///
1235    /// - `NodeId` - Mounted root scene node handle.
1236    fn render(&self) -> NodeId {
1237        let mut ctx: Context = current_context();
1238        let base_tokens: ThemeTokens = self.get_tokens();
1239        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1240        let geometry: ThemeGeometry = init_tok.get_geometry();
1241        let value: Signal<usize> = self.get_value();
1242        let init_val: usize = value.get_untracked();
1243        let max_s: usize = self.get_max_stars().max(1);
1244        let mut star_cells: Vec<NodeId> = Vec::with_capacity(max_s);
1245        let mut badges: Vec<NodeId> = Vec::with_capacity(max_s);
1246        for star_idx in 1..=max_s {
1247            let mut star_canvas: NodeId = NodeId::default();
1248            let on_rate = move |_: &UiEvent| {
1249                let _: bool = value.set_if_changed(star_idx);
1250            };
1251            let paint_star = move |bounds: Rect, display_list: &mut DisplayList| {
1252                let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
1253                let active: bool = value.get_untracked() >= star_idx;
1254                let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
1255                let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
1256                let outer_r: f32 = (bounds.get_width().min(bounds.get_height()) * 0.44).max(4.0);
1257                let inner_r: f32 = outer_r * 0.44;
1258                let col: Color = if active {
1259                    live_p.get_warning()
1260                } else {
1261                    live_p.get_switch_track_off()
1262                };
1263                let center: Point = Point::new(cx, cy);
1264                for item_index in 0..10 {
1265                    let a0: f32 = (item_index as f32) * (TAU / 10.0) - FRAC_PI_2;
1266                    let a1: f32 = ((item_index + 1) as f32) * (TAU / 10.0) - FRAC_PI_2;
1267                    let r0: f32 = if item_index % 2 == 0 {
1268                        outer_r
1269                    } else {
1270                        inner_r
1271                    };
1272                    let r1: f32 = if item_index % 2 == 0 {
1273                        inner_r
1274                    } else {
1275                        outer_r
1276                    };
1277                    let (s0, c0): (f32, f32) = a0.sin_cos();
1278                    let (s1, c1): (f32, f32) = a1.sin_cos();
1279                    display_list.push(DrawCommand::Triangle {
1280                        p0: center,
1281                        p1: Point::new(cx + c0 * r0, cy + s0 * r0),
1282                        p2: Point::new(cx + c1 * r1, cy + s1 * r1),
1283                        color: col,
1284                    });
1285                }
1286            };
1287            let row_tenth_style: Style = style! {
1288                Padding(Edges::all(SPACE_XS))
1289                Radius(geometry.get_radius_sm())
1290                CursorIcon::Pointer
1291            };
1292            let canvas_style: Style = style! {
1293                Width(Length::Px(20.0))
1294                Height(Length::Px(20.0))
1295            };
1296            let cell: NodeId = view! {
1297                row {
1298                    style: row_tenth_style
1299                    role: A11yRole::Button
1300                    a11y_label: format!("Rate {star_idx} of {max_s}")
1301                    on_click: on_rate
1302                    canvas {
1303                        node_ref: star_canvas
1304                        style: canvas_style
1305                        painter: paint_star
1306                    }
1307                }
1308            };
1309            star_cells.push(cell);
1310            badges.push(star_canvas);
1311        }
1312        let row_ninth_style: Style = style! {
1313            AlignItems::Center
1314            Gap(SPACE_XS)
1315        };
1316        let row: NodeId = view! {
1317            row {
1318                style: row_ninth_style
1319            }
1320        };
1321        if !star_cells.is_empty() {
1322            ctx.append_many(row, star_cells.as_slice());
1323        }
1324        let owned_badges: Vec<NodeId> = badges.clone();
1325        let handle: SceneHandle = ctx.get_scene().clone();
1326        let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_val, init_tok.key()));
1327        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1328            Effect::new(move || {
1329                let next_val: usize = value.get();
1330                let tok: ThemeTokens = use_live_tokens(base_tokens);
1331                let (old_val, old_key): (usize, ThemeKey) =
1332                    prev_state.replace((next_val, tok.key()));
1333                if old_val == next_val && old_key == tok.key() {
1334                    return;
1335                }
1336                handle.with_write(
1337                    |tree: &mut SceneTree| {
1338                        for blue_val in badges.iter().copied() {
1339                            tree.mark_dirty(blue_val, DIRTY_PAINT);
1340                        }
1341                    },
1342                    (),
1343                );
1344            })
1345        });
1346        ctx.get_scene().with_write(
1347            |tree: &mut SceneTree| {
1348                mark_theme_owned(tree, owned_badges.as_slice());
1349                tree.attach_scope(row, scope);
1350            },
1351            (),
1352        );
1353        row
1354    }
1355}
1356
1357/// Fluent swatch preset builder for `EuvColorPicker`.
1358impl EuvColorPicker {
1359    /// Overrides the clickable color swatch presets fluently.
1360    ///
1361    /// # Arguments
1362    ///
1363    /// - `Self` - Source color picker.
1364    /// - `Vec<Color>` - Custom swatch palette colors.
1365    ///
1366    /// # Returns
1367    ///
1368    /// - `Self` - Updated color picker.
1369    #[must_use]
1370    pub fn presets(mut self, presets: Vec<Color>) -> Self {
1371        self.set_presets(presets);
1372        self
1373    }
1374}
1375
1376/// Declarative `#[component]` implementation for `EuvColorPicker`.
1377#[component]
1378/// Inherent implementation of [`EuvColorPicker`].
1379impl EuvColorPicker {
1380    /// Renders `EuvColorPicker` into the ambient framework-managed `Context`.
1381    ///
1382    /// Both the preview tile and preset swatches are marked theme-owned so their exact literal colors are never
1383    /// rewritten by generic palette remapping, while their active/idle borders update reactively from live tokens.
1384    ///
1385    /// # Arguments
1386    ///
1387    /// - `&Self` - Component descriptor reference.
1388    ///
1389    /// # Returns
1390    ///
1391    /// - `NodeId` - Mounted root scene node handle.
1392    fn render(&self) -> NodeId {
1393        let mut ctx: Context = current_context();
1394        let base_tokens: ThemeTokens = self.get_tokens();
1395        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1396        let theme_palette: ThemePalette = init_tok.get_palette();
1397        let geometry: ThemeGeometry = init_tok.get_geometry();
1398        let bg_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Background);
1399        let sig: Signal<Color> = self.get_value();
1400        let Self { presets, .. } = self;
1401        let swatches: Vec<Color> = if presets.is_empty() {
1402            COLOR_PICKER_DEFAULTS
1403                .iter()
1404                .copied()
1405                .map(Color::hex)
1406                .collect()
1407        } else {
1408            presets.clone()
1409        };
1410        let init_color: Color = sig.get_untracked();
1411        let border_w: f32 = geometry.get_border_width();
1412        let mut preview: NodeId = NodeId::default();
1413        let mut swatch_row: NodeId = NodeId::default();
1414        let swatch_nodes: Vec<NodeId> = swatches
1415            .iter()
1416            .copied()
1417            .map(|swatch_color: Color| {
1418                let active: bool = init_color == swatch_color;
1419                let swatch_label: String = format!(
1420                    "#{:02X}{:02X}{:02X}",
1421                    swatch_color.get_red(),
1422                    swatch_color.get_green(),
1423                    swatch_color.get_blue()
1424                );
1425                let on_pick = move |_: &UiEvent| {
1426                    let _: bool = sig.set_if_changed(swatch_color);
1427                };
1428                let view_secondary_style: Style = style! {
1429                    Width(Length::Px(26.0))
1430                    Height(Length::Px(26.0))
1431                    Radius(geometry.get_radius_sm())
1432                    Overflow::Hidden
1433                    Background(swatch_color)
1434                    Border::new(border_w, if active { theme_palette.get_foreground() } else { theme_palette.get_border() })
1435                    CursorIcon::Pointer
1436                };
1437                view! {
1438                    view {
1439                        style: view_secondary_style
1440                        role: A11yRole::Button
1441                        a11y_label: swatch_label
1442                        on_click: on_pick
1443                    }
1444                }
1445            })
1446            .collect();
1447        let hex_text = move || -> String {
1448            let color_value: Color = sig.get();
1449            format!(
1450                "#{:02X}{:02X}{:02X}",
1451                color_value.get_red(),
1452                color_value.get_green(),
1453                color_value.get_blue()
1454            )
1455        };
1456        let column_quaternary_style: Style = style! {
1457            Width(Length::Percent(100.0))
1458            Gap(SPACE_SM)
1459        };
1460        let row_seventh_style: Style = style! {
1461            AlignItems::Center
1462            Gap(SPACE_SM)
1463        };
1464        let view_style: Style = style! {
1465            Width(Length::Px(24.0))
1466            Height(Length::Px(24.0))
1467            Radius(geometry.get_radius_sm())
1468            Overflow::Hidden
1469            Background(init_color)
1470            Border::new(border_w, theme_palette.get_border())
1471        };
1472        let text_quaternary_style: Style = style! {
1473            FontFamily::Monospace
1474            FontSize(13.0)
1475            FontWeight::Medium
1476            TextColor(bg_surface.get_fg())
1477        };
1478        let row_eighth_style: Style = style! {
1479            FlexWrap::Wrap
1480            Width(Length::Percent(100.0))
1481            Gap(SPACE_XS)
1482        };
1483        let root: NodeId = view! {
1484            column {
1485                style: column_quaternary_style
1486                row {
1487                    style: row_seventh_style
1488                    view {
1489                        node_ref: preview
1490                        style: view_style
1491                    }
1492                    text {
1493                        style: text_quaternary_style
1494                        { hex_text }
1495                    }
1496                }
1497                row {
1498                    node_ref: swatch_row
1499                    style: row_eighth_style
1500                }
1501            }
1502        };
1503        if !swatch_nodes.is_empty() {
1504            ctx.append_many(swatch_row, swatch_nodes.as_slice());
1505        }
1506        let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(swatch_nodes.len() + 1);
1507        owned_nodes.push(preview);
1508        owned_nodes.extend(swatch_nodes.iter().copied());
1509        let handle: SceneHandle = ctx.get_scene().clone();
1510        let prev_state: Cell<(Color, ThemeKey)> = Cell::new((init_color, init_tok.key()));
1511        let swatch_dirty: u16 = DIRTY_PAINT;
1512        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1513            Effect::new(move || {
1514                let next_color: Color = sig.get();
1515                let tok: ThemeTokens = use_live_tokens(base_tokens);
1516                let (old_color, old_key): (Color, ThemeKey) =
1517                    prev_state.replace((next_color, tok.key()));
1518                if old_color == next_color && old_key == tok.key() {
1519                    return;
1520                }
1521                let live_p: ThemePalette = tok.get_palette();
1522                let live_bw: f32 = tok.get_geometry().get_border_width();
1523                let active_border: Border = Border::new(live_bw, live_p.get_foreground());
1524                let idle_border: Border = Border::new(live_bw, live_p.get_border());
1525                handle.with_write(
1526                    |tree: &mut SceneTree| {
1527                        if let Some(item_count) = tree.get_node_mut(preview) {
1528                            let _: &mut PaintStyle = item_count
1529                                .get_mut_style()
1530                                .get_mut_paint()
1531                                .set_background(Some(next_color))
1532                                .set_border(idle_border);
1533                            tree.mark_dirty(preview, DIRTY_PAINT);
1534                        }
1535                        for (idx, col) in swatches.iter().copied().enumerate() {
1536                            if let Some(&sid) = swatch_nodes.get(idx)
1537                                && let Some(node_entry) = tree.get_node_mut(sid)
1538                            {
1539                                let next_border: Border = if col == next_color {
1540                                    active_border
1541                                } else {
1542                                    idle_border
1543                                };
1544                                let _: &mut PaintStyle = node_entry
1545                                    .get_mut_style()
1546                                    .get_mut_paint()
1547                                    .set_background(Some(col))
1548                                    .set_border(next_border);
1549                                tree.mark_dirty(sid, swatch_dirty);
1550                            }
1551                        }
1552                    },
1553                    (),
1554                );
1555            })
1556        });
1557        ctx.get_scene().with_write(
1558            |tree: &mut SceneTree| {
1559                mark_theme_owned(tree, owned_nodes.as_slice());
1560                tree.attach_scope(root, scope);
1561            },
1562            (),
1563        );
1564        root
1565    }
1566}
1567
1568/// Declarative `#[component]` implementation for `EuvTimePicker`.
1569#[component]
1570/// Inherent implementation of [`EuvTimePicker`].
1571impl EuvTimePicker {
1572    /// Renders `EuvTimePicker` into the ambient framework-managed `Context`.
1573    ///
1574    /// # Arguments
1575    ///
1576    /// - `&Self` - Component descriptor reference.
1577    ///
1578    /// # Returns
1579    ///
1580    /// - `NodeId` - Mounted root scene node handle.
1581    fn render(&self) -> NodeId {
1582        let mut ctx: Context = current_context();
1583        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
1584        let theme_palette: ThemePalette = tokens.get_palette();
1585        let geometry: ThemeGeometry = tokens.get_geometry();
1586        let card_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
1587        let sig: Signal<(u8, u8)> = self.get_value();
1588        let time_readout_text = move || -> String {
1589            let (hh, mm): (u8, u8) = sig.get();
1590            format!("{:02}:{:02}", hh % 24, mm % 60)
1591        };
1592        let on_hour_dec = move |_: &UiEvent| {
1593            let _: bool = {
1594                if let Some(mut updated_value) = sig.try_get_untracked() {
1595                    {
1596                        let item_val: &mut (u8, u8) = &mut updated_value;
1597                        let height_val: u8 = item_val.0 % 24;
1598                        item_val.0 = if height_val == 0 { 23 } else { height_val - 1 };
1599                    }
1600                    sig.set(updated_value)
1601                } else {
1602                    false
1603                }
1604            };
1605        };
1606        let on_hour_inc = move |_: &UiEvent| {
1607            let _: bool = {
1608                if let Some(mut updated_value) = sig.try_get_untracked() {
1609                    {
1610                        let tex_v: &mut (u8, u8) = &mut updated_value;
1611                        tex_v.0 = ((tex_v.0 % 24) + 1) % 24;
1612                    }
1613                    sig.set(updated_value)
1614                } else {
1615                    false
1616                }
1617            };
1618        };
1619        let on_min_dec = move |_: &UiEvent| {
1620            let _: bool = {
1621                if let Some(mut updated_value) = sig.try_get_untracked() {
1622                    {
1623                        let bary_v: &mut (u8, u8) = &mut updated_value;
1624                        bary_v.1 = ((bary_v.1 % 60) + 55) % 60;
1625                    }
1626                    sig.set(updated_value)
1627                } else {
1628                    false
1629                }
1630            };
1631        };
1632        let on_min_inc = move |_: &UiEvent| {
1633            let _: bool = {
1634                if let Some(mut updated_value) = sig.try_get_untracked() {
1635                    {
1636                        let sample_val: &mut (u8, u8) = &mut updated_value;
1637                        sample_val.1 = ((sample_val.1 % 60) + 5) % 60;
1638                    }
1639                    sig.set(updated_value)
1640                } else {
1641                    false
1642                }
1643            };
1644        };
1645        let preset_nodes: Vec<NodeId> = TIME_PRESETS
1646            .iter()
1647            .copied()
1648            .map(|(ph, pm): (u8, u8)| {
1649                let on_preset = move |_: &UiEvent| {
1650                    let _: bool = sig.set_if_changed((ph, pm));
1651                };
1652                EuvButton::new(format!("{ph:02}:{pm:02}"), tokens)
1653                    .secondary()
1654                    .small()
1655                    .on_click(on_preset)
1656                    .mount()
1657            })
1658            .collect();
1659        let mut preset_row: NodeId = NodeId::default();
1660        let column_tertiary_style: Style = style! {
1661            Width(Length::Percent(100.0))
1662            Gap(SPACE_SM)
1663        };
1664        let row_quaternary_style: Style = style! {
1665            FlexWrap::Wrap
1666            AlignItems::Center
1667            Gap(SPACE_XS)
1668        };
1669        let text_secondary_style: Style = style! {
1670            FontSize(11.0)
1671            TextColor(theme_palette.get_muted_foreground())
1672        };
1673        let row_fifth_style: Style = style! {
1674            Height(Length::Px(geometry.get_control_sm()))
1675            MinWidth(Length::Px(76.0))
1676            FlexShrink(0.0)
1677            Padding(Edges::symmetric(0.0, SPACE_MD))
1678            JustifyContent::Center
1679            AlignItems::Center
1680            Background(card_surface.get_bg())
1681            Border::new(geometry.get_border_width(), card_surface.get_border())
1682            Radius(geometry.get_radius_sm())
1683            Overflow::Hidden
1684        };
1685        let text_tertiary_style: Style = style! {
1686            FontFamily::Monospace
1687            FontSize(14.0)
1688            FontWeight::SemiBold
1689            TextColor(card_surface.get_fg())
1690            TextAlign::Center
1691            TextOverflow::Clip
1692        };
1693        let row_sixth_style: Style = style! {
1694            FlexWrap::Wrap
1695            Width(Length::Percent(100.0))
1696            Gap(SPACE_XS)
1697        };
1698        let root: NodeId = view! {
1699            column {
1700                style: column_tertiary_style
1701                row {
1702                    style: row_quaternary_style
1703                    text {
1704                        style: text_secondary_style
1705                        { TIME_HOUR_LABEL }
1706                    }
1707                    EuvButton {
1708                        label: STEP_MINUS.to_string()
1709                        tokens: tokens
1710                        outline()
1711                        small()
1712                        on_click: on_hour_dec
1713                    }
1714                    EuvButton {
1715                        label: STEP_PLUS.to_string()
1716                        tokens: tokens
1717                        outline()
1718                        small()
1719                        on_click: on_hour_inc
1720                    }
1721                    row {
1722                        style: row_fifth_style
1723                        text {
1724                            style: text_tertiary_style
1725                            { time_readout_text }
1726                        }
1727                    }
1728                    EuvButton {
1729                        label: STEP_MINUS.to_string()
1730                        tokens: tokens
1731                        outline()
1732                        small()
1733                        on_click: on_min_dec
1734                    }
1735                    EuvButton {
1736                        label: STEP_PLUS.to_string()
1737                        tokens: tokens
1738                        outline()
1739                        small()
1740                        on_click: on_min_inc
1741                    }
1742                    text {
1743                        style: text_secondary_style
1744                        { TIME_MIN_LABEL }
1745                    }
1746                }
1747                row {
1748                    node_ref: preset_row
1749                    style: row_sixth_style
1750                }
1751            }
1752        };
1753        if !preset_nodes.is_empty() {
1754            ctx.append_many(preset_row, preset_nodes.as_slice());
1755        }
1756        root
1757    }
1758}
1759
1760/// Fluent placeholder builder for `EuvTagInput`.
1761impl EuvTagInput {
1762    /// Sets the tag input field placeholder text fluently.
1763    ///
1764    /// # Arguments
1765    ///
1766    /// - `Self` - Source tag input.
1767    /// - `TextValue` - Placeholder string.
1768    ///
1769    /// # Returns
1770    ///
1771    /// - `Self` - Updated tag input.
1772    #[must_use]
1773    pub fn placeholder<TextValue>(mut self, placeholder: TextValue) -> Self
1774    where
1775        TextValue: Into<String>,
1776    {
1777        self.set_placeholder(placeholder.into());
1778        self
1779    }
1780}
1781
1782/// Declarative `#[component]` implementation for `EuvTagInput`.
1783#[component]
1784/// Inherent implementation of [`EuvTagInput`].
1785impl EuvTagInput {
1786    /// Renders `EuvTagInput` into the ambient framework-managed `Context`.
1787    ///
1788    /// Tag chips render as full pills (`RADIUS_PILL`) with contrast-safe `SurfaceRole::Secondary` colors driven
1789    /// reactively by live ambient theme tokens so adding or removing tags after a theme switch never emits stale
1790    /// colors.
1791    ///
1792    /// # Arguments
1793    ///
1794    /// - `&Self` - Component descriptor reference.
1795    ///
1796    /// # Returns
1797    ///
1798    /// - `NodeId` - Mounted root scene node handle.
1799    fn render(&self) -> NodeId {
1800        let base_tokens: ThemeTokens = self.get_tokens();
1801        let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1802        let tags_sig: Signal<Vec<String>> = self.get_tags();
1803        let Self { placeholder, .. } = self;
1804        let resolved_ph: String = if placeholder.is_empty() {
1805            TAG_DEFAULT_PLACEHOLDER.to_string()
1806        } else {
1807            placeholder.clone()
1808        };
1809        let draft: Signal<String> = Signal::new(String::new());
1810        let build_chips = move || -> Vec<NodeId> {
1811            let live_tok: ThemeTokens = use_live_tokens(base_tokens);
1812            let live_p: ThemePalette = live_tok.get_palette();
1813            let live_g: ThemeGeometry = live_tok.get_geometry();
1814            let chip_surface: SurfaceColors = live_p.surface(SurfaceRole::Secondary);
1815            tags_sig
1816                .get()
1817                .into_iter()
1818                .enumerate()
1819                .map(|(idx, tag): (usize, String)| {
1820                    let on_remove = move |_: &UiEvent| {
1821                        let _: bool = {
1822                            if let Some(mut updated_value) = tags_sig.try_get_untracked() {
1823                                {
1824                                    let list: &mut Vec<String> = &mut updated_value;
1825                                    if idx < list.len() {
1826                                        let _: String = list.remove(idx);
1827                                    }
1828                                }
1829                                tags_sig.set(updated_value)
1830                            } else {
1831                                false
1832                            }
1833                        };
1834                    };
1835                    let row_tertiary_style: Style = style! {
1836                        JustifyContent::Center
1837                        AlignItems::Center
1838                        Padding(Edges::symmetric(SPACE_XS, SPACE_SM))
1839                        Gap(6.0)
1840                        Background(chip_surface.get_bg())
1841                        Border::new(live_g.get_border_width(), chip_surface.get_border())
1842                        Radius(RADIUS_PILL)
1843                        Overflow::Hidden
1844                        CursorIcon::Pointer
1845                    };
1846                    let text_style: Style = style! {
1847                        FontSize(12.0)
1848                        FontWeight::Medium
1849                        TextColor(chip_surface.get_fg())
1850                        TextAlign::Center
1851                    };
1852                    view! {
1853                        row {
1854                            style: row_tertiary_style
1855                            on_click: on_remove
1856                            text {
1857                                style: text_style
1858                                { format!("{tag}  x") }
1859                            }
1860                        }
1861                    }
1862                })
1863                .collect()
1864        };
1865        let on_add_tag = move |_: &UiEvent| {
1866            let raw: String = draft.get_untracked().trim().to_string();
1867            if !raw.is_empty() {
1868                let _: bool = {
1869                    if let Some(mut updated_value) = tags_sig.try_get_untracked() {
1870                        {
1871                            let list: &mut Vec<String> = &mut updated_value;
1872                            if !list.iter().any(|existing: &String| existing == &raw) {
1873                                list.push(raw.clone());
1874                            }
1875                        }
1876                        tags_sig.set(updated_value)
1877                    } else {
1878                        false
1879                    }
1880                };
1881                let _: bool = draft.set_if_changed(String::new());
1882            }
1883        };
1884        let column_style: Style = style! {
1885            Width(Length::Percent(100.0))
1886            Gap(SPACE_SM)
1887        };
1888        let row_style: Style = style! {
1889            FlexWrap::Wrap
1890            Width(Length::Percent(100.0))
1891            Gap(SPACE_XS)
1892        };
1893        let row_secondary_style: Style = style! {
1894            Width(Length::Percent(100.0))
1895            AlignItems::Center
1896            Gap(SPACE_XS)
1897        };
1898        let column_secondary_style: Style = style! {
1899            FlexGrow(1.0)
1900            MinWidth(Length::Px(80.0))
1901        };
1902        view! {
1903            column {
1904                style: column_style
1905                row {
1906                    style: row_style
1907                    bind_children: build_chips
1908                }
1909                row {
1910                    style: row_secondary_style
1911                    column {
1912                        style: column_secondary_style
1913                        EuvInput {
1914                            value: draft
1915                            placeholder: resolved_ph
1916                            tokens: init_tok
1917                        }
1918                    }
1919                    EuvButton {
1920                        label: TAG_ADD_LABEL.to_string()
1921                        tokens: init_tok
1922                        outline()
1923                        on_click: on_add_tag
1924                    }
1925                }
1926            }
1927        }
1928    }
1929}