1use super::*;
2
3impl EuvAlertDialog {
5 #[must_use]
16 pub fn description<TextValue>(mut self, description: TextValue) -> Self
17 where
18 TextValue: Into<String>,
19 {
20 self.set_description(description.into());
21 self
22 }
23
24 #[must_use]
36 pub fn labels<S1, S2>(mut self, cancel_label: S1, confirm_label: S2) -> Self
37 where
38 S1: Into<String>,
39 S2: Into<String>,
40 {
41 self.set_cancel_label(cancel_label.into());
42 self.set_confirm_label(confirm_label.into());
43 self
44 }
45}
46
47#[component]
49impl EuvAlertDialog {
51 fn render(&self) -> NodeId {
61 let mut ctx: Context = current_context();
62 let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
63 let theme_palette: ThemePalette = tokens.get_palette();
64 let geometry: ThemeGeometry = tokens.get_geometry();
65 let open: Signal<bool> = self.get_open();
66 let confirmed: Signal<bool> = self.get_confirmed();
67 let Self {
68 title,
69 description,
70 cancel_label,
71 confirm_label,
72 ..
73 } = self;
74 let title_owned: String = title.clone();
75 let resolved_cancel: String = if cancel_label.is_empty() {
76 ALERT_DEFAULT_CANCEL_LABEL.to_string()
77 } else {
78 cancel_label.clone()
79 };
80 let resolved_confirm: String = if confirm_label.is_empty() {
81 ALERT_DEFAULT_CONFIRM_LABEL.to_string()
82 } else {
83 confirm_label.clone()
84 };
85 let init_open: bool = open.get_untracked();
86 let mut card: NodeId = NodeId::default();
87 let on_cancel = move |_: &UiEvent| {
88 let _: bool = confirmed.set_if_changed(false);
89 let _: bool = open.set_if_changed(false);
90 };
91 let on_confirm = move |_: &UiEvent| {
92 let _: bool = confirmed.set_if_changed(true);
93 let _: bool = open.set_if_changed(false);
94 };
95 let portal_style: Style = style! {
96 if init_open { Display::Flex } else { Display::None }
97 Position::Fixed
98 Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
99 Width(Length::Percent(100.0))
100 Height(Length::Percent(100.0))
101 JustifyContent::Center
102 AlignItems::Center
103 Background(theme_palette.get_overlay())
104 StopScrollPropagation(true)
105 ZIndex(Z_INDEX_MODAL)
106 };
107 let column_tenth_style: Style = style! {
108 Width(Length::Percent(92.0))
109 MaxWidth(Length::Px(440.0))
110 Padding(Edges::all(SPACE_XL))
111 Gap(SPACE_MD)
112 Background(theme_palette.get_card())
113 Border::new(geometry.get_border_width(), theme_palette.get_border())
114 Radius(geometry.get_radius_lg())
115 Overflow::Hidden
116 geometry.get_shadow_lg()
117 };
118 let text_fifteenth_style: Style = style! {
119 Width(Length::Percent(100.0))
120 FontSize(geometry.get_font_heading())
121 FontWeight::SemiBold
122 TextColor(theme_palette.get_card_foreground())
123 };
124 let text_sixteenth_style: Style = style! {
125 Width(Length::Percent(100.0))
126 FontSize(13.0)
127 TextColor(theme_palette.get_muted_foreground())
128 };
129 let row_eleventh_style: Style = style! {
130 FlexWrap::Wrap
131 Width(Length::Percent(100.0))
132 JustifyContent::End
133 Gap(SPACE_SM)
134 };
135 let scrim: NodeId = view! {
136 portal {
137 style: portal_style
138 column {
139 node_ref: card
140 style: column_tenth_style
141 role: A11yRole::Dialog
142 a11y_label: title_owned.clone()
143 text {
144 style: text_fifteenth_style
145 { title_owned }
146 }
147 text {
148 style: text_sixteenth_style
149 { description.as_str() }
150 }
151 row {
152 style: row_eleventh_style
153 EuvButton {
154 label: resolved_cancel
155 tokens: tokens
156 outline()
157 on_click: on_cancel
158 }
159 EuvButton {
160 label: resolved_confirm
161 tokens: tokens
162 destructive()
163 on_click: on_confirm
164 }
165 }
166 }
167 }
168 };
169 ctx.on_click(scrim, move |ui_event: &UiEvent| {
170 if ui_event.get_target() == scrim {
171 let _: bool = confirmed.set_if_changed(false);
172 let _: bool = open.set_if_changed(false);
173 }
174 });
175 let handle: SceneHandle = ctx.get_scene().clone();
176 let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(init_open));
177 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
178 let _: Effect =
179 EuvOverlayStack::bind_signal(open, ALERT_DIALOG_OVERLAY_NAME, Z_INDEX_MODAL);
180 Effect::new(move || {
181 let is_open: bool = open.get();
182 let was_open: bool = prev_open.replace(is_open);
183 if is_open == was_open {
184 return;
185 }
186 if is_open {
187 handle.with_write(
188 |tree: &mut SceneTree| {
189 let (cur_scrim_op, was_hidden): (f32, bool) = tree
190 .get_node(scrim)
191 .map(|scene_node: &SceneNode| {
192 let hidden: bool =
193 scene_node.style_ref().get_layout().get_display()
194 == Display::None;
195 (scene_node.style_ref().get_paint().get_opacity(), hidden)
196 })
197 .unwrap_or((0.0, true));
198 let start_scrim_op: f32 = if was_hidden { 0.0 } else { cur_scrim_op };
199 tree.cancel_subtree_transitions(scrim);
200 tree.cancel_subtree_transitions(card);
201 if let Some(item_count) = tree.get_node_mut(scrim) {
202 let computed_style: &mut Style = item_count.get_mut_style();
203 computed_style.get_mut_layout().set_display(Display::Flex);
204 computed_style
205 .get_mut_paint()
206 .set_pointer_events(PointerEvents::Auto)
207 .set_transform(Transform2D::default());
208 }
209 let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
210 tree.mark_dirty(scrim, dirty_l | DIRTY_PAINT);
211 tree.start_transition(
212 NodeTransition::fade(
213 scrim,
214 start_scrim_op,
215 1.0,
216 motion_duration(MOTION_STANDARD_SECS),
217 false,
218 )
219 .with_easing(MOTION_EASE_ENTER),
220 );
221 tree.start_transition(
222 NodeTransition::modal_enter(card)
223 .with_duration(motion_duration(MOTION_STANDARD_SECS))
224 .with_easing(MOTION_EASE_ENTER),
225 );
226 },
227 (),
228 );
229 } else {
230 handle.with_write(
231 |tree: &mut SceneTree| {
232 let cur_scrim_op: f32 = tree
233 .get_node(scrim)
234 .map(|target_node: &SceneNode| {
235 target_node.style_ref().get_paint().get_opacity()
236 })
237 .unwrap_or(1.0);
238 let (cur_card_op, cur_card_ty, cur_card_scale): (f32, f32, f32) = tree
239 .get_node(card)
240 .map(|node_entry: &SceneNode| {
241 let paint: PaintStyle = node_entry.style_ref().get_paint();
242 let transform_val: Transform2D = paint.get_transform();
243 (
244 paint.get_opacity(),
245 transform_val.get_translate_y(),
246 transform_val.get_scale_x().max(0.05),
247 )
248 })
249 .unwrap_or((1.0, 0.0, 1.0));
250 tree.cancel_subtree_transitions(scrim);
251 tree.cancel_subtree_transitions(card);
252 if let Some(normal_vec) = tree.get_node_mut(scrim) {
253 normal_vec
254 .get_mut_style()
255 .get_mut_paint()
256 .set_pointer_events(PointerEvents::None);
257 }
258 tree.mark_dirty(scrim, DIRTY_PAINT);
259 tree.start_transition(
260 NodeTransition::fade(
261 scrim,
262 cur_scrim_op,
263 0.0,
264 motion_duration(MOTION_STANDARD_SECS),
265 true,
266 )
267 .with_easing(MOTION_EASE_EXIT),
268 );
269 tree.start_transition(
270 NodeTransition::modal_exit(card)
271 .with_duration(motion_duration(MOTION_STANDARD_SECS))
272 .with_easing(MOTION_EASE_EXIT)
273 .with_opacity(cur_card_op, 0.0)
274 .with_offset(
275 Point::new(0.0, cur_card_ty),
276 Point::new(0.0, 10.0),
277 )
278 .with_scale(cur_card_scale, 0.96),
279 );
280 },
281 (),
282 );
283 }
284 })
285 });
286 ctx.get_scene().with_write(
287 |tree: &mut SceneTree| {
288 tree.attach_scope(scrim, scope);
289 },
290 (),
291 );
292 scrim
293 }
294}
295
296#[component]
298impl EuvCollapsible {
300 fn render(&self) -> NodeId {
310 let ctx: Context = current_context();
311 let init_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
312 let theme_palette: ThemePalette = init_tok.get_palette();
313 let geometry: ThemeGeometry = init_tok.get_geometry();
314 let open: Signal<bool> = self.get_open();
315 let content: NodeId = self.get_content();
316 let Self { title, .. } = self;
317 let init_open: bool = open.get_untracked();
318 let init_disp: Display = if init_open {
319 Display::Flex
320 } else {
321 Display::None
322 };
323 let toggle_click = move |_: &UiEvent| {
324 let _: bool = open.set(!open.get_untracked());
325 };
326 let toggle_label = move || -> String {
327 if open.get() {
328 COLLAPSIBLE_HIDE_LABEL.to_string()
329 } else {
330 COLLAPSIBLE_SHOW_LABEL.to_string()
331 }
332 };
333 let div_h: f32 = geometry.get_border_width().max(1.0);
334 let mut divider: NodeId = NodeId::default();
335 let mut body: NodeId = NodeId::default();
336 let column_eighth_style: Style = style! {
337 Width(Length::Percent(100.0))
338 Background(theme_palette.get_card())
339 Border::new(geometry.get_border_width(), theme_palette.get_border())
340 Radius(geometry.get_radius_md())
341 Overflow::Hidden
342 };
343 let row_tenth_style: Style = style! {
344 Width(Length::Percent(100.0))
345 MinHeight(Length::Px(geometry.get_control_md()))
346 Padding(Edges::symmetric(SPACE_SM, SPACE_MD))
347 Radius(concentric_radius(
348 geometry.get_radius_md(),
349 geometry.get_border_width(),
350 ))
351 JustifyContent::SpaceBetween
352 AlignItems::Center
353 Gap(SPACE_SM)
354 CursorIcon::Pointer
355 };
356 let text_thirteenth_style: Style = style! {
357 FlexGrow(1.0)
358 FlexShrink(1.0)
359 MinWidth(Length::Px(0.0))
360 FontSize(13.0)
361 FontWeight::SemiBold
362 TextColor(theme_palette.get_card_foreground())
363 };
364 let text_fourteenth_style: Style = style! {
365 FlexShrink(0.0)
366 FontSize(12.0)
367 FontWeight::Medium
368 TextColor(theme_palette.get_muted_foreground())
369 };
370 let view_secondary_style: Style = style! {
371 init_disp
372 Width(Length::Percent(100.0))
373 Height(Length::Px(div_h))
374 Background(theme_palette.get_border())
375 };
376 let column_ninth_style: Style = style! {
377 init_disp
378 Width(Length::Percent(100.0))
379 Padding(Edges::all(SPACE_MD))
380 Overflow::Hidden
381 };
382 let root: NodeId = view! {
383 column {
384 style: column_eighth_style
385 row {
386 style: row_tenth_style
387 on_click: toggle_click
388 text {
389 style: text_thirteenth_style
390 { title.as_str() }
391 }
392 text {
393 style: text_fourteenth_style
394 { toggle_label }
395 }
396 }
397 view {
398 node_ref: divider
399 style: view_secondary_style
400 }
401 column {
402 node_ref: body
403 style: column_ninth_style
404 { content }
405 }
406 }
407 };
408 let handle: SceneHandle = ctx.get_scene().clone();
409 let prev_open: Cell<bool> = Cell::new(init_open);
410 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
411 Effect::new(move || {
412 let is_open: bool = open.get();
413 if prev_open.replace(is_open) == is_open {
414 return;
415 }
416 let next_disp: Display = if is_open {
417 Display::Flex
418 } else {
419 Display::None
420 };
421 handle.with_write(
422 |tree: &mut SceneTree| {
423 let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
424 if let Some(item_count) = tree.get_node_mut(divider) {
425 item_count
426 .get_mut_style()
427 .get_mut_layout()
428 .set_display(next_disp);
429 tree.mark_dirty(divider, dirty_l | DIRTY_PAINT);
430 }
431 if let Some(node_entry) = tree.get_node_mut(body) {
432 node_entry
433 .get_mut_style()
434 .get_mut_layout()
435 .set_display(next_disp);
436 tree.mark_dirty(body, dirty_l | DIRTY_PAINT);
437 }
438 },
439 (),
440 );
441 })
442 });
443 ctx.get_scene().with_write(
444 |tree: &mut SceneTree| {
445 tree.attach_scope(root, scope);
446 },
447 (),
448 );
449 root
450 }
451}
452
453#[component]
455impl EuvToggleGroup {
457 fn render(&self) -> NodeId {
470 let mut ctx: Context = current_context();
471 let base_tokens: ThemeTokens = self.get_tokens();
472 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
473 let theme_palette: ThemePalette = init_tok.get_palette();
474 let geometry: ThemeGeometry = init_tok.get_geometry();
475 let selected: Signal<usize> = self.get_selected();
476 let Self { options, .. } = self;
477 let init_sel: usize = selected.get_untracked();
478 let track_radius: f32 = geometry.get_radius_lg();
479 let item_radius: f32 = concentric_radius(track_radius, CONTROL_INSET);
480 let mut item_nodes: Vec<NodeId> = Vec::with_capacity(options.len());
481 let mut bound_items: Vec<(NodeId, NodeId, String)> = Vec::with_capacity(options.len());
482 let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(options.len() * 2);
483 for (idx, opt) in options.iter().enumerate() {
484 let on: bool = init_sel == idx;
485 let (bg, fg, border, shadow): (Color, Color, Border, Option<Shadow>) =
486 Self::item_visuals(init_tok, on);
487 let on_pick = move |_: &UiEvent| {
488 let _: bool = selected.set_if_changed(idx);
489 };
490 let mut lbl_id: NodeId = NodeId::default();
491 let mut item_style: Style = Style::default();
492 item_style
493 .get_mut_layout()
494 .set_flex_direction(FlexDirection::Row)
495 .set_height(Length::Px(geometry.get_control_sm()))
496 .set_justify_content(JustifyContent::Center)
497 .set_align_items(AlignItems::Center)
498 .set_padding(Edges::symmetric(0.0, SPACE_MD))
499 .set_overflow(Overflow::Hidden);
500 item_style
501 .get_mut_paint()
502 .set_radius(CornerRadius::all(item_radius))
503 .set_border(border)
504 .set_background(Some(bg))
505 .set_shadow(shadow)
506 .set_cursor(CursorIcon::Pointer);
507 let text_twelfth_style: Style = style! {
508 FontSize(13.0)
509 if on {
510 FontWeight::SemiBold
511 } else {
512 FontWeight::Medium
513 }
514 TextColor(fg)
515 TextAlign::Center
516 TextOverflow::Ellipsis
517 };
518 let item_id: NodeId = view! {
519 row {
520 style: item_style
521 role: A11yRole::Button
522 a11y_label: opt.clone()
523 on_click: on_pick
524 text {
525 node_ref: lbl_id
526 style: text_twelfth_style
527 { opt.as_str() }
528 }
529 }
530 };
531 item_nodes.push(item_id);
532 owned_nodes.push(item_id);
533 owned_nodes.push(lbl_id);
534 bound_items.push((item_id, lbl_id, opt.clone()));
535 }
536 let row_ninth_style: Style = style! {
537 FlexWrap::Wrap
538 Width(Length::Percent(100.0))
539 Padding(Edges::all(CONTROL_INSET))
540 Gap(CONTROL_INSET)
541 Background(theme_palette.get_muted())
542 Border::new(geometry.get_border_width(), theme_palette.get_border())
543 Radius(track_radius)
544 Overflow::Hidden
545 };
546 let root: NodeId = view! {
547 row {
548 style: row_ninth_style
549 role: A11yRole::Group
550 }
551 };
552 if !item_nodes.is_empty() {
553 ctx.append_many(root, item_nodes.as_slice());
554 }
555 let handle: SceneHandle = ctx.get_scene().clone();
556 let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_sel, init_tok.key()));
557 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
558 Effect::new(move || {
559 let next_sel: usize = selected.get();
560 let tok: ThemeTokens = use_live_tokens(base_tokens);
561 let (old_sel, old_key): (usize, ThemeKey) =
562 prev_state.replace((next_sel, tok.key()));
563 if old_sel == next_sel && old_key == tok.key() {
564 return;
565 }
566 handle.with_write(
567 |tree: &mut SceneTree| {
568 for (idx, (item_id, lbl_id, label)) in bound_items.iter().enumerate() {
569 let is_on: bool = idx == next_sel;
570 let (bg, fg, border, shadow): (Color, Color, Border, Option<Shadow>) =
571 Self::item_visuals(tok, is_on);
572 if let Some(item_count) = tree.get_node_mut(*item_id) {
573 item_count
574 .get_mut_style()
575 .get_mut_paint()
576 .set_background(Some(bg))
577 .set_border(border)
578 .set_shadow(shadow);
579 let mut a11y: A11yProps =
580 A11yProps::new(A11yRole::Button, label.clone());
581 a11y.set_checked(Some(is_on));
582 item_count.set_a11y(Some(a11y));
583 tree.mark_dirty(*item_id, DIRTY_PAINT);
584 }
585 if let Some(node_entry) = tree.get_node_mut(*lbl_id) {
586 node_entry
587 .get_mut_style()
588 .get_mut_text()
589 .set_weight(if is_on {
590 FontWeight::SemiBold
591 } else {
592 FontWeight::Medium
593 })
594 .set_color(fg);
595 let mut dirty_lbl: u16 = DIRTY_LAYOUT | DIRTY_TEXT;
596 dirty_lbl |= DIRTY_PAINT;
597 tree.mark_dirty(*lbl_id, dirty_lbl);
598 }
599 }
600 },
601 (),
602 );
603 })
604 });
605 ctx.get_scene().with_write(
606 |tree: &mut SceneTree| {
607 for (idx, (item_id, _, label)) in item_nodes
608 .iter()
609 .copied()
610 .zip(options.iter())
611 .enumerate()
612 .map(
613 |(item_index, (id, text_value)): (usize, (NodeId, &String))| {
614 (item_index, (id, (), text_value))
615 },
616 )
617 {
618 if let Some(normal_vec) = tree.get_node_mut(item_id) {
619 let mut a11y: A11yProps = A11yProps::new(A11yRole::Button, label.clone());
620 a11y.set_checked(Some(idx == init_sel));
621 normal_vec.set_a11y(Some(a11y));
622 }
623 }
624 mark_theme_owned(tree, owned_nodes.as_slice());
625 tree.attach_scope(root, scope);
626 },
627 (),
628 );
629 root
630 }
631}
632
633impl EuvToggleGroup {
635 #[must_use]
646 pub fn item_visuals(
647 tokens: ThemeTokens,
648 pressed: bool,
649 ) -> (Color, Color, Border, Option<Shadow>) {
650 let theme_palette: ThemePalette = tokens.get_palette();
651 let geometry: ThemeGeometry = tokens.get_geometry();
652 let border_width: f32 = geometry.get_border_width();
653 if pressed {
654 let surf: SurfaceColors = theme_palette.surface(SurfaceRole::Primary);
655 (
656 surf.get_bg(),
657 surf.get_fg(),
658 Border::new(border_width, surf.get_border()),
659 Some(geometry.get_shadow_xs()),
660 )
661 } else {
662 let muted: SurfaceColors = theme_palette.surface(SurfaceRole::Muted);
663 (
664 COLOR_TRANSPARENT,
665 muted.get_fg(),
666 Border::new(border_width, COLOR_TRANSPARENT),
667 None,
668 )
669 }
670 }
671}
672
673#[component]
675impl EuvInputOtp {
677 fn render(&self) -> NodeId {
687 let mut ctx: Context = current_context();
688 let init_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
689 let theme_palette: ThemePalette = init_tok.get_palette();
690 let geometry: ThemeGeometry = init_tok.get_geometry();
691 let value: Signal<String> = self.get_value();
692 let slots: usize = self.get_length().clamp(4, 8);
693 let slot_size: f32 = geometry.get_control_md();
694 let slot_nodes: Vec<NodeId> = (0..slots)
695 .map(|slot_idx: usize| {
696 let on_slot_click = move |_: &UiEvent| {
697 let _: bool = {
698 if let Some(mut updated_value) = value.try_get_untracked() {
699 {
700 let text_value: &mut String = &mut updated_value;
701 let mut chars: Vec<char> = text_value.chars().collect();
702 while chars.len() <= slot_idx {
703 chars.push('0');
704 }
705 let next_digit: u32 = chars[slot_idx]
706 .to_digit(10)
707 .map(|delta_val: u32| (delta_val + 1) % 10)
708 .unwrap_or(1);
709 chars[slot_idx] = char::from_digit(next_digit, 10).unwrap_or('0');
710 chars.truncate(slots);
711 *text_value = chars.into_iter().collect();
712 }
713 value.set(updated_value)
714 } else {
715 false
716 }
717 };
718 };
719 let slot_text = move || -> String {
720 let cur: String = value.get();
721 cur.chars()
722 .nth(slot_idx)
723 .map(|char_value: char| char_value.to_string())
724 .unwrap_or_else(|| OTP_EMPTY_SLOT.to_string())
725 };
726 let mut slot_style: Style = Style::default();
727 slot_style
728 .get_mut_layout()
729 .set_flex_direction(FlexDirection::Row)
730 .set_width(Length::Px(slot_size))
731 .set_height(Length::Px(slot_size))
732 .set_justify_content(JustifyContent::Center)
733 .set_align_items(AlignItems::Center)
734 .set_overflow(Overflow::Hidden);
735 slot_style
736 .get_mut_paint()
737 .set_background(Some(theme_palette.get_card()))
738 .set_border(Border::new(
739 geometry.get_border_width(),
740 theme_palette.get_border(),
741 ))
742 .set_radius(CornerRadius::all(geometry.get_radius_md()))
743 .set_cursor(CursorIcon::Pointer);
744 let text_eleventh_style: Style = style! {
745 FontFamily::Monospace
746 FontSize(15.0)
747 FontWeight::SemiBold
748 TextColor(theme_palette.get_card_foreground())
749 TextAlign::Center
750 };
751 view! {
752 row {
753 style: slot_style
754 on_click: on_slot_click
755 text {
756 style: text_eleventh_style
757 { slot_text }
758 }
759 }
760 }
761 })
762 .collect();
763 let row_eighth_style: Style = style! {
764 FlexWrap::Wrap
765 AlignItems::Center
766 Gap(SPACE_XS)
767 };
768 let root: NodeId = view! {
769 row {
770 style: row_eighth_style
771 }
772 };
773 if !slot_nodes.is_empty() {
774 ctx.append_many(root, slot_nodes.as_slice());
775 }
776 root
777 }
778}
779
780impl EuvCommand {
782 #[must_use]
793 pub fn query(mut self, query: Signal<String>) -> Self {
794 self.set_query(Some(query));
795 self
796 }
797
798 #[must_use]
809 pub fn placeholder<TextValue>(mut self, placeholder: TextValue) -> Self
810 where
811 TextValue: Into<String>,
812 {
813 self.set_placeholder(placeholder.into());
814 self
815 }
816
817 #[must_use]
828 pub fn frameless(mut self, frameless: bool) -> Self {
829 self.set_frameless(frameless);
830 self
831 }
832}
833
834#[component]
836impl EuvCommand {
838 fn render(&self) -> NodeId {
848 let base_tokens: ThemeTokens = self.get_tokens();
849 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
850 let theme_palette: ThemePalette = init_tok.get_palette();
851 let geometry: ThemeGeometry = init_tok.get_geometry();
852 let selected: Signal<Option<usize>> = self.get_selected();
853 let is_frameless: bool = self.get_frameless();
854 let Self {
855 query: query_opt,
856 placeholder,
857 items,
858 ..
859 } = self;
860 let query: Signal<String> = query_opt.unwrap_or_else(|| Signal::new(String::new()));
861 let resolved_ph: String = if placeholder.is_empty() {
862 COMMAND_DEFAULT_PLACEHOLDER.to_string()
863 } else {
864 placeholder.clone()
865 };
866 let items_shared: Rc<[String]> = Rc::from(items.as_slice());
867 let build_cmd_items = move || -> Vec<NodeId> {
868 let live_tok: ThemeTokens = use_live_tokens(base_tokens);
869 let live_p: ThemePalette = live_tok.get_palette();
870 let live_g: ThemeGeometry = live_tok.get_geometry();
871 let accent: SurfaceColors = live_p.surface(SurfaceRole::Accent);
872 let card: SurfaceColors = live_p.surface(SurfaceRole::Card);
873 let item_radius: f32 = concentric_radius(live_g.get_radius_lg(), CONTROL_INSET);
874 let raw_q: String = query.get();
875 let q_ascii: bool = raw_q.is_ascii();
876 let needle_unicode: String = if q_ascii || raw_q.is_empty() {
877 String::new()
878 } else {
879 raw_q.to_lowercase()
880 };
881 let cur_sel: Option<usize> = selected.get();
882 let mut nodes: Vec<NodeId> = Vec::with_capacity(items_shared.len().max(1));
883 for (idx, item) in items_shared.iter().enumerate() {
884 if !raw_q.is_empty() {
885 let matched: bool = if q_ascii {
886 contains_ascii_ignore_case(item.as_str(), raw_q.as_str())
887 } else {
888 item.to_lowercase().contains(&needle_unicode)
889 };
890 if !matched {
891 continue;
892 }
893 }
894 let is_sel: bool = cur_sel == Some(idx);
895 let row_bg: Color = if is_sel {
896 accent.get_bg()
897 } else {
898 COLOR_TRANSPARENT
899 };
900 let row_fg: Color = if is_sel {
901 accent.get_fg()
902 } else {
903 card.get_fg()
904 };
905 let on_pick = move |_: &UiEvent| {
906 let _: bool = selected.set_if_changed(Some(idx));
907 };
908 let row_seventh_style: Style = style! {
909 Width(Length::Percent(100.0))
910 Height(Length::Px(live_g.get_control_sm()))
911 FlexShrink(0.0)
912 AlignItems::Center
913 Padding(Edges::symmetric(0.0, SPACE_MD))
914 Radius(item_radius)
915 Overflow::Hidden
916 Background(row_bg)
917 CursorIcon::Pointer
918 };
919 let text_tenth_style: Style = style! {
920 Width(Length::Percent(100.0))
921 FontSize(13.0)
922 if is_sel {
923 FontWeight::SemiBold
924 } else {
925 FontWeight::Normal
926 }
927 TextColor(row_fg)
928 TextOverflow::Ellipsis
929 };
930 let row: NodeId = view! {
931 row {
932 style: row_seventh_style
933 on_click: on_pick
934 text {
935 style: text_tenth_style
936 { item.as_str() }
937 }
938 }
939 };
940 nodes.push(row);
941 }
942 if nodes.is_empty() {
943 nodes.push({
944 let text_ninth_style: Style = style! {
945 Width(Length::Percent(100.0))
946 Padding(Edges::all(SPACE_SM))
947 FontSize(12.0)
948 TextColor(live_p.get_muted_foreground())
949 };
950 view! {
951 text {
952 style: text_ninth_style
953 { COMMAND_EMPTY_LABEL }
954 }
955 }
956 });
957 }
958 nodes
959 };
960 let cmd_root_style: Style = if is_frameless {
961 style! {
962 FlexDirection::Column
963 Width(Length::Percent(100.0))
964 FlexShrink(1.0)
965 MinHeight(Length::Px(0.0))
966 Overflow::Hidden
967 Padding(Edges::all(0.0))
968 Gap(SPACE_SM)
969 Border::new(0.0, COLOR_TRANSPARENT)
970 Radius(0.0)
971 }
972 } else {
973 style! {
974 FlexDirection::Column
975 Width(Length::Percent(100.0))
976 FlexShrink(1.0)
977 MinHeight(Length::Px(0.0))
978 Overflow::Hidden
979 Padding(Edges::all(CONTROL_INSET))
980 Gap(CONTROL_INSET)
981 Background(theme_palette.get_card())
982 Border::new(geometry.get_border_width(), theme_palette.get_border())
983 Radius(geometry.get_radius_lg())
984 geometry.get_shadow_md()
985 }
986 };
987 let scroll_style: Style = style! {
988 FlexDirection::Column
989 Width(Length::Percent(100.0))
990 FlexShrink(1.0)
991 MinHeight(Length::Px(0.0))
992 MaxHeight(Length::Px(COMMAND_LIST_MAX_HEIGHT))
993 Gap(CONTROL_INSET)
994 StopScrollPropagation(true)
995 };
996 view! {
997 column {
998 style: cmd_root_style
999 EuvInput {
1000 value: query
1001 placeholder: resolved_ph
1002 tokens: init_tok
1003 }
1004 scroll {
1005 style: scroll_style
1006 bind_children: build_cmd_items
1007 }
1008 }
1009 }
1010 }
1011}
1012
1013impl EuvHoverCard {
1015 #[must_use]
1026 pub fn open(mut self, open: Signal<bool>) -> Self {
1027 self.set_open(Some(open));
1028 self
1029 }
1030
1031 #[must_use]
1042 pub fn description<TextValue>(mut self, description: TextValue) -> Self
1043 where
1044 TextValue: Into<String>,
1045 {
1046 self.set_description(description.into());
1047 self
1048 }
1049}
1050
1051#[component]
1053impl EuvHoverCard {
1055 fn render(&self) -> NodeId {
1065 let ctx: Context = current_context();
1066 let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
1067 let theme_palette: ThemePalette = tokens.get_palette();
1068 let geometry: ThemeGeometry = tokens.get_geometry();
1069 let Self {
1070 open: open_opt,
1071 trigger_label,
1072 title,
1073 description,
1074 ..
1075 } = self;
1076 let open: Signal<bool> = open_opt.unwrap_or_else(|| Signal::new(false));
1077 let init_open: bool = open.get_untracked();
1078 let opened_by_hover: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1079 let hover_click: Rc<Cell<bool>> = opened_by_hover.clone();
1080 let hover_enter: Rc<Cell<bool>> = opened_by_hover.clone();
1081 let hover_leave: Rc<Cell<bool>> = opened_by_hover;
1082 let on_enter = move |_: &UiEvent| {
1083 if !open.get_untracked() {
1084 hover_enter.set(true);
1085 }
1086 let _: bool = open.set_if_changed(true);
1087 };
1088 let on_leave = move |_: &UiEvent| {
1089 hover_leave.set(false);
1090 let _: bool = open.set_if_changed(false);
1091 };
1092 let on_btn_click = move |_: &UiEvent| {
1093 if hover_click.replace(false) {
1094 let _: bool = open.set_if_changed(true);
1095 } else {
1096 let _: bool = open.set(!open.get_untracked());
1097 }
1098 };
1099 let mut popup: NodeId = NodeId::default();
1100 let column_fifth_style: Style = style! {
1101 AlignItems::Start
1102 Gap(SPACE_XS)
1103 };
1104 let column_sixth_style: Style = style! {
1105 if init_open { Display::Flex } else { Display::None }
1106 Width(Length::Percent(100.0))
1107 MaxWidth(Length::Px(320.0))
1108 Padding(Edges::all(SPACE_MD))
1109 Gap(SPACE_XS)
1110 Background(theme_palette.get_card())
1111 Border::new(geometry.get_border_width(), theme_palette.get_border())
1112 Radius(geometry.get_radius_lg())
1113 Overflow::Hidden
1114 geometry.get_shadow_lg()
1115 ZIndex(Z_INDEX_FLOATING)
1116 };
1117 let text_seventh_style: Style = style! {
1118 Width(Length::Percent(100.0))
1119 FontSize(13.0)
1120 FontWeight::SemiBold
1121 TextColor(theme_palette.get_card_foreground())
1122 };
1123 let text_eighth_style: Style = style! {
1124 Width(Length::Percent(100.0))
1125 FontSize(12.0)
1126 TextColor(theme_palette.get_muted_foreground())
1127 };
1128 let root: NodeId = view! {
1129 column {
1130 style: column_fifth_style
1131 on_pointer_enter: on_enter
1132 on_pointer_leave: on_leave
1133 EuvButton {
1134 label: trigger_label.clone()
1135 tokens: tokens
1136 link()
1137 small()
1138 on_click: on_btn_click
1139 }
1140 column {
1141 node_ref: popup
1142 style: column_sixth_style
1143 text {
1144 style: text_seventh_style
1145 { title.as_str() }
1146 }
1147 if !description.is_empty() {
1148 text {
1149 style: text_eighth_style
1150 { description.as_str() }
1151 }
1152 }
1153 }
1154 }
1155 };
1156 let handle: SceneHandle = ctx.get_scene().clone();
1157 let prev_open: Cell<bool> = Cell::new(init_open);
1158 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1159 Effect::new(move || {
1160 let is_open: bool = open.get();
1161 if prev_open.replace(is_open) == is_open {
1162 return;
1163 }
1164 if is_open {
1165 handle.with_write(
1166 |tree: &mut SceneTree| {
1167 let (cur_op, cur_ty, was_hidden): (f32, f32, bool) = tree
1168 .get_node(popup)
1169 .map(|scene_node: &SceneNode| {
1170 let hidden: bool =
1171 scene_node.style_ref().get_layout().get_display()
1172 == Display::None;
1173 let paint: PaintStyle = scene_node.style_ref().get_paint();
1174 (
1175 paint.get_opacity(),
1176 paint.get_transform().get_translate_y(),
1177 hidden,
1178 )
1179 })
1180 .unwrap_or((0.0, -4.0, true));
1181 let start_op: f32 = if was_hidden { 0.0 } else { cur_op };
1182 let start_ty: f32 = if was_hidden { -4.0 } else { cur_ty };
1183 tree.cancel_subtree_transitions(popup);
1184 if let Some(item_count) = tree.get_node_mut(popup) {
1185 let computed_style: &mut Style = item_count.get_mut_style();
1186 computed_style.get_mut_layout().set_display(Display::Flex);
1187 computed_style
1188 .get_mut_paint()
1189 .set_pointer_events(PointerEvents::Auto);
1190 }
1191 let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1192 tree.mark_dirty(popup, dirty_l | DIRTY_PAINT);
1193 tree.start_transition(
1194 NodeTransition::slide_fade(
1195 popup,
1196 Point::new(0.0, start_ty),
1197 Point::new(0.0, 0.0),
1198 start_op,
1199 1.0,
1200 motion_duration(MOTION_STANDARD_SECS),
1201 false,
1202 )
1203 .with_easing(MOTION_EASE_ENTER),
1204 );
1205 },
1206 (),
1207 );
1208 } else {
1209 handle.with_write(
1210 |tree: &mut SceneTree| {
1211 let (cur_op, cur_ty): (f32, f32) = tree
1212 .get_node(popup)
1213 .map(|target_node: &SceneNode| {
1214 let paint: PaintStyle = target_node.style_ref().get_paint();
1215 (paint.get_opacity(), paint.get_transform().get_translate_y())
1216 })
1217 .unwrap_or((1.0, 0.0));
1218 tree.cancel_subtree_transitions(popup);
1219 if let Some(node_entry) = tree.get_node_mut(popup) {
1220 node_entry
1221 .get_mut_style()
1222 .get_mut_paint()
1223 .set_pointer_events(PointerEvents::None);
1224 }
1225 tree.mark_dirty(popup, DIRTY_PAINT);
1226 tree.start_transition(
1227 NodeTransition::slide_fade(
1228 popup,
1229 Point::new(0.0, cur_ty),
1230 Point::new(0.0, -4.0),
1231 cur_op,
1232 0.0,
1233 motion_duration(MOTION_STANDARD_SECS),
1234 true,
1235 )
1236 .with_easing(MOTION_EASE_EXIT),
1237 );
1238 },
1239 (),
1240 );
1241 }
1242 })
1243 });
1244 ctx.get_scene().with_write(
1245 |tree: &mut SceneTree| {
1246 tree.attach_scope(root, scope);
1247 },
1248 (),
1249 );
1250 root
1251 }
1252}
1253
1254#[component]
1256impl EuvCalendar {
1258 fn render(&self) -> NodeId {
1271 let mut ctx: Context = current_context();
1272 let base_tokens: ThemeTokens = self.get_tokens();
1273 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1274 let theme_palette: ThemePalette = init_tok.get_palette();
1275 let geometry: ThemeGeometry = init_tok.get_geometry();
1276 let selected_day: Signal<u32> = self.get_selected_day();
1277 let total_days: u32 = self.get_days_in_month().clamp(28, 31);
1278 let Self { month_label, .. } = self;
1279 let init_day: u32 = selected_day.get_untracked();
1280 let border_w: f32 = geometry.get_border_width();
1281 let cell_h: f32 = geometry.get_control_sm();
1282 let cell_radius: f32 = geometry.get_radius_md();
1283 let mut days_grid: NodeId = NodeId::default();
1284 let mut day_nodes: Vec<NodeId> = Vec::with_capacity(total_days as usize);
1285 let mut bound_days: Vec<(NodeId, NodeId)> = Vec::with_capacity(total_days as usize);
1286 let mut owned_nodes: Vec<NodeId> = Vec::with_capacity((total_days as usize) * 2);
1287 for day in 1..=total_days {
1288 let is_sel: bool = init_day == day;
1289 let (bg, fg, border): (Color, Color, Border) = Self::day_visuals(init_tok, is_sel);
1290 let on_pick = move |_: &UiEvent| {
1291 let _: bool = selected_day.set_if_changed(day);
1292 };
1293 let mut lbl_id: NodeId = NodeId::default();
1294 let mut cell_style: Style = Style::default();
1295 cell_style
1296 .get_mut_layout()
1297 .set_flex_direction(FlexDirection::Row)
1298 .set_height(Length::Px(cell_h))
1299 .set_justify_content(JustifyContent::Center)
1300 .set_align_items(AlignItems::Center)
1301 .set_overflow(Overflow::Hidden);
1302 cell_style
1303 .get_mut_paint()
1304 .set_radius(CornerRadius::all(cell_radius))
1305 .set_background(Some(bg))
1306 .set_border(border)
1307 .set_cursor(CursorIcon::Pointer);
1308 let text_sixth_style: Style = style! {
1309 Width(Length::Percent(100.0))
1310 FontSize(12.0)
1311 if is_sel {
1312 FontWeight::SemiBold
1313 } else {
1314 FontWeight::Medium
1315 }
1316 TextColor(fg)
1317 TextAlign::Center
1318 TextOverflow::Clip
1319 };
1320 let cell_id: NodeId = view! {
1321 row {
1322 style: cell_style
1323 on_click: on_pick
1324 text {
1325 node_ref: lbl_id
1326 style: text_sixth_style
1327 { day.to_string() }
1328 }
1329 }
1330 };
1331 day_nodes.push(cell_id);
1332 owned_nodes.push(cell_id);
1333 owned_nodes.push(lbl_id);
1334 bound_days.push((cell_id, lbl_id));
1335 }
1336 let column_quaternary_style: Style = style! {
1337 Width(Length::Percent(100.0))
1338 Padding(Edges::all(SPACE_MD))
1339 Gap(SPACE_SM)
1340 Background(theme_palette.get_card())
1341 Border::new(border_w, theme_palette.get_border())
1342 Radius(geometry.get_radius_lg())
1343 Overflow::Hidden
1344 };
1345 let text_quaternary_style: Style = style! {
1346 Width(Length::Percent(100.0))
1347 FontSize(14.0)
1348 FontWeight::SemiBold
1349 TextColor(theme_palette.get_card_foreground())
1350 TextAlign::Center
1351 };
1352 let grid_style: Style = style! {
1353 GridColumns(7)
1354 Width(Length::Percent(100.0))
1355 Gap(2.0)
1356 };
1357 let row_sixth_style: Style = style! {
1358 JustifyContent::Center
1359 AlignItems::Center
1360 Padding(Edges::symmetric(2.0, 0.0))
1361 };
1362 let text_fifth_style: Style = style! {
1363 FontSize(11.0)
1364 FontWeight::Medium
1365 TextColor(theme_palette.get_muted_foreground())
1366 TextAlign::Center
1367 };
1368 let root: NodeId = view! {
1369 column {
1370 style: column_quaternary_style
1371 text {
1372 style: text_quaternary_style
1373 { month_label.as_str() }
1374 }
1375 grid {
1376 style: grid_style
1377 for wd in CALENDAR_WEEKDAYS.iter().copied() {
1378 row {
1379 style: row_sixth_style
1380 text {
1381 style: text_fifth_style
1382 { wd }
1383 }
1384 }
1385 }
1386 }
1387 grid {
1388 node_ref: days_grid
1389 style: grid_style
1390 }
1391 }
1392 };
1393 if !day_nodes.is_empty() {
1394 ctx.append_many(days_grid, day_nodes.as_slice());
1395 }
1396 let handle: SceneHandle = ctx.get_scene().clone();
1397 let prev_state: Cell<(u32, ThemeKey)> = Cell::new((init_day, init_tok.key()));
1398 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1399 Effect::new(move || {
1400 let next_day: u32 = selected_day.get();
1401 let tok: ThemeTokens = use_live_tokens(base_tokens);
1402 let (old_day, old_key): (u32, ThemeKey) = prev_state.replace((next_day, tok.key()));
1403 if old_day == next_day && old_key == tok.key() {
1404 return;
1405 }
1406 handle.with_write(
1407 |tree: &mut SceneTree| {
1408 for (idx, (cell_id, lbl_id)) in bound_days.iter().enumerate() {
1409 let is_sel: bool = (idx as u32) + 1 == next_day;
1410 let (bg, fg, border): (Color, Color, Border) =
1411 Self::day_visuals(tok, is_sel);
1412 if let Some(item_count) = tree.get_node_mut(*cell_id) {
1413 item_count
1414 .get_mut_style()
1415 .get_mut_paint()
1416 .set_background(Some(bg))
1417 .set_border(border);
1418 tree.mark_dirty(*cell_id, DIRTY_PAINT);
1419 }
1420 if let Some(node_entry) = tree.get_node_mut(*lbl_id) {
1421 node_entry
1422 .get_mut_style()
1423 .get_mut_text()
1424 .set_weight(if is_sel {
1425 FontWeight::SemiBold
1426 } else {
1427 FontWeight::Medium
1428 })
1429 .set_color(fg);
1430 let mut dirty_lbl: u16 = DIRTY_LAYOUT | DIRTY_TEXT;
1431 dirty_lbl |= DIRTY_PAINT;
1432 tree.mark_dirty(*lbl_id, dirty_lbl);
1433 }
1434 }
1435 },
1436 (),
1437 );
1438 })
1439 });
1440 ctx.get_scene().with_write(
1441 |tree: &mut SceneTree| {
1442 mark_theme_owned(tree, owned_nodes.as_slice());
1443 tree.attach_scope(root, scope);
1444 },
1445 (),
1446 );
1447 root
1448 }
1449}
1450
1451impl EuvCalendar {
1453 #[must_use]
1464 pub fn day_visuals(tokens: ThemeTokens, selected: bool) -> (Color, Color, Border) {
1465 let theme_palette: ThemePalette = tokens.get_palette();
1466 let border_width: f32 = tokens.get_geometry().get_border_width();
1467 if selected {
1468 let surf: SurfaceColors = theme_palette.surface(SurfaceRole::Primary);
1469 (
1470 surf.get_bg(),
1471 surf.get_fg(),
1472 Border::new(border_width, surf.get_border()),
1473 )
1474 } else {
1475 let card: SurfaceColors = theme_palette.surface(SurfaceRole::Card);
1476 (
1477 COLOR_TRANSPARENT,
1478 card.get_fg(),
1479 Border::new(border_width, COLOR_TRANSPARENT),
1480 )
1481 }
1482 }
1483}
1484
1485#[component]
1487impl EuvAspectRatio {
1489 fn render(&self) -> NodeId {
1499 let init_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
1500 let theme_palette: ThemePalette = init_tok.get_palette();
1501 let geometry: ThemeGeometry = init_tok.get_geometry();
1502 let ratio: f32 = if self.get_ratio() > 0.0 && self.get_ratio().is_finite() {
1503 self.get_ratio()
1504 } else {
1505 16.0 / 9.0
1506 };
1507 let child: NodeId = self.get_child();
1508 let column_tertiary_style: Style = style! {
1509 Width(Length::Percent(100.0))
1510 AspectRatio(ratio)
1511 JustifyContent::Center
1512 AlignItems::Center
1513 Background(theme_palette.get_muted())
1514 Border::new(geometry.get_border_width(), theme_palette.get_border())
1515 Radius(geometry.get_radius_md())
1516 Overflow::Hidden
1517 };
1518 view! {
1519 column {
1520 style: column_tertiary_style
1521 { child }
1522 }
1523 }
1524 }
1525}
1526
1527#[component]
1529impl EuvMenubar {
1531 fn render(&self) -> NodeId {
1544 let mut ctx: Context = current_context();
1545 let base_tokens: ThemeTokens = self.get_tokens();
1546 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1547 let theme_palette: ThemePalette = init_tok.get_palette();
1548 let geometry: ThemeGeometry = init_tok.get_geometry();
1549 let active_menu: Signal<Option<usize>> = self.get_active_menu();
1550 let Self { menus, .. } = self;
1551 let init_active: Option<usize> = active_menu.get_untracked();
1552 let bar_radius: f32 = geometry.get_radius_lg();
1553 let item_radius: f32 = concentric_radius(bar_radius, CONTROL_INSET);
1554 let mut menu_nodes: Vec<NodeId> = Vec::with_capacity(menus.len());
1555 let mut bound_menus: Vec<(NodeId, NodeId)> = Vec::with_capacity(menus.len());
1556 let mut owned_nodes: Vec<NodeId> = Vec::with_capacity(menus.len() * 2);
1557 for (idx, label) in menus.iter().enumerate() {
1558 let is_open: bool = init_active == Some(idx);
1559 let (bg, fg): (Color, Color) = Self::item_colors(init_tok, is_open);
1560 let on_pick = move |_: &UiEvent| {
1561 let _: bool = {
1562 if let Some(mut updated_value) = active_menu.try_get_untracked() {
1563 {
1564 let cur: &mut Option<usize> = &mut updated_value;
1565 *cur = if *cur == Some(idx) { None } else { Some(idx) };
1566 }
1567 active_menu.set(updated_value)
1568 } else {
1569 false
1570 }
1571 };
1572 };
1573 let mut lbl_id: NodeId = NodeId::default();
1574 let row_fifth_style: Style = style! {
1575 Height(Length::Px(geometry.get_control_sm()))
1576 JustifyContent::Center
1577 AlignItems::Center
1578 Padding(Edges::symmetric(0.0, SPACE_MD))
1579 Overflow::Hidden
1580 Radius(item_radius)
1581 Background(bg)
1582 CursorIcon::Pointer
1583 };
1584 let text_tertiary_style: Style = style! {
1585 FontSize(13.0)
1586 FontWeight::Medium
1587 TextColor(fg)
1588 TextAlign::Center
1589 TextOverflow::Ellipsis
1590 };
1591 let item_id: NodeId = view! {
1592 row {
1593 style: row_fifth_style
1594 role: A11yRole::MenuItem
1595 a11y_label: label.clone()
1596 on_click: on_pick
1597 text {
1598 node_ref: lbl_id
1599 style: text_tertiary_style
1600 { label.as_str() }
1601 }
1602 }
1603 };
1604 menu_nodes.push(item_id);
1605 owned_nodes.push(item_id);
1606 owned_nodes.push(lbl_id);
1607 bound_menus.push((item_id, lbl_id));
1608 }
1609 let row_quaternary_style: Style = style! {
1610 FlexWrap::Wrap
1611 Width(Length::Percent(100.0))
1612 Padding(Edges::all(CONTROL_INSET))
1613 Gap(CONTROL_INSET)
1614 Background(theme_palette.get_card())
1615 Border::new(geometry.get_border_width(), theme_palette.get_border())
1616 Radius(bar_radius)
1617 Overflow::Hidden
1618 };
1619 let root: NodeId = view! {
1620 row {
1621 style: row_quaternary_style
1622 role: A11yRole::Menu
1623 }
1624 };
1625 if !menu_nodes.is_empty() {
1626 ctx.append_many(root, menu_nodes.as_slice());
1627 }
1628 let handle: SceneHandle = ctx.get_scene().clone();
1629 let prev_state: Cell<(Option<usize>, ThemeKey)> = Cell::new((init_active, init_tok.key()));
1630 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1631 Effect::new(move || {
1632 let next_active: Option<usize> = active_menu.get();
1633 let tok: ThemeTokens = use_live_tokens(base_tokens);
1634 let (old_active, old_key): (Option<usize>, ThemeKey) =
1635 prev_state.replace((next_active, tok.key()));
1636 if old_active == next_active && old_key == tok.key() {
1637 return;
1638 }
1639 handle.with_write(
1640 |tree: &mut SceneTree| {
1641 for (idx, (item_id, lbl_id)) in bound_menus.iter().enumerate() {
1642 let is_open: bool = next_active == Some(idx);
1643 let (bg, fg): (Color, Color) = Self::item_colors(tok, is_open);
1644 if let Some(item_count) = tree.get_node_mut(*item_id) {
1645 item_count
1646 .get_mut_style()
1647 .get_mut_paint()
1648 .set_background(Some(bg));
1649 tree.mark_dirty(*item_id, DIRTY_PAINT);
1650 }
1651 if let Some(node_entry) = tree.get_node_mut(*lbl_id) {
1652 node_entry.get_mut_style().get_mut_text().set_color(fg);
1653 tree.mark_dirty(*lbl_id, DIRTY_PAINT);
1654 }
1655 }
1656 },
1657 (),
1658 );
1659 })
1660 });
1661 ctx.get_scene().with_write(
1662 |tree: &mut SceneTree| {
1663 mark_theme_owned(tree, owned_nodes.as_slice());
1664 tree.attach_scope(root, scope);
1665 },
1666 (),
1667 );
1668 root
1669 }
1670}
1671
1672impl EuvMenubar {
1674 #[must_use]
1685 pub fn item_colors(tokens: ThemeTokens, active: bool) -> (Color, Color) {
1686 let palette: ThemePalette = tokens.get_palette();
1687 let surface: SurfaceColors =
1688 palette.interaction_colors(InteractionRole::OptionItem, false, active, false);
1689 (surface.get_bg(), surface.get_fg())
1690 }
1691}
1692
1693#[component]
1695impl EuvCarousel {
1697 fn render(&self) -> NodeId {
1709 let mut ctx: Context = current_context();
1710 let base_tokens: ThemeTokens = self.get_tokens();
1711 let init_tok: ThemeTokens = live_tokens_untracked(base_tokens);
1712 let theme_palette: ThemePalette = init_tok.get_palette();
1713 let geometry: ThemeGeometry = init_tok.get_geometry();
1714 let muted_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Muted);
1715 let active: Signal<usize> = self.get_active_slide();
1716 let Self { slides, .. } = self;
1717 let total: usize = slides.len();
1718 let init_active: usize = if total == 0 {
1719 0
1720 } else {
1721 active.get_untracked() % total
1722 };
1723 let slides_for_text: Rc<[String]> = Rc::from(slides.as_slice());
1724 let slide_label = move || -> String {
1725 if total == 0 {
1726 CAROUSEL_EMPTY_LABEL.to_string()
1727 } else {
1728 let idx: usize = active.get() % total;
1729 slides_for_text[idx].clone()
1730 }
1731 };
1732 let slide_counter = move || -> String {
1733 if total == 0 {
1734 CAROUSEL_ZERO_COUNTER.to_string()
1735 } else {
1736 format!("{} / {total}", (active.get() % total) + 1)
1737 }
1738 };
1739 let on_prev = move |_: &UiEvent| {
1740 if total > 0 {
1741 let _: bool = {
1742 if let Some(mut updated_value) = active.try_get_untracked() {
1743 {
1744 let item_val: &mut usize = &mut updated_value;
1745 *item_val = if *item_val == 0 {
1746 total - 1
1747 } else {
1748 *item_val - 1
1749 };
1750 }
1751 active.set(updated_value)
1752 } else {
1753 false
1754 }
1755 };
1756 }
1757 };
1758 let on_next = move |_: &UiEvent| {
1759 if total > 0 {
1760 let _: bool = {
1761 if let Some(mut updated_value) = active.try_get_untracked() {
1762 {
1763 let tex_v: &mut usize = &mut updated_value;
1764 *tex_v = (*tex_v + 1) % total;
1765 }
1766 active.set(updated_value)
1767 } else {
1768 false
1769 }
1770 };
1771 }
1772 };
1773 let dot_nodes: Vec<NodeId> = (0..total)
1774 .map(|idx: usize| {
1775 let is_cur: bool = idx == init_active;
1776 let dot_bg: Color = Self::dot_color(theme_palette, is_cur);
1777 let on_pick_dot = move |_: &UiEvent| {
1778 let _: bool = active.set_if_changed(idx);
1779 };
1780 let view_style: Style = style! {
1781 Width(Length::Px(CAROUSEL_DOT_SIZE))
1782 Height(Length::Px(CAROUSEL_DOT_SIZE))
1783 Radius(RADIUS_PILL)
1784 Background(dot_bg)
1785 CursorIcon::Pointer
1786 };
1787 view! {
1788 view {
1789 style: view_style
1790 on_click: on_pick_dot
1791 }
1792 }
1793 })
1794 .collect();
1795 let mut dots_row: NodeId = NodeId::default();
1796 let column_style: Style = style! {
1797 Width(Length::Percent(100.0))
1798 Gap(SPACE_SM)
1799 };
1800 let column_secondary_style: Style = style! {
1801 Width(Length::Percent(100.0))
1802 Padding(Edges::all(SPACE_XL))
1803 JustifyContent::Center
1804 AlignItems::Center
1805 Background(muted_surface.get_bg())
1806 Border::new(geometry.get_border_width(), muted_surface.get_border())
1807 Radius(geometry.get_radius_lg())
1808 Overflow::Hidden
1809 };
1810 let text_style: Style = style! {
1811 Width(Length::Percent(100.0))
1812 FontSize(14.0)
1813 FontWeight::SemiBold
1814 TextColor(muted_surface.get_fg())
1815 TextAlign::Center
1816 };
1817 let row_style: Style = style! {
1818 FlexWrap::Wrap
1819 Width(Length::Percent(100.0))
1820 JustifyContent::SpaceBetween
1821 AlignItems::Center
1822 Gap(SPACE_SM)
1823 };
1824 let row_secondary_style: Style = style! {
1825 AlignItems::Center
1826 Gap(SPACE_SM)
1827 };
1828 let row_tertiary_style: Style = style! {
1829 AlignItems::Center
1830 Gap(SPACE_XS)
1831 };
1832 let text_secondary_style: Style = style! {
1833 FontSize(12.0)
1834 TextColor(theme_palette.get_muted_foreground())
1835 };
1836 let root: NodeId = view! {
1837 column {
1838 style: column_style
1839 column {
1840 style: column_secondary_style
1841 text {
1842 style: text_style
1843 { slide_label }
1844 }
1845 }
1846 row {
1847 style: row_style
1848 EuvButton {
1849 label: PAGE_PREV_LABEL.to_string()
1850 tokens: init_tok
1851 outline()
1852 small()
1853 on_click: on_prev
1854 }
1855 row {
1856 style: row_secondary_style
1857 row {
1858 node_ref: dots_row
1859 style: row_tertiary_style
1860 }
1861 text {
1862 style: text_secondary_style
1863 { slide_counter }
1864 }
1865 }
1866 EuvButton {
1867 label: PAGE_NEXT_LABEL.to_string()
1868 tokens: init_tok
1869 outline()
1870 small()
1871 on_click: on_next
1872 }
1873 }
1874 }
1875 };
1876 if !dot_nodes.is_empty() {
1877 ctx.append_many(dots_row, dot_nodes.as_slice());
1878 let handle: SceneHandle = ctx.get_scene().clone();
1879 let owned_dots: Vec<NodeId> = dot_nodes.clone();
1880 let prev_state: Cell<(usize, ThemeKey)> = Cell::new((init_active, init_tok.key()));
1881 let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1882 Effect::new(move || {
1883 let next_idx: usize = active.get() % total;
1884 let tok: ThemeTokens = use_live_tokens(base_tokens);
1885 let (old_idx, old_key): (usize, ThemeKey) =
1886 prev_state.replace((next_idx, tok.key()));
1887 if old_idx == next_idx && old_key == tok.key() {
1888 return;
1889 }
1890 let live_p: ThemePalette = tok.get_palette();
1891 handle.with_write(
1892 |tree: &mut SceneTree| {
1893 for (idx, &dot_id) in dot_nodes.iter().enumerate() {
1894 if let Some(item_count) = tree.get_node_mut(dot_id) {
1895 item_count.get_mut_style().get_mut_paint().set_background(
1896 Some(Self::dot_color(live_p, idx == next_idx)),
1897 );
1898 tree.mark_dirty(dot_id, DIRTY_PAINT);
1899 }
1900 }
1901 },
1902 (),
1903 );
1904 })
1905 });
1906 ctx.get_scene().with_write(
1907 |tree: &mut SceneTree| {
1908 mark_theme_owned(tree, owned_dots.as_slice());
1909 tree.attach_scope(root, scope);
1910 },
1911 (),
1912 );
1913 }
1914 root
1915 }
1916}
1917
1918impl EuvCarousel {
1920 #[must_use]
1931 pub fn dot_color(palette: ThemePalette, active: bool) -> Color {
1932 if active {
1933 palette.get_primary()
1934 } else {
1935 palette.get_border()
1936 }
1937 }
1938}