Skip to main content

euv_example/pages/overview/
fn.rs

1use super::*;
2
3/// Mounts one contrast-safe quick-launch tile for a single `ShowcaseRouteSpec`.
4///
5/// # Arguments
6///
7/// - `&ShowcaseRouteSpec` - Route metadata entry.
8/// - `Signal<String>` - Active route signal mutated on click.
9/// - `ThemeTokens` - Design tokens at mount time.
10///
11/// # Returns
12///
13/// - `NodeId` - Mounted interactive quick-launch tile node.
14pub(crate) fn mount_overview_route_tile(
15    spec: &ShowcaseRouteSpec,
16    route_sig: Signal<String>,
17    tokens: ThemeTokens,
18) -> NodeId {
19    let target: String = spec.get_path().to_string();
20    let badge_txt: String = spec.get_tag().to_string();
21    let title_txt: String = spec.get_label().to_string();
22    let desc_txt: String = spec.get_summary().to_string();
23    let on_dir_click = move |_: &UiEvent| {
24        let _: bool = route_sig.set_if_changed(target.clone());
25    };
26    let tile_style = move || -> Style {
27        let live: ThemeTokens = use_live_tokens(tokens);
28        let live_p: ThemePalette = live.get_palette();
29        let live_g: ThemeGeometry = live.get_geometry();
30        Style::default()
31            .row()
32            .width(Length::Percent(100.0))
33            .padding(Edges::symmetric(SPACE_SM, SPACE_MD))
34            .align(AlignItems::Center)
35            .justify(JustifyContent::SpaceBetween)
36            .gap(SPACE_SM)
37            .overflow(Overflow::Hidden)
38            .radius(live_g.get_radius_md())
39            .background(live_p.get_background())
40            .border(live_g.get_border_width(), live_p.get_border())
41            .cursor(CursorIcon::Pointer)
42    };
43    let badge_box_style = move || -> Style {
44        let live: ThemeTokens = use_live_tokens(tokens);
45        let live_p: ThemePalette = live.get_palette();
46        Style::default()
47            .row()
48            .width(Length::Px(OVERVIEW_TAG_BADGE_SIZE))
49            .height(Length::Px(OVERVIEW_TAG_BADGE_SIZE))
50            .flex_shrink(0.0)
51            .radius(OVERVIEW_PILL_RADIUS)
52            .background(live_p.get_primary())
53            .justify(JustifyContent::Center)
54            .align(AlignItems::Center)
55    };
56    let badge_text_style = move || -> Style {
57        let live: ThemeTokens = use_live_tokens(tokens);
58        let live_p: ThemePalette = live.get_palette();
59        Style::default()
60            .font_size(11.5)
61            .font_family(FontFamily::Monospace)
62            .font_weight(FontWeight::Bold)
63            .color(live_p.get_primary_foreground())
64            .text_align(TextAlign::Center)
65            .text_overflow(TextOverflow::Clip)
66    };
67    let title_style = move || -> Style {
68        let live: ThemeTokens = use_live_tokens(tokens);
69        let live_p: ThemePalette = live.get_palette();
70        Style::default()
71            .width(Length::Percent(100.0))
72            .font_size(14.0)
73            .font_weight(FontWeight::SemiBold)
74            .color(live_p.get_foreground())
75            .overflow(Overflow::Hidden)
76            .text_overflow(TextOverflow::Ellipsis)
77    };
78    let desc_style = move || -> Style {
79        let live: ThemeTokens = use_live_tokens(tokens);
80        let live_p: ThemePalette = live.get_palette();
81        Style::default()
82            .width(Length::Percent(100.0))
83            .font_size(12.0)
84            .color(live_p.get_muted_foreground())
85            .overflow(Overflow::Hidden)
86            .text_overflow(TextOverflow::Ellipsis)
87    };
88    let arrow_style = move || -> Style {
89        let live: ThemeTokens = use_live_tokens(tokens);
90        let live_p: ThemePalette = live.get_palette();
91        Style::default()
92            .flex_shrink(0.0)
93            .font_size(14.0)
94            .font_weight(FontWeight::Bold)
95            .color(live_p.get_muted_foreground())
96            .text_overflow(TextOverflow::Clip)
97    };
98    view! {
99        row {
100            bind_style: tile_style
101            on_click: on_dir_click
102            row {
103                style: {
104                    flex_grow: 1.0
105                    flex_shrink: 1.0
106                    min_width: Length::Px(0.0)
107                    align: AlignItems::Center
108                    gap: SPACE_SM
109                    overflow: Overflow::Hidden
110                }
111                row {
112                    bind_style: badge_box_style
113                    text {
114                        bind_style: badge_text_style
115                        { badge_txt }
116                    }
117                }
118                column {
119                    style: {
120                        flex_grow: 1.0
121                        flex_shrink: 1.0
122                        min_width: Length::Px(0.0)
123                        gap: SPACE_XS
124                        overflow: Overflow::Hidden
125                    }
126                    text {
127                        bind_style: title_style
128                        { title_txt }
129                    }
130                    text {
131                        bind_style: desc_style
132                        { desc_txt }
133                    }
134                }
135            }
136            text {
137                bind_style: arrow_style
138                { HOME_DIR_ARROW }
139            }
140        }
141    }
142}
143
144/// Mounts a single categorized section block inside the overview quick-launch directory.
145///
146/// # Arguments
147///
148/// - `&'static str` - Section heading matching `ShowcaseRouteSpec::section`.
149/// - `Signal<String>` - Active route signal mutated on tile click.
150/// - `ThemeTokens` - Design tokens at mount time.
151///
152/// # Returns
153///
154/// - `Option<NodeId>` - Mounted section block, or `None` when the section has no non-overview routes.
155pub(crate) fn mount_overview_section_block(
156    section: &'static str,
157    route_sig: Signal<String>,
158    tokens: ThemeTokens,
159) -> Option<NodeId> {
160    let tiles: Vec<NodeId> = SHOWCASE_ROUTES
161        .iter()
162        .filter(|spec: &&ShowcaseRouteSpec| {
163            spec.get_section() == section && spec.get_path() != ROUTE_OVERVIEW
164        })
165        .map(|spec: &ShowcaseRouteSpec| mount_overview_route_tile(spec, route_sig, tokens))
166        .collect();
167    if tiles.is_empty() {
168        return None;
169    }
170    let count_badge: String = format!("{}", tiles.len());
171    let grid_node: NodeId = mount_responsive_grid(tiles, 4);
172    let header_style = move || -> Style {
173        let live: ThemeTokens = use_live_tokens(tokens);
174        Style::default()
175            .font_size(11.5)
176            .font_weight(FontWeight::Bold)
177            .color(live.get_palette().get_muted_foreground())
178    };
179    Some(view! {
180        column {
181            style: {
182                width: Length::Percent(100.0)
183                gap: SPACE_SM
184            }
185            row {
186                style: {
187                    width: Length::Percent(100.0)
188                    align: AlignItems::Center
189                    gap: SPACE_SM
190                }
191                text {
192                    bind_style: header_style
193                    { section }
194                }
195                EuvBadge {
196                    label: count_badge
197                    tone: EuvTone::Neutral
198                    tokens: tokens
199                }
200            }
201            { grid_node }
202        }
203    })
204}
205
206/// Mounts a concise runtime KPI card with reactive value text and contrast-safe surface tokens.
207///
208/// # Arguments
209///
210/// - `&str` - Upper KPI label.
211/// - `String` - Static caption text.
212/// - `NodeId` - Mounted value text node.
213/// - `ThemeTokens` - Design tokens at mount time.
214///
215/// # Returns
216///
217/// - `NodeId` - Mounted KPI card node.
218pub(crate) fn mount_overview_kpi_card(
219    label: &str,
220    caption: String,
221    value_node: NodeId,
222    tokens: ThemeTokens,
223) -> NodeId {
224    let label_txt: String = label.to_string();
225    let card_style = move || -> Style {
226        let live: ThemeTokens = use_live_tokens(tokens);
227        let live_p: ThemePalette = live.get_palette();
228        let live_g: ThemeGeometry = live.get_geometry();
229        Style::default()
230            .column()
231            .width(Length::Percent(100.0))
232            .padding(Edges::all(SPACE_MD))
233            .gap(SPACE_XS)
234            .overflow(Overflow::Hidden)
235            .background(live_p.get_card())
236            .border(live_g.get_border_width(), live_p.get_border())
237            .radius(live_g.get_radius_lg())
238    };
239    let label_style = move || -> Style {
240        let live: ThemeTokens = use_live_tokens(tokens);
241        Style::default()
242            .width(Length::Percent(100.0))
243            .font_size(12.0)
244            .font_weight(FontWeight::Medium)
245            .color(live.get_palette().get_muted_foreground())
246    };
247    let cap_style = move || -> Style {
248        let live: ThemeTokens = use_live_tokens(tokens);
249        Style::default()
250            .width(Length::Percent(100.0))
251            .font_size(12.0)
252            .color(live.get_palette().get_muted_foreground())
253    };
254    view! {
255        column {
256            bind_style: card_style
257            text {
258                bind_style: label_style
259                { label_txt }
260            }
261            { value_node }
262            text {
263                bind_style: cap_style
264                { caption }
265            }
266        }
267    }
268}
269
270/// Mounts the executive Overview landing page with `euv.png` brand hero, live runtime KPI strip, categorized quick-launch cards, and framework highlights.
271///
272/// # Arguments
273///
274/// - `&ShowcaseState` - Reactive showcase state.
275/// - `ThemeTokens` - Active design tokens.
276///
277/// # Returns
278///
279/// - `NodeId` - Mounted overview page node.
280pub fn mount_overview_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
281    let route_sig: Signal<String> = state.get_route();
282    let scheme_sig: Signal<DesignScheme> = state.get_theme().get_scheme();
283    let mode_sig: Signal<ThemeMode> = state.get_theme().get_mode();
284    let hero_style = move || -> Style {
285        let live: ThemeTokens = use_live_tokens(tokens);
286        let live_p: ThemePalette = live.get_palette();
287        let live_g: ThemeGeometry = live.get_geometry();
288        Style::default()
289            .column()
290            .overflow(Overflow::Hidden)
291            .width(Length::Percent(100.0))
292            .padding(Edges::all(SPACE_XL))
293            .gap(SPACE_MD)
294            .background(live_p.get_card())
295            .border(
296                live_g.get_border_width().max(1.0),
297                live_p.get_primary().with_alpha(96),
298            )
299            .radius(live_g.get_radius_xl())
300            .shadow(live_g.get_shadow_sm())
301    };
302    let headline_style = move || -> Style {
303        let live: ThemeTokens = use_live_tokens(tokens);
304        Style::default()
305            .width(Length::Percent(100.0))
306            .font_size(20.0)
307            .font_weight(FontWeight::Bold)
308            .color(live.get_palette().get_card_foreground())
309    };
310    let hero_desc_style = move || -> Style {
311        let live: ThemeTokens = use_live_tokens(tokens);
312        Style::default()
313            .width(Length::Percent(100.0))
314            .font_size(13.5)
315            .color(live.get_palette().get_muted_foreground())
316    };
317    let kpi_val_style = move || -> Style {
318        let live: ThemeTokens = use_live_tokens(tokens);
319        Style::default()
320            .width(Length::Percent(100.0))
321            .font_size(17.0)
322            .font_weight(FontWeight::Bold)
323            .color(live.get_palette().get_card_foreground())
324    };
325    let theme_kpi_text = move || -> String {
326        let scheme: DesignScheme = scheme_sig.get();
327        let mode: ThemeMode = mode_sig.get();
328        format!("{} ({mode:?})", scheme.as_str())
329    };
330    let theme_val_node: NodeId = view! {
331        text {
332            bind_style: kpi_val_style
333            { theme_kpi_text }
334        }
335    };
336    let render_val_node: NodeId = view! {
337        text {
338            bind_style: kpi_val_style
339            { KPI_RENDER_VAL }
340        }
341    };
342    let modules_val: String = format!("{} Routes", SHOWCASE_ROUTES.len());
343    let modules_val_node: NodeId = view! {
344        text {
345            bind_style: kpi_val_style
346            { modules_val }
347        }
348    };
349    let targets_val_node: NodeId = view! {
350        text {
351            bind_style: kpi_val_style
352            { KPI_TARGETS_VAL }
353        }
354    };
355    let kpi_cards: Vec<NodeId> = vec![
356        mount_overview_kpi_card(
357            KPI_THEME_LABEL,
358            KPI_THEME_CAP.to_string(),
359            theme_val_node,
360            tokens,
361        ),
362        mount_overview_kpi_card(
363            KPI_RENDER_LABEL,
364            KPI_RENDER_CAP.to_string(),
365            render_val_node,
366            tokens,
367        ),
368        mount_overview_kpi_card(
369            KPI_MODULES_LABEL,
370            KPI_MODULES_CAP.to_string(),
371            modules_val_node,
372            tokens,
373        ),
374        mount_overview_kpi_card(
375            KPI_TARGETS_LABEL,
376            KPI_TARGETS_CAP.to_string(),
377            targets_val_node,
378            tokens,
379        ),
380    ];
381    let kpi_strip: NodeId = mount_responsive_grid(kpi_cards, 4);
382    let sections: [&'static str; 5] = [
383        NAV_SEC_CONTENT,
384        NAV_SEC_COMPONENTS,
385        NAV_SEC_PLATFORM,
386        NAV_SEC_ENGINES,
387        NAV_SEC_START,
388    ];
389    let section_blocks: Vec<NodeId> = sections
390        .iter()
391        .filter_map(|sec: &&'static str| mount_overview_section_block(sec, route_sig, tokens))
392        .collect();
393    let highlight_cards: Vec<NodeId> = HIGHLIGHT_TITLES
394        .iter()
395        .zip(HIGHLIGHT_BODIES.iter())
396        .map(|(title, body): (&&str, &&str)| {
397            let title_str: String = (*title).to_string();
398            let body_str: String = (*body).to_string();
399            let body_style = move || -> Style {
400                let live: ThemeTokens = use_live_tokens(tokens);
401                Style::default()
402                    .width(Length::Percent(100.0))
403                    .font_size(13.0)
404                    .color(live.get_palette().get_muted_foreground())
405            };
406            view! {
407                EuvCard {
408                    title: title_str
409                    tokens: tokens
410                    text {
411                        bind_style: body_style
412                        { body_str }
413                    }
414                }
415            }
416        })
417        .collect();
418    let highlight_grid: NodeId = mount_responsive_grid(highlight_cards, 3);
419    let on_open_charts = move |_: &UiEvent| {
420        let _: bool = route_sig.set_if_changed(ROUTE_CHARTS.to_string());
421    };
422    let on_open_markdown = move |_: &UiEvent| {
423        let _: bool = route_sig.set_if_changed(ROUTE_MARKDOWN.to_string());
424    };
425    let on_open_3d = move |_: &UiEvent| {
426        let _: bool = route_sig.set_if_changed(ROUTE_GAME_3D.to_string());
427    };
428    let on_open_water = move |_: &UiEvent| {
429        let _: bool = route_sig.set_if_changed(ROUTE_WATER.to_string());
430    };
431    let on_open_stress = move |_: &UiEvent| {
432        let _: bool = route_sig.set_if_changed(ROUTE_STRESS.to_string());
433    };
434    let on_open_themes = move |_: &UiEvent| {
435        let _: bool = route_sig.set_if_changed(ROUTE_THEMES.to_string());
436    };
437    let hero_brand_logo: ImageBuffer = euv_brand_logo_image();
438    view! {
439        EuvPage {
440            title: OVERVIEW_TITLE.to_string()
441            subtitle: OVERVIEW_SUBTITLE.to_string()
442            tokens: tokens
443            view {
444                bind_style: hero_style
445                row {
446                    style: {
447                        width: Length::Percent(100.0)
448                        align: AlignItems::Center
449                        gap: SPACE_MD
450                    }
451                    image {
452                        source: hero_brand_logo
453                        style: {
454                            width: Length::Px(OVERVIEW_LOGO_SIZE)
455                            height: Length::Px(OVERVIEW_LOGO_SIZE)
456                            flex_shrink: 0.0
457                        }
458                    }
459                    column {
460                        style: {
461                            flex_grow: 1.0
462                            flex_shrink: 1.0
463                            min_width: Length::Px(0.0)
464                            gap: SPACE_XS
465                            overflow: Overflow::Hidden
466                        }
467                        row {
468                            style: {
469                                width: Length::Percent(100.0)
470                                flex_wrap: FlexWrap::Wrap
471                                align: AlignItems::Center
472                                gap: SPACE_XS
473                            }
474                            EuvBadge {
475                                label: HERO_BADGE_VER.to_string()
476                                tone: EuvTone::Primary
477                                tokens: tokens
478                            }
479                            EuvBadge {
480                                label: HERO_BADGE_ZERO_WV.to_string()
481                                tone: EuvTone::Success
482                                tokens: tokens
483                            }
484                            EuvBadge {
485                                label: HERO_BADGE_TARGETS.to_string()
486                                tone: EuvTone::Neutral
487                                tokens: tokens
488                            }
489                            EuvBadge {
490                                label: HERO_BADGE_FREEZE.to_string()
491                                tone: EuvTone::Warning
492                                tokens: tokens
493                            }
494                        }
495                        text {
496                            bind_style: headline_style
497                            { HERO_HEADLINE }
498                        }
499                    }
500                }
501                text {
502                    bind_style: hero_desc_style
503                    { HERO_DESCRIPTION }
504                }
505                EuvActionRow {
506                    EuvButton {
507                        label: BTN_OPEN_CHARTS.to_string()
508                        tokens: tokens
509                        sm()
510                        on_click: on_open_charts
511                    }
512                    EuvButton {
513                        label: BTN_OPEN_MARKDOWN.to_string()
514                        tokens: tokens
515                        secondary()
516                        sm()
517                        on_click: on_open_markdown
518                    }
519                    EuvButton {
520                        label: BTN_OPEN_3D_RT.to_string()
521                        tokens: tokens
522                        secondary()
523                        sm()
524                        on_click: on_open_3d
525                    }
526                    EuvButton {
527                        label: BTN_OPEN_WATER.to_string()
528                        tokens: tokens
529                        secondary()
530                        sm()
531                        on_click: on_open_water
532                    }
533                    EuvButton {
534                        label: BTN_OPEN_STRESS_LAB.to_string()
535                        tokens: tokens
536                        outline()
537                        sm()
538                        on_click: on_open_stress
539                    }
540                    EuvButton {
541                        label: BTN_OPEN_THEMES.to_string()
542                        tokens: tokens
543                        outline()
544                        sm()
545                        on_click: on_open_themes
546                    }
547                }
548            }
549            { kpi_strip }
550            EuvCard {
551                title: HOME_DIR_TITLE.to_string()
552                tokens: tokens
553                subtitle: HOME_DIR_SUBTITLE
554                column {
555                    style: {
556                        width: Length::Percent(100.0)
557                        gap: SPACE_LG
558                    }
559                    ..section_blocks
560                }
561            }
562            EuvCard {
563                title: HIGHLIGHTS_TITLE.to_string()
564                tokens: tokens
565                subtitle: HIGHLIGHTS_SUBTITLE
566                { highlight_grid }
567            }
568        }
569    }
570}