euv-example 0.48.0

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

style! {
    pub(crate) c_full_col {
        FlexDirection::Column
        width: Length::Percent(100.0)
        height: Length::Percent(100.0)
    }
    pub(crate) c_action_row {
        FlexDirection::Row
        FlexWrap::Wrap
        AlignItems::Center
        width: Length::Percent(100.0)
        gap: SPACE_SM
    }
}

/// Resolves the adaptive column count for a fluid card grid from the live viewport width (1 column on compact phones, 2 on tablets/laptops, 3 on desktops, 4 on wide/ultrawide displays), capped at `max_cols`.
///
/// # Arguments
///
/// - `f32` - Live viewport width in logical pixels.
/// - `u16` - Maximum column count requested by the page section.
///
/// # Returns
///
/// - `u16` - Resolved column count in `1..=max_cols`.
pub(crate) fn responsive_grid_columns(viewport_w: f32, max_cols: u16) -> u16 {
    let fluid: u16 = if viewport_w < GRID_BP_TWO_COLS {
        1
    } else if viewport_w < GRID_BP_THREE_COLS {
        2
    } else if viewport_w < GRID_BP_FOUR_COLS {
        3
    } else {
        4
    };
    fluid.clamp(1, max_cols.max(1))
}

/// Mounts a fluid full-width card grid whose column count tracks the live viewport (see `responsive_grid_columns`) with uniform `SPACE_MD` gutters.
///
/// # Arguments
///
/// - `Vec<NodeId>` - Pre-mounted card children in reading order.
/// - `u16` - Maximum column count on wide/ultrawide displays.
///
/// # Returns
///
/// - `NodeId` - Mounted responsive grid container.
pub(crate) fn mount_responsive_grid(children: Vec<NodeId>, max_cols: u16) -> NodeId {
    let vp_sig: Signal<Size> = use_viewport_size();
    let grid_style = move || -> Style {
        let cols: u16 = responsive_grid_columns(vp_sig.get().get_width(), max_cols);
        Style::default()
            .grid(cols)
            .width(Length::Percent(100.0))
            .gap(SPACE_MD)
    };
    view! {
        grid {
            bind_style: grid_style
            ..children
        }
    }
}

/// Computes an adaptive studio viewport height from the live window height so 720p/800p laptops keep toolbars above the fold while 1080p/4K displays expand generously.
///
/// # Arguments
///
/// - `f32` - Live viewport height in logical pixels.
///
/// # Returns
///
/// - `f32` - Clamped studio canvas height in logical pixels.
pub(crate) fn adaptive_viewport_height(viewport_h: f32) -> f32 {
    (viewport_h - VIEWPORT_CHROME_RESERVE).clamp(VIEWPORT_MIN_HEIGHT, VIEWPORT_MAX_HEIGHT)
}

/// Mounts a wide studio workspace: the primary viewport (`main`) grows to fill the row while the inspector `rail` keeps a fixed comfortable width on wide screens, stacking cleanly into one full-width column on compact/tablet viewports.
///
/// # Arguments
///
/// - `NodeId` - Primary workspace node (canvas, table, preview).
/// - `NodeId` - Inspector / controls rail node.
///
/// # Returns
///
/// - `NodeId` - Mounted adaptive studio container.
pub(crate) fn mount_studio_layout(main: NodeId, rail: NodeId) -> NodeId {
    let vp_sig: Signal<Size> = use_viewport_size();
    let shell_style = move || -> Style {
        let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
        let base: Style = Style::default()
            .width(Length::Percent(100.0))
            .gap(SPACE_MD)
            .align(AlignItems::Start);
        if wide { base.row() } else { base.column() }
    };
    let main_style = move || -> Style {
        let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
        let base: Style = Style::default()
            .column()
            .gap(SPACE_MD)
            .min_width(Length::Px(0.0));
        if wide {
            base.flex_grow(1.0).flex_shrink(1.0)
        } else {
            base.width(Length::Percent(100.0))
        }
    };
    let rail_style = move || -> Style {
        let wide: bool = vp_sig.get().get_width() >= GRID_BP_STUDIO_SPLIT;
        let base: Style = Style::default().column().gap(SPACE_MD).flex_shrink(0.0);
        if wide {
            base.width(Length::Px(STUDIO_RAIL_WIDTH))
        } else {
            base.width(Length::Percent(100.0))
        }
    };
    view! {
        view {
            bind_style: shell_style
            column {
                bind_style: main_style
                { main }
            }
            column {
                bind_style: rail_style
                { rail }
            }
        }
    }
}