1use super::*;
2
3pub(crate) fn ensure_showcase_routes_registered(state: &ShowcaseState) {
9 if state.get_router_ready().replace(true) {
10 return;
11 }
12 let mut router: EuvRouter = state.get_router().clone();
13 for spec in SHOWCASE_ROUTES.iter() {
14 let path: &'static str = spec.get_path();
15 let st: ShowcaseState = state.clone();
16 router = router.route_component(path, spec.get_label(), move |_: &EuvRouteMatch| {
17 let tok: ThemeTokens = untracked(|| st.get_theme().get_tokens().get());
18 ShowcasePage::new(path, st.clone(), tok)
19 });
20 }
21 let _: EuvRouter = router;
22}
23
24pub(crate) fn mount_lazy_cmd_palette_modal(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
35 let cmd_open: Signal<bool> = state.get_cmd_palette_open();
36 let cmd_query: Signal<String> = state.get_cmd_palette_query();
37 let mut cmd_items: Vec<String> = SHOWCASE_ROUTES
38 .iter()
39 .map(|spec: &ShowcaseRouteSpec| {
40 format!("Go to {} ({})", spec.get_label(), spec.get_section())
41 })
42 .collect();
43 cmd_items.push(CMD_ITEM_TOGGLE_MODE.to_string());
44 let cmd_sel: Signal<Option<usize>> = Signal::new(None);
45 let cmd_route: Signal<String> = state.get_route();
46 let cmd_state: ShowcaseState = state.clone();
47 let cmd_list: NodeId = view! {
48 EuvCommand {
49 items: cmd_items
50 selected: cmd_sel
51 tokens: tokens
52 query: cmd_query
53 placeholder: CMD_PLACEHOLDER
54 }
55 };
56 let (cmd_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
57 Effect::new(move || {
58 if let Some(idx) = cmd_sel.get() {
59 match SHOWCASE_ROUTES.get(idx) {
60 Some(spec) => {
61 let _: bool = cmd_route.set_if_changed(spec.get_path().to_string());
62 }
63 None => {
64 cmd_state.toggle_theme_mode();
65 }
66 }
67 let _: bool = cmd_sel.set_if_changed(None);
68 let _: bool = cmd_open.set_if_changed(false);
69 }
70 })
71 });
72 let cmd_modal: NodeId = view! {
73 EuvModal {
74 open: cmd_open
75 title: CMD_MODAL_TITLE.to_string()
76 body: cmd_list
77 tokens: tokens
78 }
79 };
80 let rctx: Context = current_context();
81 let cmd_theme_sig: Memo<ThemeTokens> = state.get_theme().get_tokens();
82 let prev_cmd_tok: Rc<Cell<ThemeTokens>> = Rc::new(Cell::new(tokens));
83 let cmd_theme_ctx: Context = rctx.clone();
84 let (cmd_theme_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
85 Effect::new(move || {
86 let next_tok: ThemeTokens = cmd_theme_sig.get();
87 let old_tok: ThemeTokens = prev_cmd_tok.replace(next_tok);
88 if old_tok == next_tok {
89 return;
90 }
91 cmd_theme_ctx.get_scene().with_write(
92 |tree: &mut SceneTree| {
93 remap_subtree_theme_in_place(tree, cmd_modal, old_tok, next_tok);
94 },
95 (),
96 );
97 })
98 });
99 rctx.get_scene().with_write(
100 |tree: &mut SceneTree| {
101 tree.attach_scope(cmd_modal, cmd_scope);
102 tree.attach_scope(cmd_modal, cmd_theme_scope);
103 },
104 (),
105 );
106 cmd_modal
107}
108
109pub fn mount_showcase_root(state: &ShowcaseState) -> NodeId {
119 provide_theme(state.get_theme().clone());
120 ensure_showcase_routes_registered(state);
121 let global_banner: Signal<ShowcaseGlobalBanner> =
122 state!(global ShowcaseGlobalBanner = ShowcaseGlobalBanner::default());
123 let state_c: ShowcaseState = state.clone();
124 let bg_state: ShowcaseState = state.clone();
125 let fg_state: ShowcaseState = state.clone();
126 let sys_state: ShowcaseState = state.clone();
127 let sys_log_sig: Signal<Vec<String>> = state.get_system_event_log();
128 let sys_count_sig: Signal<u32> = state.get_system_event_count();
129 let (ev_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
130 let _: SystemEventSubscription = on_background(move || {
131 bg_state.freeze_for_background();
132 });
133 let _: SystemEventSubscription = on_foreground(move || {
134 fg_state.restore_from_foreground();
135 });
136 let _: SystemEventSubscription = on_system_event(move |ev: &SystemEvent| {
137 if matches!(ev, SystemEvent::Terminate) {
138 sys_state.freeze_for_background();
139 let _: usize = EuvOverlayStack::dismiss_all();
140 reset_fullscreen_state();
141 } else if matches!(ev, SystemEvent::Foreground) {
142 sys_state.restore_from_foreground();
143 }
144 let next_seq: u32 = sys_count_sig.get_untracked().saturating_add(1);
145 let _: bool = sys_count_sig.set(next_seq);
146 let entry: String = format!("#{next_seq}: {ev:?}");
147 let _: bool = sys_log_sig.update(|items: &mut Vec<String>| {
148 items.insert(0, entry);
149 if items.len() > SYS_EVENTS_LOG_LIMIT {
150 items.truncate(SYS_EVENTS_LOG_LIMIT);
151 }
152 });
153 });
154 on!(ShowcasePulseEvent => move |ev: &ShowcasePulseEvent| {
155 let src: String = ev.get_source().clone();
156 let _: bool = global_banner.update(|b: &mut ShowcaseGlobalBanner| {
157 let next_pulses: u32 = b.get_pulses().saturating_add(1);
158 b.set_pulses(next_pulses);
159 b.set_last_source(src);
160 });
161 })
162 });
163 let build_root_children = move || -> Vec<NodeId> {
164 let tokens: ThemeTokens = untracked(|| state_c.get_theme().get_tokens().get());
165 let hub: DynamicUpdateHub = state_c.get_dynamic_hub().clone();
166 let _: u64 = hub.routes_signal().get();
167 let cmd_open: Signal<bool> = state_c.get_cmd_palette_open();
168 let cmd_slot: NodeId = view! {
169 column {
170 style: {
171 position: Position::Absolute
172 width: Length::Px(0.0)
173 height: Length::Px(0.0)
174 }
175 }
176 };
177 let cmd_mounted: Rc<Cell<bool>> = Rc::new(Cell::new(false));
178 let cmd_state_lazy: ShowcaseState = state_c.clone();
179 let rctx: Context = current_context();
180 let cmd_ctx: Context = rctx.clone();
181 let (cmd_lazy_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
182 Effect::new(move || {
183 if !cmd_open.get() || cmd_mounted.get() {
184 return;
185 }
186 cmd_mounted.set(true);
187 let live_tok: ThemeTokens =
188 untracked(|| cmd_state_lazy.get_theme().get_tokens().get());
189 let modal_node: NodeId = with_context(cmd_ctx.clone(), || {
190 mount_lazy_cmd_palette_modal(&cmd_state_lazy, live_tok)
191 });
192 cmd_ctx.get_scene().with_write(
193 |tree: &mut SceneTree| {
194 let dirty_mask: u16 = DIRTY_CHILDREN + DIRTY_LAYOUT + DIRTY_PAINT;
195 tree.append_child(cmd_slot, modal_node);
196 tree.mark_dirty(cmd_slot, dirty_mask);
197 },
198 (),
199 );
200 })
201 });
202 rctx.get_scene().with_write(
203 |tree: &mut SceneTree| {
204 tree.attach_scope(cmd_slot, cmd_lazy_scope);
205 },
206 (),
207 );
208 let state_shell: ShowcaseState = state_c.clone();
209 let hub_shell: DynamicUpdateHub = hub.clone();
210 let render_native_shell = move || -> NodeId {
211 let shell_node: NodeId = mount_native_app_shell(&state_shell, &hub_shell, tokens);
212 shell_node
213 };
214 let global_wasm_slot: NodeId = view! {
215 slot {
216 id: WASM_GLOBAL_ROOT_SLOT
217 hub: hub
218 style: c_full_col()
219 fallback: render_native_shell
220 }
221 };
222 vec![global_wasm_slot, cmd_slot]
223 };
224 let root_node: NodeId = view! {
225 column {
226 style: {
227 width: Length::Percent(100.0)
228 height: Length::Percent(100.0)
229 }
230 bind_children: build_root_children
231 }
232 };
233 let root_ctx: Context = current_context();
234 root_ctx.get_scene().with_write(
235 |tree: &mut SceneTree| {
236 tree.attach_scope(root_node, ev_scope);
237 },
238 (),
239 );
240 root_node
241}
242
243pub(crate) fn mount_native_app_shell(
255 state_shell: &ShowcaseState,
256 hub_shell: &DynamicUpdateHub,
257 tokens: ThemeTokens,
258) -> NodeId {
259 let mut nav_items: Vec<EuvNavItem> = ShowcaseState::nav_items();
260 for dyn_route in hub_shell.registered_routes().into_iter() {
261 if dyn_route == ROUTE_DYNAMIC_PANEL {
262 continue;
263 }
264 if !nav_items
265 .iter()
266 .any(|item: &EuvNavItem| item.get_path().as_str() == dyn_route.as_str())
267 {
268 let label: String = hub_shell
269 .page_title(&dyn_route)
270 .filter(|t: &String| !t.is_empty())
271 .unwrap_or_else(|| dyn_route.clone());
272 nav_items.push(EuvNavItem::new(dyn_route, label).section(NAV_SEC_RUNTIME));
273 }
274 }
275 let nav: NodeId = view! {
276 EuvSidebarNav {
277 items: nav_items
278 active_route: state_shell.get_route()
279 tokens: tokens
280 }
281 };
282 let bottom_items: Vec<EuvNavItem> = vec![
283 EuvNavItem::new(ROUTE_OVERVIEW.to_string(), BNAV_HOME_LABEL.to_string())
284 .section(BNAV_HOME_ICON),
285 EuvNavItem::new(ROUTE_MARKDOWN.to_string(), BNAV_DOCS_LABEL.to_string())
286 .section(BNAV_DOCS_ICON),
287 EuvNavItem::new(ROUTE_LAB.to_string(), BNAV_CASES_LABEL.to_string())
288 .section(BNAV_CASES_ICON),
289 EuvNavItem::new(ROUTE_STRESS.to_string(), BNAV_STRESS_LABEL.to_string())
290 .section(BNAV_STRESS_ICON),
291 EuvNavItem::new(ROUTE_GAME_3D.to_string(), BNAV_3D_LABEL.to_string()).section(BNAV_3D_ICON),
292 ];
293 let bottom_nav: NodeId = view! {
294 EuvBottomNav {
295 items: bottom_items
296 active_route: state_shell.get_route()
297 tokens: tokens
298 }
299 };
300 let swipe_order: Vec<String> = showcase_swipe_order();
301 let state_for_outlet: ShowcaseState = state_shell.clone();
302 let router: EuvRouter = state_shell
303 .get_router()
304 .clone()
305 .with_dynamic_hub(hub_shell.clone());
306 let route_sig: Signal<String> = state_shell.get_route();
307 let cur_target: String = route_sig.get_untracked();
308 if router.get_current_path().get_untracked() != cur_target {
309 router.replace(&cur_target);
310 }
311 let breadcrumb_sig: Signal<String> =
312 Signal::new(ShowcaseState::breadcrumb_for_route(&cur_target));
313 let page_pad_sig: Signal<Edges> = Signal::new(Edges::all(SPACE_LG));
314 let router_sync_in: EuvRouter = router.clone();
315 let router_path_sig: Signal<String> = router.get_current_path();
316 let reduced_motion_sig: Signal<bool> = state_shell.get_reduced_motion();
317 let sctx: Context = current_context();
318 let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
319 let _: Effect = Effect::new(move || {
320 let target: String = route_sig.get();
321 if router_sync_in.get_current_path().get_untracked() != target {
322 router_sync_in.push(&target);
323 }
324 let _: bool =
325 breadcrumb_sig.set_if_changed(ShowcaseState::breadcrumb_for_route(&target));
326 });
327 let _: Effect = Effect::new(move || {
328 set_reduced_motion(reduced_motion_sig.get());
329 });
330 Effect::new(move || {
331 let rp: String = router_path_sig.get();
332 if route_sig.get_untracked() != rp {
333 let _: bool = route_sig.set_if_changed(rp);
334 }
335 })
336 });
337 let page_node: NodeId = router
338 .outlet(move |matched: &EuvRouteMatch| {
339 let tok: ThemeTokens = untracked(|| state_for_outlet.get_theme().get_tokens().get());
340 mount_route_by_name(matched.get_path(), &state_for_outlet, tok)
341 })
342 .with_theme(state_shell.get_theme().clone())
343 .with_page_padding(page_pad_sig)
344 .with_route_order(swipe_order.clone())
345 .with_double_back_exit(true)
346 .mount();
347 sctx.get_scene().with_write(
348 |tree: &mut SceneTree| {
349 tree.attach_scope(page_node, sync_scope);
350 },
351 (),
352 );
353 let top_actions: NodeId = mount_topbar_actions(state_shell, tokens);
354 let mobile_actions: NodeId = mount_topbar_actions(state_shell, tokens);
355 view! {
356 EuvAppShell {
357 brand: SHOWCASE_BRAND.to_string()
358 sidebar: nav
359 main_content: page_node
360 tokens: tokens
361 theme: state_shell.get_theme().clone()
362 page_padding: page_pad_sig
363 route: state_shell.get_route()
364 breadcrumb: breadcrumb_sig
365 top_bar_actions: top_actions
366 mobile_header_actions: mobile_actions
367 bottom_nav: bottom_nav
368 swipe_routes: swipe_order
369 swipe_routes_enabled: state_shell.get_swipe_routing()
370 show_fps: true
371 show_fps_signal: state_shell.get_show_fps_hud()
372 auto_hide_chrome_on_scroll: true
373 auto_hide_chrome_signal: state_shell.get_auto_hide_chrome()
374 }
375 }
376}
377
378pub fn mount_active_route(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
389 let route: String = state.get_route().get_untracked();
390 mount_route_by_name(&route, state, tokens)
391}
392
393pub(crate) fn mount_route_by_name(
405 route: &str,
406 state: &ShowcaseState,
407 tokens: ThemeTokens,
408) -> NodeId {
409 let builder: fn(&ShowcaseState, ThemeTokens) -> NodeId = SHOWCASE_ROUTES
410 .iter()
411 .find(|spec: &&ShowcaseRouteSpec| spec.get_path() == route)
412 .map(|spec: &ShowcaseRouteSpec| spec.get_mount())
413 .unwrap_or(mount_overview_page);
414 builder(state, tokens)
415}
416
417pub(crate) fn showcase_swipe_order() -> Vec<String> {
423 let mut order: Vec<String> = BOTTOM_NAV_ROUTES
424 .iter()
425 .map(|path: &&str| (*path).to_string())
426 .collect();
427 for spec in SHOWCASE_ROUTES.iter() {
428 if !BOTTOM_NAV_ROUTES.contains(&spec.get_path()) {
429 order.push(spec.get_path().to_string());
430 }
431 }
432 order
433}
434
435pub(crate) fn topbar_icon_basis(bounds: Rect) -> (f32, f32, f32, f32) {
445 let w: f32 = bounds.get_width().max(8.0);
446 let h: f32 = bounds.get_height().max(8.0);
447 let side: f32 = w.min(h);
448 let ox: f32 = bounds.get_x() + (w - side) * 0.5;
449 let oy: f32 = bounds.get_y() + (h - side) * 0.5;
450 let u: f32 = side / 24.0;
451 let sw: f32 = (1.75 * u).clamp(1.2, 2.0);
452 (ox, oy, u, sw)
453}
454
455pub(crate) fn push_rounded_stroke(
465 dl: &mut DisplayList,
466 from: Point,
467 to: Point,
468 color: Color,
469 width: f32,
470) {
471 let cap_r: f32 = (width * 0.48).max(0.45);
472 dl.push(DrawCommand::Line {
473 from,
474 to,
475 color,
476 width,
477 });
478 dl.push(DrawCommand::Circle {
479 center: from,
480 radius: cap_r,
481 color,
482 });
483 dl.push(DrawCommand::Circle {
484 center: to,
485 radius: cap_r,
486 color,
487 });
488}
489
490pub(crate) fn draw_topbar_search_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
498 let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
499 let lens_d: f32 = 13.6 * u;
500 dl.push(DrawCommand::FillRoundedRect {
501 rect: Rect::new(ox + 4.2 * u, oy + 4.2 * u, lens_d, lens_d),
502 color: COLOR_TRANSPARENT,
503 radius: CornerRadius::all(RADIUS_PILL),
504 border: Border::new(sw, color),
505 });
506 push_rounded_stroke(
507 dl,
508 Point::new(ox + 16.0 * u, oy + 16.0 * u),
509 Point::new(ox + 20.2 * u, oy + 20.2 * u),
510 color,
511 sw,
512 );
513}
514
515pub(crate) fn draw_theme_sun_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
523 let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
524 let cx: f32 = ox + 12.0 * u;
525 let cy: f32 = oy + 12.0 * u;
526 let core_r: f32 = 4.2 * u;
527 dl.push(DrawCommand::FillRoundedRect {
528 rect: Rect::new(cx - core_r, cy - core_r, core_r * 2.0, core_r * 2.0),
529 color: COLOR_TRANSPARENT,
530 radius: CornerRadius::all(RADIUS_PILL),
531 border: Border::new(sw, color),
532 });
533 let r_in: f32 = 7.0 * u;
534 let r_out: f32 = 9.4 * u;
535 for idx in 0..8_u8 {
536 let ang: f32 = (idx as f32) * (PI * 0.25);
537 let (cos_a, sin_a): (f32, f32) = (ang.cos(), ang.sin());
538 push_rounded_stroke(
539 dl,
540 Point::new(cx + r_in * cos_a, cy + r_in * sin_a),
541 Point::new(cx + r_out * cos_a, cy + r_out * sin_a),
542 color,
543 sw,
544 );
545 }
546}
547
548pub(crate) fn draw_theme_moon_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
556 let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
557 let c1x: f32 = 11.8;
558 let c1y: f32 = 12.4;
559 let r1: f32 = 8.2;
560 let c2x: f32 = 16.4;
561 let c2y: f32 = 8.2;
562 let r2: f32 = 6.6;
563 let dx: f32 = c2x - c1x;
564 let dy: f32 = c2y - c1y;
565 let dist: f32 = (dx * dx + dy * dy).sqrt();
566 let base_ang: f32 = dy.atan2(dx);
567 let a: f32 = (r1 * r1 - r2 * r2 + dist * dist) / (2.0 * dist);
568 let alpha1: f32 = (a / r1).clamp(-1.0, 1.0).acos();
569 let theta1_top: f32 = base_ang - alpha1;
570 let theta1_bot: f32 = base_ang + alpha1;
571 let theta1_end: f32 = theta1_top + 2.0 * PI;
572 let outer_steps: usize = 28;
573 let mut prev_outer: Point = Point::new(
574 ox + (c1x + r1 * theta1_bot.cos()) * u,
575 oy + (c1y + r1 * theta1_bot.sin()) * u,
576 );
577 for step in 1..=outer_steps {
578 let t: f32 = (step as f32) / (outer_steps as f32);
579 let ang: f32 = theta1_bot + (theta1_end - theta1_bot) * t;
580 let next_pt: Point = Point::new(
581 ox + (c1x + r1 * ang.cos()) * u,
582 oy + (c1y + r1 * ang.sin()) * u,
583 );
584 dl.push(DrawCommand::Line {
585 from: prev_outer,
586 to: next_pt,
587 color,
588 width: sw,
589 });
590 prev_outer = next_pt;
591 }
592 let p_top_x: f32 = c1x + r1 * theta1_top.cos();
593 let p_top_y: f32 = c1y + r1 * theta1_top.sin();
594 let p_bot_x: f32 = c1x + r1 * theta1_bot.cos();
595 let p_bot_y: f32 = c1y + r1 * theta1_bot.sin();
596 let mut theta2_top: f32 = (p_top_y - c2y).atan2(p_top_x - c2x);
597 let theta2_bot: f32 = (p_bot_y - c2y).atan2(p_bot_x - c2x);
598 if theta2_top < theta2_bot {
599 theta2_top += 2.0 * PI;
600 }
601 let inner_steps: usize = 18;
602 let mut prev_inner: Point = Point::new(ox + p_top_x * u, oy + p_top_y * u);
603 for step in 1..=inner_steps {
604 let t: f32 = (step as f32) / (inner_steps as f32);
605 let ang: f32 = theta2_top + (theta2_bot - theta2_top) * t;
606 let next_pt: Point = Point::new(
607 ox + (c2x + r2 * ang.cos()) * u,
608 oy + (c2y + r2 * ang.sin()) * u,
609 );
610 dl.push(DrawCommand::Line {
611 from: prev_inner,
612 to: next_pt,
613 color,
614 width: sw,
615 });
616 prev_inner = next_pt;
617 }
618 let tip_r: f32 = (sw * 0.48).max(0.45);
619 dl.push(DrawCommand::Circle {
620 center: Point::new(ox + p_top_x * u, oy + p_top_y * u),
621 radius: tip_r,
622 color,
623 });
624 dl.push(DrawCommand::Circle {
625 center: Point::new(ox + p_bot_x * u, oy + p_bot_y * u),
626 radius: tip_r,
627 color,
628 });
629 let star_x: f32 = ox + 17.8 * u;
630 let star_y: f32 = oy + 6.4 * u;
631 let star_arm: f32 = 2.1 * u;
632 let star_sw: f32 = (1.45 * u).clamp(1.05, 1.75);
633 push_rounded_stroke(
634 dl,
635 Point::new(star_x, star_y - star_arm),
636 Point::new(star_x, star_y + star_arm),
637 color,
638 star_sw,
639 );
640 push_rounded_stroke(
641 dl,
642 Point::new(star_x - star_arm, star_y),
643 Point::new(star_x + star_arm, star_y),
644 color,
645 star_sw,
646 );
647}
648
649pub(crate) fn draw_gear_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
657 let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
658 let cx: f32 = ox + 12.0 * u;
659 let cy: f32 = oy + 12.0 * u;
660 let teeth: f32 = 6.0;
661 let r_valley: f32 = 6.7 * u;
662 let r_crown: f32 = 9.4 * u;
663 let steepness: f32 = 2.6;
664 let norm: f32 = steepness.tanh();
665 let steps: usize = 72;
666 let start_ang: f32 = -PI * 0.5;
667 let step_ang: f32 = 2.0 * PI / (steps as f32);
668 let mut prev_pt: Point = Point::new(cx, cy - r_crown);
669 for idx in 1..=steps {
670 let ang: f32 = start_ang + ((idx % steps) as f32) * step_ang;
671 let wave: f32 = (teeth * (ang - start_ang)).cos();
672 let blend: f32 = 0.5 + 0.5 * ((steepness * wave).tanh() / norm);
673 let r: f32 = r_valley + (r_crown - r_valley) * blend;
674 let next_pt: Point = Point::new(cx + r * ang.cos(), cy + r * ang.sin());
675 dl.push(DrawCommand::Line {
676 from: prev_pt,
677 to: next_pt,
678 color,
679 width: sw,
680 });
681 prev_pt = next_pt;
682 }
683 let hole_r: f32 = 3.1 * u;
684 dl.push(DrawCommand::FillRoundedRect {
685 rect: Rect::new(cx - hole_r, cy - hole_r, hole_r * 2.0, hole_r * 2.0),
686 color: COLOR_TRANSPARENT,
687 radius: CornerRadius::all(RADIUS_PILL),
688 border: Border::new(sw, color),
689 });
690}
691
692pub(crate) fn mount_topbar_actions(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
703 let cmd_open: Signal<bool> = state.get_cmd_palette_open();
704 let st_mode: ShowcaseState = state.clone();
705 let route_sig: Signal<String> = state.get_route();
706 let icon_btn_style = move || -> Style {
707 let live_tok: ThemeTokens = use_live_tokens(tokens);
708 let live_p: ThemePalette = live_tok.get_palette();
709 let live_g: ThemeGeometry = live_tok.get_geometry();
710 Style::default()
711 .row()
712 .width(Length::Px(TOPBAR_CONTROL_SIZE))
713 .height(Length::Px(TOPBAR_CONTROL_SIZE))
714 .flex_shrink(0.0)
715 .justify(JustifyContent::Center)
716 .align(AlignItems::Center)
717 .background(live_p.get_background())
718 .border(live_g.get_border_width(), live_p.get_border())
719 .radius(live_g.get_radius_md())
720 .cursor(CursorIcon::Pointer)
721 };
722 let paint_search = move |bounds: Rect, dl: &mut DisplayList| {
723 let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
724 draw_topbar_search_icon(bounds, dl, live_p.get_foreground());
725 };
726 let paint_mode = move |bounds: Rect, dl: &mut DisplayList| {
727 let live_tok: ThemeTokens = live_tokens_untracked(tokens);
728 let fg: Color = live_tok.get_palette().get_foreground();
729 match live_tok.get_mode() {
730 ThemeMode::Dark => draw_theme_sun_icon(bounds, dl, fg),
731 ThemeMode::Light => draw_theme_moon_icon(bounds, dl, fg),
732 }
733 };
734 let paint_settings = move |bounds: Rect, dl: &mut DisplayList| {
735 let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
736 draw_gear_icon(bounds, dl, live_p.get_foreground());
737 };
738 let on_open_cmd = move |_: &UiEvent| {
739 let _: bool = cmd_open.set_if_changed(true);
740 };
741 let on_toggle_mode = move |_: &UiEvent| {
742 st_mode.toggle_theme_mode();
743 };
744 let on_open_settings = move |_: &UiEvent| {
745 let _: bool = route_sig.set_if_changed(ROUTE_SETTINGS.to_string());
746 };
747 view! {
748 row {
749 style: {
750 gap: SPACE_XS
751 align: AlignItems::Center
752 }
753 row {
754 bind_style: icon_btn_style
755 role: A11yRole::Button
756 a11y_label: BTN_SEARCH_A11Y.to_string()
757 on_click: on_open_cmd
758 canvas {
759 style: {
760 width: Length::Px(TOPBAR_ICON_SIZE)
761 height: Length::Px(TOPBAR_ICON_SIZE)
762 }
763 caching: CanvasCaching::RetainedStatic
764 painter: paint_search
765 }
766 }
767 row {
768 bind_style: icon_btn_style
769 role: A11yRole::Button
770 a11y_label: BTN_MODE_A11Y.to_string()
771 on_click: on_toggle_mode
772 canvas {
773 style: {
774 width: Length::Px(TOPBAR_ICON_SIZE)
775 height: Length::Px(TOPBAR_ICON_SIZE)
776 }
777 caching: CanvasCaching::RetainedStatic
778 painter: paint_mode
779 }
780 }
781 row {
782 bind_style: icon_btn_style
783 role: A11yRole::Button
784 a11y_label: BTN_SETTINGS_A11Y.to_string()
785 on_click: on_open_settings
786 canvas {
787 style: {
788 width: Length::Px(TOPBAR_ICON_SIZE)
789 height: Length::Px(TOPBAR_ICON_SIZE)
790 }
791 caching: CanvasCaching::RetainedStatic
792 painter: paint_settings
793 }
794 }
795 }
796 }
797}