euv-example 0.49.1

Cross-platform native showcase application demonstrating euv fine-grained reactivity, multi-mode rendering, window controls, and euv-ui components.
Documentation
use super::*;

/// 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.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted Media Studio page node.
pub fn mount_media_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    state.ensure_media_loaded();
    let link_log: Signal<String> = state.get_media_html_link_log();
    let media_loading: Signal<bool> = state.get_media_loading();
    let link_log_cb: Signal<String> = link_log;
    let media_status_text = move || -> String {
        if media_loading.get() {
            MEDIA_LOADING_STATUS.to_string()
        } else {
            MEDIA_READY_STATUS.to_string()
        }
    };
    let link_log_text = move || -> String { link_log.get() };
    let status_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        style! {
            Width(Length::Percent(100.0))
            FontSize(12.5)
            FontWeight::Medium
            TextColor(live.get_palette().get_primary())
        }
    };
    let link_style = move || -> Style {
        let live: ThemeTokens = use_live_tokens(tokens);
        style! {
            Width(Length::Percent(100.0))
            FontSize(12.0)
            FontFamily::Monospace
            TextColor(live.get_palette().get_muted_foreground())
        }
    };
    let on_html_link = move |href: String| {
        let _: bool = open_external_url(&href);
        let _: bool = link_log_cb.set_if_changed(format!("Opened native link: {href}"));
    };
    let media_cards: Vec<NodeId> = vec![
        {
            let euv_image_style: Style = style! {
                Height(Length::Px(MEDIA_PHOTO_HEIGHT))
            };
            view! {
                EuvImage {
                    asset: ImageAsset::sample_photo(MEDIA_PHOTO_LABEL)
                    tokens: tokens
                    style: euv_image_style
                }
            }
        },
        view! {
            EuvSvgView {
                document: SvgDocument::sample_svg()
                label: MEDIA_SVG_LABEL.to_string()
                tokens: tokens
            }
        },
        view! {
            EuvGifPlayer {
                state: state.get_media_gif()
                tokens: tokens
            }
        },
        view! {
            EuvLivePhoto {
                state: state.get_media_live()
                tokens: tokens
            }
        },
        view! {
            EuvVideoPlayer {
                state: state.get_media_video()
                tokens: tokens
            }
        },
        view! {
            EuvAudioPlayer {
                state: state.get_media_audio()
                tokens: tokens
            }
        },
        view! {
            EuvPdfViewer {
                state: state.get_media_pdf()
                tokens: tokens
            }
        },
        view! {
            EuvHtmlView {
                document: HtmlDocument::sample_html()
                tokens: tokens
                on_link: on_html_link
            }
        },
    ];
    let media_grid: NodeId = mount_responsive_grid(media_cards, MEDIA_GRID_MAX_COLS);
    view! {
        EuvPage {
            title: MEDIA_PAGE_TITLE.to_string()
            subtitle: MEDIA_PAGE_SUBTITLE.to_string()
            tokens: tokens
            EuvCard {
                title: MEDIA_STATUS_CARD_TITLE.to_string()
                tokens: tokens
                subtitle: MEDIA_STATUS_CARD_SUB
                text {
                    bind_style: status_style
                    { media_status_text }
                }
                text {
                    bind_style: link_style
                    { link_log_text }
                }
            }
            { media_grid }
        }
    }
}