1use super::*;
2
3#[component]
5impl EuvLabel {
7 fn render(&self) -> NodeId {
17 let tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
18 let p: ThemePalette = tok.get_palette();
19 let bg_surface: SurfaceColors = p.surface(SurfaceRole::Background);
20 let required: bool = self.get_required();
21 let Self { text, .. } = self;
22 view! {
23 row {
24 style: {
25 align: AlignItems::Center
26 gap: SPACE_XS
27 }
28 text {
29 style: {
30 flex_shrink: 1.0
31 min_width: Length::Px(0.0)
32 font_size: 13.0
33 font_weight: FontWeight::Medium
34 color: bg_surface.get_fg()
35 }
36 { text.clone() }
37 }
38 if required {
39 text {
40 style: {
41 flex_shrink: 0.0
42 font_size: 13.0
43 font_weight: FontWeight::Bold
44 color: p.get_destructive()
45 }
46 { STAR_FILLED }
47 }
48 }
49 }
50 }
51 }
52}
53
54impl EuvForm {
56 #[must_use]
67 pub fn field(mut self, node: NodeId) -> Self {
68 self.get_mut_fields().push(node);
69 self
70 }
71}
72
73#[component]
75impl EuvForm {
77 fn render(&self) -> NodeId {
87 let mut ctx: Context = current_context();
88 let Self { fields, .. } = self;
89 let root: NodeId = view! {
90 column {
91 style: {
92 width: Length::Percent(100.0)
93 gap: SPACE_MD
94 }
95 }
96 };
97 if !fields.is_empty() {
98 ctx.append_many(root, fields.as_slice());
99 }
100 root
101 }
102}
103
104#[component]
106impl EuvTextarea {
108 fn render(&self) -> NodeId {
118 let ctx: Context = current_context();
119 let tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
120 let p: ThemePalette = tok.get_palette();
121 let g: ThemeGeometry = tok.get_geometry();
122 let card_surface: SurfaceColors = p.surface(SurfaceRole::Card);
123 let sig: Signal<String> = self.get_value();
124 let initial: String = sig.get_untracked();
125 let caret: usize = initial.len();
126 let Self { placeholder, .. } = self;
127 let placeholder_owned: String = placeholder.clone();
128 let a11y_label: String = placeholder_owned.clone();
129 let on_change_cb = move |ev: &UiEvent| {
130 if let UiEventKind::Change(val) = ev.get_kind() {
131 let _: bool = sig.set_if_changed(val.clone());
132 }
133 };
134 let input_st: Style = style! {
135 width: Length::Percent(100.0)
136 height: Length::Px(96.0)
137 padding: Edges::all(SPACE_SM)
138 background: card_surface.get_bg()
139 border: (g.get_border_width(), card_surface.get_border())
140 radius: g.get_radius_md()
141 overflow: Overflow::Hidden
142 color: card_surface.get_fg()
143 font_size: g.get_font_body()
144 }
145 .with_overrides(self.get_style());
146 let node: NodeId = view! {
147 input {
148 value: initial.clone()
149 placeholder: placeholder_owned
150 caret: caret
151 multiline: true
152 style: input_st
153 role: A11yRole::TextInput
154 a11y_label: a11y_label.clone()
155 a11y_value: initial
156 on_change: on_change_cb
157 }
158 };
159 let handle: SceneHandle = ctx.get_scene().clone();
160 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
161 Effect::new(move || {
162 let next_val: String = sig.get();
163 handle.with_write(
164 |tree: &mut SceneTree| {
165 let mut changed: bool = false;
166 if let Some(n) = tree.get_node_mut(node) {
167 if let NodeKind::Input(inp) = n.get_mut_kind()
168 && inp.get_value() != &next_val
169 {
170 let len: usize = next_val.len();
171 let _: &mut InputNodeState = inp.set_value(next_val.clone());
172 let _: &mut InputNodeState = inp.set_caret(len);
173 changed = true;
174 }
175 if let Some(a11y) = n.get_mut_a11y().as_mut() {
176 let _: &mut A11yProps = a11y.set_value(next_val);
177 } else {
178 let mut next_a11y: A11yProps =
179 A11yProps::new(A11yRole::TextInput, a11y_label.clone());
180 let _: &mut A11yProps = next_a11y.set_value(next_val);
181 let _: &mut SceneNode = n.set_a11y(Some(next_a11y));
182 }
183 }
184 if changed {
185 tree.mark_dirty(node, DIRTY_PAINT);
186 }
187 },
188 (),
189 );
190 })
191 });
192 ctx.get_scene().with_write(
193 |tree: &mut SceneTree| {
194 tree.attach_scope(node, scope);
195 },
196 (),
197 );
198 node
199 }
200}
201
202impl EuvNumberInput {
204 #[must_use]
216 pub fn range(mut self, min: i64, max: i64) -> Self {
217 self.set_min(Some(min));
218 self.set_max(Some(max));
219 self
220 }
221
222 #[must_use]
233 pub fn step(mut self, step: i64) -> Self {
234 self.set_step(step.max(1));
235 self
236 }
237}
238
239#[component]
241impl EuvNumberInput {
243 fn render(&self) -> NodeId {
253 let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
254 let p: ThemePalette = tokens.get_palette();
255 let g: ThemeGeometry = tokens.get_geometry();
256 let card_surface: SurfaceColors = p.surface(SurfaceRole::Card);
257 let sig: Signal<i64> = self.get_value();
258 let step_v: i64 = if self.get_step() > 0 {
259 self.get_step()
260 } else {
261 1
262 };
263 let Self { min, max, .. } = self;
264 let raw_min: i64 = min.unwrap_or(i64::MIN / 2);
265 let raw_max: i64 = max.unwrap_or(i64::MAX / 2);
266 let (min_v, max_v): (i64, i64) = if raw_min <= raw_max {
267 (raw_min, raw_max)
268 } else {
269 (raw_max, raw_min)
270 };
271 let on_dec = move |_: &UiEvent| {
272 let _: bool =
273 sig.update(|v: &mut i64| *v = v.saturating_sub(step_v).clamp(min_v, max_v));
274 };
275 let on_inc = move |_: &UiEvent| {
276 let _: bool =
277 sig.update(|v: &mut i64| *v = v.saturating_add(step_v).clamp(min_v, max_v));
278 };
279 let value_text = move || -> String { sig.get().to_string() };
280 view! {
281 row {
282 style: {
283 align: AlignItems::Center
284 gap: SPACE_SM
285 }
286 EuvButton {
287 label: STEP_MINUS.to_string()
288 tokens: tokens
289 outline()
290 sm()
291 on_click: on_dec
292 }
293 row {
294 style: {
295 width: Length::Px(72.0)
296 height: Length::Px(g.get_control_sm())
297 justify: JustifyContent::Center
298 align: AlignItems::Center
299 background: card_surface.get_bg()
300 border: (g.get_border_width(), card_surface.get_border())
301 radius: g.get_radius_sm()
302 overflow: Overflow::Hidden
303 }
304 text {
305 style: {
306 font_size: 14.0
307 font_weight: FontWeight::Medium
308 color: card_surface.get_fg()
309 text_align: TextAlign::Center
310 }
311 { value_text }
312 }
313 }
314 EuvButton {
315 label: STEP_PLUS.to_string()
316 tokens: tokens
317 outline()
318 sm()
319 on_click: on_inc
320 }
321 }
322 }
323 }
324}
325
326impl EuvRadioGroup {
328 #[must_use]
339 pub fn state_colors(palette: ThemePalette, active: bool) -> (Color, Color, Color) {
340 if active {
341 let s: SurfaceColors = palette.surface(SurfaceRole::Primary);
342 (s.get_bg(), s.get_border(), s.get_fg())
343 } else {
344 let s: SurfaceColors = palette.surface(SurfaceRole::Card);
345 (s.get_bg(), palette.get_border(), COLOR_TRANSPARENT)
346 }
347 }
348}
349
350#[component]
352impl EuvRadioGroup {
354 fn render(&self) -> NodeId {
367 let mut ctx: Context = current_context();
368 let base_tokens: ThemeTokens = self.get_tokens();
369 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
370 let p: ThemePalette = init_tok.get_palette();
371 let g: ThemeGeometry = init_tok.get_geometry();
372 let bg_surface: SurfaceColors = p.surface(SurfaceRole::Background);
373 let selected: Signal<usize> = self.get_selected();
374 let Self { options, .. } = self;
375 let init_sel: usize = selected.get_untracked();
376 let mut ring_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
377 let mut dot_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
378 let mut row_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
379 let option_labels: Vec<String> = options.clone();
380 for (idx, opt) in options.iter().enumerate() {
381 let active: bool = init_sel == idx;
382 let (ring_bg, ring_border, dot_bg): (Color, Color, Color) =
383 Self::state_colors(p, active);
384 let mut ring: NodeId = NodeId::default();
385 let mut dot: NodeId = NodeId::default();
386 let on_pick = move |_: &UiEvent| {
387 let _: bool = selected.set_if_changed(idx);
388 };
389 let item: NodeId = view! {
390 row {
391 style: {
392 align: AlignItems::Center
393 padding: Edges::symmetric(SPACE_XS, SPACE_SM)
394 radius: g.get_radius_sm()
395 gap: SPACE_SM
396 cursor: CursorIcon::Pointer
397 }
398 on_click: on_pick
399 row {
400 node_ref: ring
401 style: {
402 width: Length::Px(RADIO_RING_SIZE)
403 height: Length::Px(RADIO_RING_SIZE)
404 flex_shrink: 0.0
405 justify: JustifyContent::Center
406 align: AlignItems::Center
407 radius: RADIUS_PILL
408 overflow: Overflow::Hidden
409 border: (RADIO_RING_BORDER_WIDTH, ring_border)
410 background: ring_bg
411 }
412 view {
413 node_ref: dot
414 style: {
415 width: Length::Px(RADIO_DOT_SIZE)
416 height: Length::Px(RADIO_DOT_SIZE)
417 radius: RADIUS_PILL
418 background: dot_bg
419 }
420 }
421 }
422 text {
423 style: {
424 flex_grow: 1.0
425 flex_shrink: 1.0
426 min_width: Length::Px(0.0)
427 font_size: 14.0
428 color: bg_surface.get_fg()
429 }
430 { opt.clone() }
431 }
432 }
433 };
434 ring_nodes.push(ring);
435 dot_nodes.push(dot);
436 row_nodes.push(item);
437 }
438 let root: NodeId = view! {
439 column {
440 style: {
441 gap: SPACE_SM
442 }
443 }
444 };
445 if !row_nodes.is_empty() {
446 ctx.append_many(root, row_nodes.as_slice());
447 }
448 let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(ring_nodes.len() + dot_nodes.len());
449 owned_nodes.extend(ring_nodes.iter().copied());
450 owned_nodes.extend(dot_nodes.iter().copied());
451 let init_rows: Vec<NodeId> = row_nodes.clone();
452 let init_labels: Vec<String> = option_labels.clone();
453 let handle: SceneHandle = ctx.get_scene().clone();
454 let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_sel, init_tok.key()));
455 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
456 Effect::new(move || {
457 let next_sel: usize = selected.get();
458 let tok: ThemeTokens = use_live_tokens(base_tokens);
459 let (old_sel, old_key): (usize, ThemeKey) =
460 prev_state.replace((next_sel, tok.key()));
461 if old_sel == next_sel && old_key == tok.key() {
462 return;
463 }
464 let live_p: ThemePalette = tok.get_palette();
465 handle.with_write(
466 |tree: &mut SceneTree| {
467 for (idx, (&ring_id, &dot_id)) in
468 ring_nodes.iter().zip(dot_nodes.iter()).enumerate()
469 {
470 let is_active: bool = idx == next_sel;
471 let (ring_bg, ring_border, dot_bg): (Color, Color, Color) =
472 Self::state_colors(live_p, is_active);
473 if let Some(n) = tree.get_node_mut(ring_id) {
474 let _: &mut PaintStyle = n
475 .get_mut_style()
476 .get_mut_paint()
477 .set_background(Some(ring_bg))
478 .set_border(Border::new(RADIO_RING_BORDER_WIDTH, ring_border));
479 tree.mark_dirty(ring_id, DIRTY_PAINT);
480 }
481 if let Some(n) = tree.get_node_mut(dot_id) {
482 let _: &mut PaintStyle = n
483 .get_mut_style()
484 .get_mut_paint()
485 .set_background(Some(dot_bg));
486 tree.mark_dirty(dot_id, DIRTY_PAINT);
487 }
488 if let Some(&row_id) = row_nodes.get(idx)
489 && let Some(n) = tree.get_node_mut(row_id)
490 {
491 if let Some(a11y) = n.get_mut_a11y().as_mut() {
492 let _: &mut A11yProps = a11y.set_checked(Some(is_active));
493 } else if let Some(lbl) = option_labels.get(idx) {
494 let mut a11y: A11yProps =
495 A11yProps::new(A11yRole::Checkbox, lbl.clone());
496 let _: &mut A11yProps = a11y.set_checked(Some(is_active));
497 let _: &mut SceneNode = n.set_a11y(Some(a11y));
498 }
499 }
500 }
501 },
502 (),
503 );
504 })
505 });
506 ctx.get_scene().with_write(
507 |tree: &mut SceneTree| {
508 for (idx, &row_id) in init_rows.iter().enumerate() {
509 if let Some(n) = tree.get_node_mut(row_id)
510 && let Some(lbl) = init_labels.get(idx)
511 {
512 let mut a11y: A11yProps = A11yProps::new(A11yRole::Checkbox, lbl.clone());
513 let _: &mut A11yProps = a11y.set_checked(Some(idx == init_sel));
514 let _: &mut SceneNode = n.set_a11y(Some(a11y));
515 }
516 }
517 mark_theme_owned(tree, owned_nodes.as_slice());
518 tree.attach_scope(root, scope);
519 },
520 (),
521 );
522 root
523 }
524}
525
526impl EuvSlider {
528 #[must_use]
539 pub fn palette_colors(palette: ThemePalette) -> (Color, Color, Color, Color) {
540 let track_color: Color = palette.get_switch_track_off();
541 let primary_surface: SurfaceColors = palette.surface(SurfaceRole::Primary);
542 let fill_color: Color = primary_surface.get_bg();
543 let thumb_ring: Color = primary_surface.get_bg();
544 let thumb_fill: Color = primary_surface.get_fg();
545 (track_color, fill_color, thumb_fill, thumb_ring)
546 }
547}
548
549#[component]
551impl EuvSlider {
553 fn render(&self) -> NodeId {
567 let mut ctx: Context = current_context();
568 let base_tokens: ThemeTokens = self.get_tokens();
569 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
570 let p: ThemePalette = init_tok.get_palette();
571 let value: Signal<f32> = self.get_value();
572 let min_v: f32 = self.get_min();
573 let max_v: f32 = self.get_max();
574 let span: f32 = (max_v - min_v).max(0.001);
575 let init_val: f32 = value.get_untracked();
576 let mut track: NodeId = NodeId::default();
577 let paint_slider = move |bounds: Rect, dl: &mut DisplayList| {
578 let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
579 let (track_color, fill_color, thumb_fill, thumb_ring): (Color, Color, Color, Color) =
580 Self::palette_colors(live_p);
581 let pct: f32 = ((value.get_untracked() - min_v) / span).clamp(0.0, 1.0);
582 let track_h: f32 = SLIDER_TRACK_HEIGHT;
583 let track_y: f32 = bounds.get_y() + (bounds.get_height() - track_h) * 0.5;
584 let pad_x: f32 = SLIDER_THUMB_RADIUS;
585 let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(8.0);
586 let track_x: f32 = bounds.get_x() + pad_x;
587 let track_rect: Rect = Rect::new(track_x, track_y, track_w, track_h);
588 let pill_radius: CornerRadius = CornerRadius::all(RADIUS_PILL);
589 let fill_w: f32 = (track_w * pct).clamp(0.0, track_w);
590 let thumb_cx: f32 = track_x + fill_w;
591 let thumb_cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
592 if pct <= SLIDER_PCT_EPS {
593 dl.push(DrawCommand::FillRoundedRect {
594 rect: track_rect,
595 color: track_color,
596 radius: pill_radius,
597 border: Border::default(),
598 });
599 } else if pct >= 1.0 - SLIDER_PCT_EPS {
600 dl.push(DrawCommand::FillRoundedRect {
601 rect: track_rect,
602 color: fill_color,
603 radius: pill_radius,
604 border: Border::default(),
605 });
606 } else {
607 let split_x: f32 = thumb_cx.clamp(track_x, track_rect.right());
608 let left_w: f32 = (split_x - track_x).max(0.0);
609 let right_w: f32 = (track_rect.right() - split_x).max(0.0);
610 dl.push(DrawCommand::PushRoundedClip {
611 rect: track_rect,
612 radius: pill_radius,
613 });
614 if left_w > 0.0 {
615 dl.push(DrawCommand::FillRoundedRect {
616 rect: Rect::new(track_x, track_y, left_w, track_h),
617 color: fill_color,
618 radius: CornerRadius::all(0.0),
619 border: Border::default(),
620 });
621 }
622 if right_w > 0.0 {
623 dl.push(DrawCommand::FillRoundedRect {
624 rect: Rect::new(split_x, track_y, right_w, track_h),
625 color: track_color,
626 radius: CornerRadius::all(0.0),
627 border: Border::default(),
628 });
629 }
630 dl.push(DrawCommand::PopClip);
631 }
632 let thumb_d: f32 = SLIDER_THUMB_RADIUS * 2.0;
633 dl.push(DrawCommand::FillRoundedRect {
634 rect: Rect::new(
635 thumb_cx - SLIDER_THUMB_RADIUS,
636 thumb_cy - SLIDER_THUMB_RADIUS,
637 thumb_d,
638 thumb_d,
639 ),
640 color: thumb_fill,
641 radius: pill_radius,
642 border: Border::new(SLIDER_THUMB_RING_WIDTH, thumb_ring),
643 });
644 };
645 let value_text = move || -> String { format!("{:.1}", value.get()) };
646 let row: NodeId = view! {
647 row {
648 style: {
649 width: Length::Percent(100.0)
650 height: Length::Px(42.0)
651 align: AlignItems::Center
652 gap: SPACE_SM
653 stop_event_propagation: true
654 }
655 canvas {
656 node_ref: track
657 style: {
658 flex_grow: 1.0
659 height: Length::Px(42.0)
660 stop_event_propagation: true
661 cursor: CursorIcon::Pointer
662 }
663 painter: paint_slider
664 }
665 row {
666 style: {
667 width: Length::Px(40.0)
668 justify: JustifyContent::End
669 align: AlignItems::Center
670 }
671 text {
672 style: {
673 font_size: 12.0
674 font_weight: FontWeight::Medium
675 color: p.get_muted_foreground()
676 }
677 { value_text }
678 }
679 }
680 }
681 };
682 let dragging: Rc<Cell<bool>> = Rc::new(Cell::new(false));
683 let scene_down: SceneHandle = ctx.get_scene().clone();
684 let drag_down: Rc<Cell<bool>> = dragging.clone();
685 ctx.on_pointer_down(track, move |ev: &UiEvent| {
686 drag_down.set(true);
687 if let UiEventKind::PointerDown(pos) = ev.get_kind()
688 && let Some(bounds) = scene_down.node_screen_bounds(track)
689 {
690 let pad_x: f32 = SLIDER_THUMB_RADIUS;
691 let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(1.0);
692 let frac: f32 =
693 ((pos.get_x() - (bounds.get_x() + pad_x)) / track_w).clamp(0.0, 1.0);
694 let next: f32 = (min_v + frac * span).clamp(min_v, max_v);
695 let _: bool = value.set_if_changed(next);
696 }
697 });
698 let scene_move: SceneHandle = ctx.get_scene().clone();
699 let drag_move: Rc<Cell<bool>> = dragging.clone();
700 ctx.on_pointer_move(track, move |ev: &UiEvent| {
701 if !drag_move.get() {
702 return;
703 }
704 if let UiEventKind::PointerMove(pos) = ev.get_kind()
705 && let Some(bounds) = scene_move.node_screen_bounds(track)
706 {
707 let pad_x: f32 = SLIDER_THUMB_RADIUS;
708 let track_w: f32 = (bounds.get_width() - pad_x * 2.0).max(1.0);
709 let frac: f32 =
710 ((pos.get_x() - (bounds.get_x() + pad_x)) / track_w).clamp(0.0, 1.0);
711 let next: f32 = (min_v + frac * span).clamp(min_v, max_v);
712 let _: bool = value.set_if_changed(next);
713 }
714 });
715 let drag_up: Rc<Cell<bool>> = dragging.clone();
716 ctx.on_pointer_up(track, move |_: &UiEvent| {
717 drag_up.set(false);
718 });
719 let drag_cancel: Rc<Cell<bool>> = dragging.clone();
720 ctx.on_pointer_cancel(track, move |_: &UiEvent| {
721 drag_cancel.set(false);
722 });
723 let drag_state: Rc<Cell<bool>> = dragging.clone();
724 let app_state_sig: Signal<AppState> = ctx.get_app_state();
725 let scene_watch: SceneHandle = ctx.get_scene().clone();
726 let prev_state: Cell<(f32, ThemeKey)> = Cell::new((init_val, init_tok.key()));
727 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
728 let _: Effect = Effect::new(move || {
729 if app_state_sig.get() != AppState::Active {
730 drag_state.set(false);
731 }
732 });
733 Effect::new(move || {
734 let next_val: f32 = value.get();
735 let tok: ThemeTokens = use_live_tokens(base_tokens);
736 let (old_val, old_key): (f32, ThemeKey) = prev_state.replace((next_val, tok.key()));
737 if old_val.to_bits() == next_val.to_bits() && old_key == tok.key() {
738 return;
739 }
740 scene_watch.with_write(
741 |tree: &mut SceneTree| {
742 if let Some(n) = tree.get_node_mut(track)
743 && let Some(a11y) = n.get_mut_a11y().as_mut()
744 {
745 let _: &mut A11yProps = a11y.set_value(format!("{next_val:.1}"));
746 }
747 tree.mark_dirty(track, DIRTY_PAINT);
748 },
749 (),
750 );
751 })
752 });
753 ctx.get_scene().with_write(
754 |tree: &mut SceneTree| {
755 if let Some(n) = tree.get_node_mut(track) {
756 let mut a11y: A11yProps =
757 A11yProps::new(A11yRole::Slider, SLIDER_A11Y_LABEL.to_string());
758 let _: &mut A11yProps = a11y.set_value(format!("{init_val:.1}"));
759 let _: &mut SceneNode = n.set_a11y(Some(a11y));
760 }
761 mark_theme_owned(tree, &[track]);
762 tree.attach_scope(track, scope);
763 },
764 (),
765 );
766 row
767 }
768}
769
770impl EuvSelect {
772 #[must_use]
784 pub fn option_colors(palette: ThemePalette, selected: bool, hovered: bool) -> (Color, Color) {
785 if selected {
786 let s: SurfaceColors = palette.surface(SurfaceRole::Primary);
787 if hovered {
788 let bg: Color = blend_over(s.get_fg().with_alpha(24), s.get_bg());
789 let fg: Color = palette.readable_foreground_with(s.get_fg(), bg);
790 (bg, fg)
791 } else {
792 (s.get_bg(), s.get_fg())
793 }
794 } else if hovered {
795 let s: SurfaceColors = palette.surface(SurfaceRole::Accent);
796 (s.get_bg(), s.get_fg())
797 } else {
798 let s: SurfaceColors = palette.surface(SurfaceRole::Card);
799 (COLOR_TRANSPARENT, s.get_fg())
800 }
801 }
802}
803
804#[component]
806impl EuvSelect {
808 fn render(&self) -> NodeId {
822 let mut ctx: Context = current_context();
823 let base_tokens: ThemeTokens = self.get_tokens();
824 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
825 let p: ThemePalette = init_tok.get_palette();
826 let g: ThemeGeometry = init_tok.get_geometry();
827 let bg_surface: SurfaceColors = p.surface(SurfaceRole::Background);
828 let card_surface: SurfaceColors = p.surface(SurfaceRole::Card);
829 let selected: Signal<usize> = self.get_selected();
830 let open: Signal<bool> = self.get_open();
831 let hovered_idx: Signal<Option<usize>> = Signal::new(None);
832 let Self { options, .. } = self;
833 let opts_for_label: Rc<[String]> = Rc::from(options.as_slice());
834 let init_sel: usize = selected.get_untracked();
835 let init_open: bool = open.get_untracked();
836 let menu_radius: f32 = g.get_radius_lg();
837 let item_radius: f32 = concentric_radius(menu_radius, CONTROL_INSET);
838 let mut menu: NodeId = NodeId::default();
839 let mut chevron: NodeId = NodeId::default();
840 let on_toggle = move |_: &UiEvent| {
841 let _: bool = open.update(|v: &mut bool| *v = !*v);
842 };
843 let selected_text = move || -> String {
844 let idx: usize = selected.get();
845 opts_for_label.get(idx).cloned().unwrap_or_default()
846 };
847 let paint_chevron = move |bounds: Rect, dl: &mut DisplayList| {
848 let chevron_color: Color = live_tokens_untracked(base_tokens)
849 .get_palette()
850 .get_muted_foreground();
851 let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
852 let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
853 dl.push(DrawCommand::Line {
854 from: Point::new(cx - 4.0, cy - 2.0),
855 to: Point::new(cx, cy + 2.5),
856 color: chevron_color,
857 width: 1.6,
858 });
859 dl.push(DrawCommand::Line {
860 from: Point::new(cx, cy + 2.5),
861 to: Point::new(cx + 4.0, cy - 2.0),
862 color: chevron_color,
863 width: 1.6,
864 });
865 };
866 let mut option_rows: Vec<NodeId> = Vec::with_capacity(options.len());
867 let mut option_texts: Vec<NodeId> = Vec::with_capacity(options.len());
868 for (idx, opt) in options.iter().enumerate() {
869 let is_sel: bool = init_sel == idx;
870 let (row_bg, txt_fg): (Color, Color) = Self::option_colors(p, is_sel, false);
871 let mut txt_id: NodeId = NodeId::default();
872 let on_pick = move |_: &UiEvent| {
873 let _: bool = selected.set_if_changed(idx);
874 let _: bool = open.set_if_changed(false);
875 };
876 let opt_row: NodeId = view! {
877 row {
878 style: {
879 width: Length::Percent(100.0)
880 height: Length::Px(g.get_control_sm())
881 padding: Edges::symmetric(0.0, SPACE_MD)
882 align: AlignItems::Center
883 background: row_bg
884 radius: item_radius
885 overflow: Overflow::Hidden
886 cursor: CursorIcon::Pointer
887 }
888 role: A11yRole::ListItem
889 a11y_label: opt.clone()
890 on_click: on_pick
891 text {
892 node_ref: txt_id
893 style: {
894 width: Length::Percent(100.0)
895 font_size: 13.0
896 font_weight: if is_sel { FontWeight::Medium } else { FontWeight::Normal }
897 color: txt_fg
898 text_overflow: TextOverflow::Ellipsis
899 }
900 { opt.clone() }
901 }
902 }
903 };
904 ctx.on_hover(opt_row, move |ev: &UiEvent| match ev.get_kind() {
905 UiEventKind::PointerEnter => {
906 let _: bool = hovered_idx.set_if_changed(Some(idx));
907 }
908 UiEventKind::PointerLeave => {
909 let _: bool = hovered_idx.update(|cur: &mut Option<usize>| {
910 if *cur == Some(idx) {
911 *cur = None;
912 }
913 });
914 }
915 _ => {}
916 });
917 option_rows.push(opt_row);
918 option_texts.push(txt_id);
919 }
920 let option_rows_for_menu: Vec<NodeId> = option_rows.clone();
921 let wrapper: NodeId = view! {
922 column {
923 style: {
924 width: Length::Percent(100.0)
925 gap: SPACE_XS
926 }
927 row {
928 style: {
929 width: Length::Percent(100.0)
930 height: Length::Px(g.get_control_md())
931 padding: Edges::symmetric(0.0, SPACE_MD)
932 justify: JustifyContent::SpaceBetween
933 align: AlignItems::Center
934 gap: SPACE_SM
935 background: bg_surface.get_bg()
936 border: (g.get_border_width(), bg_surface.get_border())
937 radius: g.get_radius_md()
938 overflow: Overflow::Hidden
939 cursor: CursorIcon::Pointer
940 }
941 on_click: on_toggle
942 text {
943 style: {
944 flex_grow: 1.0
945 flex_shrink: 1.0
946 min_width: Length::Px(0.0)
947 font_size: 14.0
948 color: bg_surface.get_fg()
949 text_overflow: TextOverflow::Ellipsis
950 }
951 { selected_text }
952 }
953 canvas {
954 node_ref: chevron
955 style: {
956 width: Length::Px(12.0)
957 height: Length::Px(12.0)
958 flex_shrink: 0.0
959 }
960 painter: paint_chevron
961 }
962 }
963 column {
964 node_ref: menu
965 style: {
966 display: if init_open { Display::Flex } else { Display::None }
967 pointer_events: if init_open { PointerEvents::Auto } else { PointerEvents::None }
968 width: Length::Percent(100.0)
969 padding: Edges::all(CONTROL_INSET)
970 gap: CONTROL_INSET
971 background: card_surface.get_bg()
972 border: (g.get_border_width(), card_surface.get_border())
973 radius: menu_radius
974 shadow: g.get_shadow_md()
975 overflow: Overflow::Hidden
976 z_index: Z_INDEX_FLOATING
977 }
978 ..option_rows_for_menu
979 }
980 }
981 };
982 let mut owned_nodes: Vec<NodeId> =
983 Vec::with_capacity(option_rows.len() + option_texts.len() + 1);
984 owned_nodes.push(chevron);
985 owned_nodes.extend(option_rows.iter().copied());
986 owned_nodes.extend(option_texts.iter().copied());
987 let handle_open: SceneHandle = ctx.get_scene().clone();
988 let handle_paint: SceneHandle = ctx.get_scene().clone();
989 let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(init_open));
990 let prev_paint: Cell<(usize, Option<usize>, ThemeKey)> =
991 Cell::new((init_sel, None, init_tok.key()));
992 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
993 let _: Effect =
994 EuvOverlayStack::bind_signal(open, SELECT_OVERLAY_NAME, Z_INDEX_DRAWER - 10);
995 let _: Effect = Effect::new(move || {
996 let cur_sel: usize = selected.get();
997 let cur_hov: Option<usize> = hovered_idx.get();
998 let tok: ThemeTokens = use_live_tokens(base_tokens);
999 let (old_sel, old_hov, old_key): (usize, Option<usize>, ThemeKey) =
1000 prev_paint.replace((cur_sel, cur_hov, tok.key()));
1001 if old_sel == cur_sel && old_hov == cur_hov && old_key == tok.key() {
1002 return;
1003 }
1004 let live_p: ThemePalette = tok.get_palette();
1005 handle_paint.with_write(
1006 |tree: &mut SceneTree| {
1007 for (idx, (&row_id, &txt_id)) in
1008 option_rows.iter().zip(option_texts.iter()).enumerate()
1009 {
1010 let is_sel: bool = idx == cur_sel;
1011 let is_hov: bool = cur_hov == Some(idx);
1012 let (row_bg, txt_fg): (Color, Color) =
1013 Self::option_colors(live_p, is_sel, is_hov);
1014 let (hov_bg, _): (Color, Color) =
1015 Self::option_colors(live_p, is_sel, true);
1016 if let Some(n) = tree.get_node_mut(row_id) {
1017 let paint: &mut PaintStyle = n.get_mut_style().get_mut_paint();
1018 let _: &mut PaintStyle = paint.set_background(Some(row_bg));
1019 let mut hover_p: PaintStyle = *paint;
1020 let _: &mut PaintStyle = hover_p.set_background(Some(hov_bg));
1021 let _: &mut SceneNode = n.set_hover_style(Some(hover_p));
1022 tree.mark_dirty(row_id, DIRTY_PAINT);
1023 }
1024 if let Some(n) = tree.get_node_mut(txt_id) {
1025 let _: &mut TextStyle = n
1026 .get_mut_style()
1027 .get_mut_text()
1028 .set_color(txt_fg)
1029 .set_weight(if is_sel {
1030 FontWeight::Medium
1031 } else {
1032 FontWeight::Normal
1033 });
1034 let mut dirty_txt: u16 = DIRTY_LAYOUT | DIRTY_TEXT;
1035 dirty_txt |= DIRTY_PAINT;
1036 tree.mark_dirty(txt_id, dirty_txt);
1037 }
1038 }
1039 if old_key != tok.key() {
1040 tree.mark_dirty(chevron, DIRTY_PAINT);
1041 }
1042 },
1043 (),
1044 );
1045 });
1046 Effect::new(move || {
1047 let is_open: bool = open.get();
1048 let was_open: bool = prev_open.replace(is_open);
1049 if is_open == was_open {
1050 return;
1051 }
1052 if is_open {
1053 handle_open.with_write(
1054 |tree: &mut SceneTree| {
1055 tree.cancel_subtree_transitions(menu);
1056 let (from_opacity, from_tx, from_ty, from_scale): (f32, f32, f32, f32) =
1057 tree.get_node(menu)
1058 .map(|n: &SceneNode| {
1059 let st: &Style = n.style_ref();
1060 if st.get_layout().get_display() == Display::Flex {
1061 let tr: Transform2D = st.get_paint().get_transform();
1062 (
1063 st.get_paint().get_opacity().clamp(0.0, 1.0),
1064 tr.get_translate_x(),
1065 tr.get_translate_y(),
1066 tr.get_scale_x().clamp(0.5, 1.0),
1067 )
1068 } else {
1069 (0.0, 0.0, -SELECT_SLIDE_OFFSET_Y, SELECT_CLOSED_SCALE)
1070 }
1071 })
1072 .unwrap_or((
1073 0.0,
1074 0.0,
1075 -SELECT_SLIDE_OFFSET_Y,
1076 SELECT_CLOSED_SCALE,
1077 ));
1078 if let Some(n) = tree.get_node_mut(menu) {
1079 let st: &mut Style = n.get_mut_style();
1080 let _: &mut LayoutStyle =
1081 st.get_mut_layout().set_display(Display::Flex);
1082 let _: &mut PaintStyle =
1083 st.get_mut_paint().set_pointer_events(PointerEvents::Auto);
1084 }
1085 let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1086 tree.mark_dirty(menu, dirty_l | DIRTY_PAINT);
1087 tree.start_transition(
1088 NodeTransition::slide_fade(
1089 menu,
1090 Point::new(from_tx, from_ty),
1091 Point::new(0.0, 0.0),
1092 from_opacity,
1093 1.0,
1094 motion_duration(MOTION_STANDARD_SECS),
1095 false,
1096 )
1097 .with_scale(from_scale, 1.0)
1098 .with_easing(MOTION_EASE_ENTER),
1099 );
1100 },
1101 (),
1102 );
1103 } else {
1104 let _: bool = hovered_idx.set_if_changed(None);
1105 handle_open.with_write(
1106 |tree: &mut SceneTree| {
1107 tree.cancel_subtree_transitions(menu);
1108 let (cur_opacity, cur_tx, cur_ty, cur_scale): (f32, f32, f32, f32) =
1109 tree.get_node(menu)
1110 .map(|n: &SceneNode| {
1111 let paint: PaintStyle = n.style_ref().get_paint();
1112 let tr: Transform2D = paint.get_transform();
1113 (
1114 paint.get_opacity().clamp(0.0, 1.0),
1115 tr.get_translate_x(),
1116 tr.get_translate_y(),
1117 tr.get_scale_x().clamp(0.5, 1.0),
1118 )
1119 })
1120 .unwrap_or((1.0, 0.0, 0.0, 1.0));
1121 if let Some(n) = tree.get_node_mut(menu) {
1122 let _: &mut PaintStyle = n
1123 .get_mut_style()
1124 .get_mut_paint()
1125 .set_pointer_events(PointerEvents::None);
1126 }
1127 tree.mark_dirty(menu, DIRTY_PAINT);
1128 tree.start_transition(
1129 NodeTransition::slide_fade(
1130 menu,
1131 Point::new(cur_tx, cur_ty),
1132 Point::new(0.0, -SELECT_SLIDE_OFFSET_Y),
1133 cur_opacity,
1134 0.0,
1135 motion_duration(MOTION_STANDARD_SECS),
1136 true,
1137 )
1138 .with_scale(cur_scale, SELECT_CLOSED_SCALE)
1139 .with_easing(MOTION_EASE_EXIT),
1140 );
1141 },
1142 (),
1143 );
1144 }
1145 })
1146 });
1147 ctx.get_scene().with_write(
1148 |tree: &mut SceneTree| {
1149 for (idx, &row_id) in owned_nodes.iter().skip(1).take(options.len()).enumerate() {
1150 let (hov_bg, _): (Color, Color) = Self::option_colors(p, idx == init_sel, true);
1151 if let Some(n) = tree.get_node_mut(row_id) {
1152 let mut hover_p: PaintStyle = n.style_ref().get_paint();
1153 let _: &mut PaintStyle = hover_p.set_background(Some(hov_bg));
1154 let _: &mut SceneNode = n.set_hover_style(Some(hover_p));
1155 }
1156 }
1157 mark_theme_owned(tree, owned_nodes.as_slice());
1158 tree.attach_scope(menu, scope);
1159 },
1160 (),
1161 );
1162 wrapper
1163 }
1164}
1165
1166#[component]
1168impl EuvRating {
1170 fn render(&self) -> NodeId {
1183 let mut ctx: Context = current_context();
1184 let base_tokens: ThemeTokens = self.get_tokens();
1185 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1186 let g: ThemeGeometry = init_tok.get_geometry();
1187 let value: Signal<usize> = self.get_value();
1188 let init_val: usize = value.get_untracked();
1189 let max_s: usize = self.get_max_stars().max(1);
1190 let mut star_cells: Vec<NodeId> = Vec::with_capacity(max_s);
1191 let mut badges: Vec<NodeId> = Vec::with_capacity(max_s);
1192 for star_idx in 1..=max_s {
1193 let mut star_canvas: NodeId = NodeId::default();
1194 let on_rate = move |_: &UiEvent| {
1195 let _: bool = value.set_if_changed(star_idx);
1196 };
1197 let paint_star = move |bounds: Rect, dl: &mut DisplayList| {
1198 let live_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
1199 let active: bool = value.get_untracked() >= star_idx;
1200 let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
1201 let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
1202 let outer_r: f32 = (bounds.get_width().min(bounds.get_height()) * 0.44).max(4.0);
1203 let inner_r: f32 = outer_r * 0.44;
1204 let col: Color = if active {
1205 live_p.get_warning()
1206 } else {
1207 live_p.get_switch_track_off()
1208 };
1209 let center: Point = Point::new(cx, cy);
1210 for i in 0..10 {
1211 let a0: f32 = (i as f32) * (TAU / 10.0) - FRAC_PI_2;
1212 let a1: f32 = ((i + 1) as f32) * (TAU / 10.0) - FRAC_PI_2;
1213 let r0: f32 = if i % 2 == 0 { outer_r } else { inner_r };
1214 let r1: f32 = if i % 2 == 0 { inner_r } else { outer_r };
1215 let (s0, c0): (f32, f32) = a0.sin_cos();
1216 let (s1, c1): (f32, f32) = a1.sin_cos();
1217 dl.push(DrawCommand::Triangle {
1218 p0: center,
1219 p1: Point::new(cx + c0 * r0, cy + s0 * r0),
1220 p2: Point::new(cx + c1 * r1, cy + s1 * r1),
1221 color: col,
1222 });
1223 }
1224 };
1225 let cell: NodeId = view! {
1226 row {
1227 style: {
1228 padding: Edges::all(2.0)
1229 radius: g.get_radius_sm()
1230 cursor: CursorIcon::Pointer
1231 }
1232 role: A11yRole::Button
1233 a11y_label: format!("Rate {star_idx} of {max_s}")
1234 on_click: on_rate
1235 canvas {
1236 node_ref: star_canvas
1237 style: {
1238 width: Length::Px(20.0)
1239 height: Length::Px(20.0)
1240 }
1241 painter: paint_star
1242 }
1243 }
1244 };
1245 star_cells.push(cell);
1246 badges.push(star_canvas);
1247 }
1248 let row: NodeId = view! {
1249 row {
1250 style: {
1251 align: AlignItems::Center
1252 gap: SPACE_XS
1253 }
1254 }
1255 };
1256 if !star_cells.is_empty() {
1257 ctx.append_many(row, star_cells.as_slice());
1258 }
1259 let owned_badges: Vec<NodeId> = badges.clone();
1260 let handle: SceneHandle = ctx.get_scene().clone();
1261 let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_val, init_tok.key()));
1262 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1263 Effect::new(move || {
1264 let next_val: usize = value.get();
1265 let tok: ThemeTokens = use_live_tokens(base_tokens);
1266 let (old_val, old_key): (usize, ThemeKey) =
1267 prev_state.replace((next_val, tok.key()));
1268 if old_val == next_val && old_key == tok.key() {
1269 return;
1270 }
1271 handle.with_write(
1272 |tree: &mut SceneTree| {
1273 for b in badges.iter().copied() {
1274 tree.mark_dirty(b, DIRTY_PAINT);
1275 }
1276 },
1277 (),
1278 );
1279 })
1280 });
1281 ctx.get_scene().with_write(
1282 |tree: &mut SceneTree| {
1283 mark_theme_owned(tree, owned_badges.as_slice());
1284 tree.attach_scope(row, scope);
1285 },
1286 (),
1287 );
1288 row
1289 }
1290}
1291
1292impl EuvColorPicker {
1294 #[must_use]
1305 pub fn presets(mut self, presets: Vec<Color>) -> Self {
1306 self.set_presets(presets);
1307 self
1308 }
1309}
1310
1311#[component]
1313impl EuvColorPicker {
1315 fn render(&self) -> NodeId {
1328 let mut ctx: Context = current_context();
1329 let base_tokens: ThemeTokens = self.get_tokens();
1330 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1331 let p: ThemePalette = init_tok.get_palette();
1332 let g: ThemeGeometry = init_tok.get_geometry();
1333 let bg_surface: SurfaceColors = p.surface(SurfaceRole::Background);
1334 let sig: Signal<Color> = self.get_value();
1335 let Self { presets, .. } = self;
1336 let swatches: Vec<Color> = if presets.is_empty() {
1337 COLOR_PICKER_DEFAULTS
1338 .iter()
1339 .copied()
1340 .map(Color::hex)
1341 .collect()
1342 } else {
1343 presets.clone()
1344 };
1345 let init_color: Color = sig.get_untracked();
1346 let border_w: f32 = g.get_border_width();
1347 let mut preview: NodeId = NodeId::default();
1348 let mut swatch_row: NodeId = NodeId::default();
1349 let swatch_nodes: Vec<NodeId> = swatches
1350 .iter()
1351 .copied()
1352 .map(|swatch_color: Color| {
1353 let active: bool = init_color == swatch_color;
1354 let swatch_label: String = format!(
1355 "#{:02X}{:02X}{:02X}",
1356 swatch_color.get_r(),
1357 swatch_color.get_g(),
1358 swatch_color.get_b()
1359 );
1360 let on_pick = move |_: &UiEvent| {
1361 let _: bool = sig.set_if_changed(swatch_color);
1362 };
1363 view! {
1364 view {
1365 style: {
1366 width: Length::Px(26.0)
1367 height: Length::Px(26.0)
1368 radius: g.get_radius_sm()
1369 overflow: Overflow::Hidden
1370 background: swatch_color
1371 border: (border_w, if active { p.get_foreground() } else { p.get_border() })
1372 cursor: CursorIcon::Pointer
1373 }
1374 role: A11yRole::Button
1375 a11y_label: swatch_label
1376 on_click: on_pick
1377 }
1378 }
1379 })
1380 .collect();
1381 let hex_text = move || -> String {
1382 let c: Color = sig.get();
1383 format!("#{:02X}{:02X}{:02X}", c.get_r(), c.get_g(), c.get_b())
1384 };
1385 let root: NodeId = view! {
1386 column {
1387 style: {
1388 width: Length::Percent(100.0)
1389 gap: SPACE_SM
1390 }
1391 row {
1392 style: {
1393 align: AlignItems::Center
1394 gap: SPACE_SM
1395 }
1396 view {
1397 node_ref: preview
1398 style: {
1399 width: Length::Px(24.0)
1400 height: Length::Px(24.0)
1401 radius: g.get_radius_sm()
1402 overflow: Overflow::Hidden
1403 background: init_color
1404 border: (border_w, p.get_border())
1405 }
1406 }
1407 text {
1408 style: {
1409 font_family: FontFamily::Monospace
1410 font_size: 13.0
1411 font_weight: FontWeight::Medium
1412 color: bg_surface.get_fg()
1413 }
1414 { hex_text }
1415 }
1416 }
1417 row {
1418 node_ref: swatch_row
1419 style: {
1420 flex_wrap: FlexWrap::Wrap
1421 width: Length::Percent(100.0)
1422 gap: SPACE_XS
1423 }
1424 }
1425 }
1426 };
1427 if !swatch_nodes.is_empty() {
1428 ctx.append_many(swatch_row, swatch_nodes.as_slice());
1429 }
1430 let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(swatch_nodes.len() + 1);
1431 owned_nodes.push(preview);
1432 owned_nodes.extend(swatch_nodes.iter().copied());
1433 let handle: SceneHandle = ctx.get_scene().clone();
1434 let prev_state: Cell<(Color, ThemeKey)> = Cell::new((init_color, init_tok.key()));
1435 let swatch_dirty: u16 = DIRTY_PAINT;
1436 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1437 Effect::new(move || {
1438 let next_color: Color = sig.get();
1439 let tok: ThemeTokens = use_live_tokens(base_tokens);
1440 let (old_color, old_key): (Color, ThemeKey) =
1441 prev_state.replace((next_color, tok.key()));
1442 if old_color == next_color && old_key == tok.key() {
1443 return;
1444 }
1445 let live_p: ThemePalette = tok.get_palette();
1446 let live_bw: f32 = tok.get_geometry().get_border_width();
1447 let active_border: Border = Border::new(live_bw, live_p.get_foreground());
1448 let idle_border: Border = Border::new(live_bw, live_p.get_border());
1449 handle.with_write(
1450 |tree: &mut SceneTree| {
1451 if let Some(n) = tree.get_node_mut(preview) {
1452 let _: &mut PaintStyle = n
1453 .get_mut_style()
1454 .get_mut_paint()
1455 .set_background(Some(next_color))
1456 .set_border(idle_border);
1457 tree.mark_dirty(preview, DIRTY_PAINT);
1458 }
1459 for (idx, col) in swatches.iter().copied().enumerate() {
1460 if let Some(&sid) = swatch_nodes.get(idx)
1461 && let Some(n) = tree.get_node_mut(sid)
1462 {
1463 let next_border: Border = if col == next_color {
1464 active_border
1465 } else {
1466 idle_border
1467 };
1468 let _: &mut PaintStyle = n
1469 .get_mut_style()
1470 .get_mut_paint()
1471 .set_background(Some(col))
1472 .set_border(next_border);
1473 tree.mark_dirty(sid, swatch_dirty);
1474 }
1475 }
1476 },
1477 (),
1478 );
1479 })
1480 });
1481 ctx.get_scene().with_write(
1482 |tree: &mut SceneTree| {
1483 mark_theme_owned(tree, owned_nodes.as_slice());
1484 tree.attach_scope(root, scope);
1485 },
1486 (),
1487 );
1488 root
1489 }
1490}
1491
1492#[component]
1494impl EuvTimePicker {
1496 fn render(&self) -> NodeId {
1506 let mut ctx: Context = current_context();
1507 let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
1508 let p: ThemePalette = tokens.get_palette();
1509 let g: ThemeGeometry = tokens.get_geometry();
1510 let card_surface: SurfaceColors = p.surface(SurfaceRole::Card);
1511 let sig: Signal<(u8, u8)> = self.get_value();
1512 let time_readout_text = move || -> String {
1513 let (hh, mm): (u8, u8) = sig.get();
1514 format!("{:02}:{:02}", hh % 24, mm % 60)
1515 };
1516 let on_hour_dec = move |_: &UiEvent| {
1517 let _: bool = sig.update(|v: &mut (u8, u8)| {
1518 let h: u8 = v.0 % 24;
1519 v.0 = if h == 0 { 23 } else { h - 1 };
1520 });
1521 };
1522 let on_hour_inc = move |_: &UiEvent| {
1523 let _: bool = sig.update(|v: &mut (u8, u8)| {
1524 v.0 = ((v.0 % 24) + 1) % 24;
1525 });
1526 };
1527 let on_min_dec = move |_: &UiEvent| {
1528 let _: bool = sig.update(|v: &mut (u8, u8)| {
1529 v.1 = ((v.1 % 60) + 55) % 60;
1530 });
1531 };
1532 let on_min_inc = move |_: &UiEvent| {
1533 let _: bool = sig.update(|v: &mut (u8, u8)| {
1534 v.1 = ((v.1 % 60) + 5) % 60;
1535 });
1536 };
1537 let preset_nodes: Vec<NodeId> = TIME_PRESETS
1538 .iter()
1539 .copied()
1540 .map(|(ph, pm): (u8, u8)| {
1541 let on_preset = move |_: &UiEvent| {
1542 let _: bool = sig.set_if_changed((ph, pm));
1543 };
1544 EuvButton::new(format!("{ph:02}:{pm:02}"), tokens)
1545 .secondary()
1546 .sm()
1547 .on_click(on_preset)
1548 .mount()
1549 })
1550 .collect();
1551 let mut preset_row: NodeId = NodeId::default();
1552 let root: NodeId = view! {
1553 column {
1554 style: {
1555 width: Length::Percent(100.0)
1556 gap: SPACE_SM
1557 }
1558 row {
1559 style: {
1560 flex_wrap: FlexWrap::Wrap
1561 align: AlignItems::Center
1562 gap: SPACE_XS
1563 }
1564 text {
1565 style: {
1566 font_size: 11.0
1567 color: p.get_muted_foreground()
1568 }
1569 { TIME_HOUR_LABEL }
1570 }
1571 EuvButton {
1572 label: STEP_MINUS.to_string()
1573 tokens: tokens
1574 outline()
1575 sm()
1576 on_click: on_hour_dec
1577 }
1578 EuvButton {
1579 label: STEP_PLUS.to_string()
1580 tokens: tokens
1581 outline()
1582 sm()
1583 on_click: on_hour_inc
1584 }
1585 row {
1586 style: {
1587 height: Length::Px(g.get_control_sm())
1588 min_width: Length::Px(76.0)
1589 flex_shrink: 0.0
1590 padding: Edges::symmetric(0.0, SPACE_MD)
1591 justify: JustifyContent::Center
1592 align: AlignItems::Center
1593 background: card_surface.get_bg()
1594 border: (g.get_border_width(), card_surface.get_border())
1595 radius: g.get_radius_sm()
1596 overflow: Overflow::Hidden
1597 }
1598 text {
1599 style: {
1600 font_family: FontFamily::Monospace
1601 font_size: 14.0
1602 font_weight: FontWeight::SemiBold
1603 color: card_surface.get_fg()
1604 text_align: TextAlign::Center
1605 text_overflow: TextOverflow::Clip
1606 }
1607 { time_readout_text }
1608 }
1609 }
1610 EuvButton {
1611 label: STEP_MINUS.to_string()
1612 tokens: tokens
1613 outline()
1614 sm()
1615 on_click: on_min_dec
1616 }
1617 EuvButton {
1618 label: STEP_PLUS.to_string()
1619 tokens: tokens
1620 outline()
1621 sm()
1622 on_click: on_min_inc
1623 }
1624 text {
1625 style: {
1626 font_size: 11.0
1627 color: p.get_muted_foreground()
1628 }
1629 { TIME_MIN_LABEL }
1630 }
1631 }
1632 row {
1633 node_ref: preset_row
1634 style: {
1635 flex_wrap: FlexWrap::Wrap
1636 width: Length::Percent(100.0)
1637 gap: SPACE_XS
1638 }
1639 }
1640 }
1641 };
1642 if !preset_nodes.is_empty() {
1643 ctx.append_many(preset_row, preset_nodes.as_slice());
1644 }
1645 root
1646 }
1647}
1648
1649impl EuvTagInput {
1651 #[must_use]
1662 pub fn placeholder<S>(mut self, placeholder: S) -> Self
1663 where
1664 S: Into<String>,
1665 {
1666 self.set_placeholder(placeholder.into());
1667 self
1668 }
1669}
1670
1671#[component]
1673impl EuvTagInput {
1675 fn render(&self) -> NodeId {
1689 let base_tokens: ThemeTokens = self.get_tokens();
1690 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1691 let tags_sig: Signal<Vec<String>> = self.get_tags();
1692 let Self { placeholder, .. } = self;
1693 let resolved_ph: String = if placeholder.is_empty() {
1694 TAG_DEFAULT_PLACEHOLDER.to_string()
1695 } else {
1696 placeholder.clone()
1697 };
1698 let draft: Signal<String> = Signal::new(String::new());
1699 let build_chips = move || -> Vec<NodeId> {
1700 let live_tok: ThemeTokens = use_live_tokens(base_tokens);
1701 let live_p: ThemePalette = live_tok.get_palette();
1702 let live_g: ThemeGeometry = live_tok.get_geometry();
1703 let chip_surface: SurfaceColors = live_p.surface(SurfaceRole::Secondary);
1704 tags_sig
1705 .get()
1706 .into_iter()
1707 .enumerate()
1708 .map(|(idx, tag): (usize, String)| {
1709 let on_remove = move |_: &UiEvent| {
1710 let _: bool = tags_sig.update(|list: &mut Vec<String>| {
1711 if idx < list.len() {
1712 let _: String = list.remove(idx);
1713 }
1714 });
1715 };
1716 view! {
1717 row {
1718 style: {
1719 justify: JustifyContent::Center
1720 align: AlignItems::Center
1721 padding: Edges::symmetric(SPACE_XS, SPACE_SM)
1722 gap: 6.0
1723 background: chip_surface.get_bg()
1724 border: (live_g.get_border_width(), chip_surface.get_border())
1725 radius: RADIUS_PILL
1726 overflow: Overflow::Hidden
1727 cursor: CursorIcon::Pointer
1728 }
1729 on_click: on_remove
1730 text {
1731 style: {
1732 font_size: 12.0
1733 font_weight: FontWeight::Medium
1734 color: chip_surface.get_fg()
1735 text_align: TextAlign::Center
1736 }
1737 { format!("{tag} x") }
1738 }
1739 }
1740 }
1741 })
1742 .collect()
1743 };
1744 let on_add_tag = move |_: &UiEvent| {
1745 let raw: String = draft.get_untracked().trim().to_string();
1746 if !raw.is_empty() {
1747 let _: bool = tags_sig.update(|list: &mut Vec<String>| {
1748 if !list.iter().any(|existing: &String| existing == &raw) {
1749 list.push(raw.clone());
1750 }
1751 });
1752 let _: bool = draft.set_if_changed(String::new());
1753 }
1754 };
1755 view! {
1756 column {
1757 style: {
1758 width: Length::Percent(100.0)
1759 gap: SPACE_SM
1760 }
1761 row {
1762 style: {
1763 flex_wrap: FlexWrap::Wrap
1764 width: Length::Percent(100.0)
1765 gap: SPACE_XS
1766 }
1767 bind_children: build_chips
1768 }
1769 row {
1770 style: {
1771 width: Length::Percent(100.0)
1772 align: AlignItems::Center
1773 gap: SPACE_XS
1774 }
1775 column {
1776 style: {
1777 flex_grow: 1.0
1778 min_width: Length::Px(80.0)
1779 }
1780 EuvInput {
1781 value: draft
1782 placeholder: resolved_ph
1783 tokens: init_tok
1784 }
1785 }
1786 EuvButton {
1787 label: TAG_ADD_LABEL.to_string()
1788 tokens: init_tok
1789 outline()
1790 on_click: on_add_tag
1791 }
1792 }
1793 }
1794 }
1795 }
1796}