Skip to main content

euv_example/pages/media/
fn.rs

1use super::*;
2
3/// Mounts the complete cross-platform Media Studio page demonstrating Image, SVG, GIF, LIVE Photo, Video, Audio, PDF, and native HTML5 in a fluid responsive grid.
4///
5/// # Arguments
6///
7/// - `&ShowcaseState` - Reactive showcase state.
8/// - `ThemeTokens` - Active design tokens.
9///
10/// # Returns
11///
12/// - `NodeId` - Mounted Media Studio page node.
13pub fn mount_media_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14    state.ensure_media_loaded();
15    let link_log: Signal<String> = state.get_media_html_link_log();
16    let media_loading: Signal<bool> = state.get_media_loading();
17    let link_log_cb: Signal<String> = link_log;
18    let media_status_text = move || -> String {
19        if media_loading.get() {
20            MEDIA_LOADING_STATUS.to_string()
21        } else {
22            MEDIA_READY_STATUS.to_string()
23        }
24    };
25    let link_log_text = move || -> String { link_log.get() };
26    let status_style = move || -> Style {
27        let live: ThemeTokens = use_live_tokens(tokens);
28        Style::default()
29            .width(Length::Percent(100.0))
30            .font_size(12.5)
31            .font_weight(FontWeight::Medium)
32            .color(live.get_palette().get_primary())
33    };
34    let link_style = move || -> Style {
35        let live: ThemeTokens = use_live_tokens(tokens);
36        Style::default()
37            .width(Length::Percent(100.0))
38            .font_size(12.0)
39            .font_family(FontFamily::Monospace)
40            .color(live.get_palette().get_muted_foreground())
41    };
42    let on_html_link = move |href: String| {
43        let _: bool = link_log_cb.set_if_changed(format!("Opened native link: {href}"));
44    };
45    let media_cards: Vec<NodeId> = vec![
46        view! {
47            EuvImage {
48                asset: ImageAsset::sample_photo(MEDIA_PHOTO_LABEL)
49                tokens: tokens
50                style: {
51                    height: Length::Px(MEDIA_PHOTO_HEIGHT)
52                }
53            }
54        },
55        view! {
56            EuvSvgView {
57                document: SvgDocument::sample_svg()
58                label: MEDIA_SVG_LABEL.to_string()
59                tokens: tokens
60            }
61        },
62        view! {
63            EuvGifPlayer {
64                state: state.get_media_gif()
65                tokens: tokens
66            }
67        },
68        view! {
69            EuvLivePhoto {
70                state: state.get_media_live()
71                tokens: tokens
72            }
73        },
74        view! {
75            EuvVideoPlayer {
76                state: state.get_media_video()
77                tokens: tokens
78            }
79        },
80        view! {
81            EuvAudioPlayer {
82                state: state.get_media_audio()
83                tokens: tokens
84            }
85        },
86        view! {
87            EuvPdfViewer {
88                state: state.get_media_pdf()
89                tokens: tokens
90            }
91        },
92        view! {
93            EuvHtmlView {
94                document: HtmlDocument::sample_html()
95                tokens: tokens
96                on_link: on_html_link
97            }
98        },
99    ];
100    let media_grid: NodeId = mount_responsive_grid(media_cards, MEDIA_GRID_MAX_COLS);
101    view! {
102        EuvPage {
103            title: MEDIA_PAGE_TITLE.to_string()
104            subtitle: MEDIA_PAGE_SUBTITLE.to_string()
105            tokens: tokens
106            EuvCard {
107                title: MEDIA_STATUS_CARD_TITLE.to_string()
108                tokens: tokens
109                subtitle: MEDIA_STATUS_CARD_SUB
110                text {
111                    bind_style: status_style
112                    { media_status_text }
113                }
114                text {
115                    bind_style: link_style
116                    { link_log_text }
117                }
118            }
119            { media_grid }
120        }
121    }
122}