euv-ui 0.48.10

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
use super::*;

/// Computes the usable vertical `(top, bottom)` span inside a left or right hardware safe-area strip after excluding OS signal clusters and the physical camera punch hole.
///
/// # Arguments
///
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Logical viewport height in dp.
/// - `SafeAreaInsets` - Hardware safe-area insets.
/// - `bool` - `true` when docking on the right safe-area strip, `false` for the left strip.
///
/// # Returns
///
/// - `(f32, f32)` - Usable `(usable_top, usable_bottom)` Y bounds in logical dp.
#[must_use]
pub fn compute_side_rail_vertical_bounds(
    vp_w: f32,
    vp_h: f32,
    safe: SafeAreaInsets,
    is_right: bool,
) -> (f32, f32) {
    let base_top: f32 = safe.get_top().max(0.0);
    let is_landscape: bool = vp_w > vp_h;
    if is_right && !is_landscape {
        let usable_top: f32 = base_top.max(CHROME_SIDE_RAIL_SIGNAL_CLEARANCE_PORTRAIT);
        return (usable_top, vp_h.max(usable_top + 160.0));
    }
    if is_landscape && vp_h < 600.0 {
        if is_right {
            let usable_top: f32 = base_top.max(CHROME_SIDE_RAIL_EDGE_INSET);
            let usable_bottom: f32 =
                (vp_h - CHROME_SIDE_RAIL_CAMERA_CLEARANCE).max(usable_top + 160.0);
            return (usable_top, usable_bottom);
        }
        let usable_top: f32 = base_top.max(CHROME_SIDE_RAIL_CAMERA_CLEARANCE);
        let usable_bottom: f32 = (vp_h - CHROME_SIDE_RAIL_EDGE_INSET).max(usable_top + 160.0);
        return (usable_top, usable_bottom);
    }
    let usable_top: f32 = base_top.max(CHROME_SIDE_RAIL_SIGNAL_CLEARANCE_PORTRAIT);
    let usable_bottom: f32 = (vp_h - CHROME_SIDE_RAIL_CAMERA_CLEARANCE).max(usable_top + 160.0);
    (usable_top, usable_bottom)
}

/// Computes the top vertical clearance inside a right hardware safe-area strip so vertical navigation never overlaps OS camera, clock, or signal indicators.
///
/// # Arguments
///
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Logical viewport height in dp.
/// - `SafeAreaInsets` - Hardware safe-area insets.
///
/// # Returns
///
/// - `f32` - Top Y clearance in logical dp inside the right safe-area rail.
#[must_use]
pub fn compute_side_rail_signal_clearance(vp_w: f32, vp_h: f32, safe: SafeAreaInsets) -> f32 {
    compute_side_rail_vertical_bounds(vp_w, vp_h, safe, true).0
}

/// Computes the header height and inner padding when hosting the page top bar directly inside a tall top hardware safe-area strip while tightly avoiding the top-right hardware cutout/signal region.
///
/// # Arguments
///
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Raw top safe-area height in dp.
/// - `f32` - Raw left safe-area inset in dp.
/// - `f32` - Raw right safe-area inset in dp.
///
/// # Returns
///
/// - `(f32, Edges)` - Resolved `(header_height, header_padding)`.
#[must_use]
pub(crate) fn resolve_top_safe_header(
    vp_w: f32,
    top_raw: f32,
    left_raw: f32,
    right_raw: f32,
) -> (f32, Edges) {
    let pad_bottom: f32 = ((top_raw - SHELL_TOPBAR_CONTROL_HEIGHT) * 0.36).clamp(14.0, 20.0);
    let pad_top: f32 = (top_raw - SHELL_TOPBAR_CONTROL_HEIGHT - pad_bottom).max(0.0);
    let pad_left: f32 = left_raw + CHROME_TOP_SAFE_LEFT_CORNER_PAD;
    let desired_right: f32 = CHROME_TOP_SAFE_RIGHT_AVOIDANCE;
    let max_right: f32 = (vp_w - pad_left - CHROME_TOP_SAFE_MIN_CONTENT_WIDTH)
        .max(CHROME_TOP_SAFE_MIN_RIGHT_AVOIDANCE);
    let pad_right: f32 = right_raw.max(desired_right.min(max_right));
    (
        top_raw,
        Edges::new(pad_top, pad_right, pad_bottom, pad_left),
    )
}

/// Computes curved-display horizontal corner clearance for top headers on hardware-safe-area viewports (landscape, split-screen panes, and shallow top-inset devices) so top-left logos and top-right buttons never clip against `55..59dp` display or Split View corners.
///
/// Returns `0.0` on rectangular desktops/web (`safe == 0`), smartwatches (`< 300dp`), and tall-notch/Dynamic-Island portrait phones (`safe.top >= 44dp`) where controls already sit cleanly below the display corner curve.
///
/// # Arguments
///
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Logical viewport height in dp.
/// - `SafeAreaInsets` - Hardware safe-area insets.
///
/// # Returns
///
/// - `f32` - Horizontal corner clearance in logical dp (`0.0` when controls are outside curved corners).
#[must_use]
pub(crate) fn resolve_curved_corner_header_inset(
    vp_w: f32,
    vp_h: f32,
    safe: SafeAreaInsets,
) -> f32 {
    let top_raw: f32 = safe.get_top().max(0.0);
    let has_hw_safe: bool = top_raw
        .max(safe.get_right().max(0.0))
        .max(safe.get_bottom().max(0.0))
        .max(safe.get_left().max(0.0))
        > 0.5;
    if !has_hw_safe || vp_w.min(vp_h) < CHROME_WATCH_VIEWPORT_MAX {
        return 0.0;
    }
    if top_raw <= 0.5 {
        return if vp_w > vp_h {
            CHROME_LANDSCAPE_CORNER_H_PAD
        } else {
            CHROME_SPLIT_CORNER_H_PAD
        };
    }
    if top_raw >= CHROME_CORNER_CLEAR_TOP_THRESHOLD {
        return 0.0;
    }
    let y_top: f32 = top_raw + SHELL_TOPBAR_SAFE_TOP_GAP;
    let dy: f32 = (CHROME_DISPLAY_CORNER_RADIUS - y_top).max(0.0);
    let chord_x: f32 = CHROME_DISPLAY_CORNER_RADIUS
        - (CHROME_DISPLAY_CORNER_RADIUS * CHROME_DISPLAY_CORNER_RADIUS - dy * dy)
            .max(0.0)
            .sqrt();
    (chord_x + CHROME_CORNER_BREATHING_GAP)
        .clamp(CHROME_SPLIT_CORNER_MIN_H_PAD, CHROME_LANDSCAPE_CORNER_H_PAD)
}

/// Computes the canonical mobile header height and inner padding for standard postures where the top bar sits below any top safe inset.
///
/// # Arguments
///
/// - `f32` - Effective top safe inset in dp.
/// - `f32` - Left safe inset in dp.
/// - `f32` - Right safe inset in dp.
/// - `f32` - Curved-corner horizontal clearance in dp (`> 0` on curved-bezel landscape and split-screen viewports).
///
/// # Returns
///
/// - `(f32, Edges)` - Resolved `(header_height, header_padding)`.
#[must_use]
pub(crate) fn resolve_standard_mobile_header(
    eff_top_inset: f32,
    left_inset: f32,
    right_inset: f32,
    corner_h: f32,
) -> (f32, Edges) {
    let safe_bar_content_h: f32 =
        SHELL_TOPBAR_CONTROL_HEIGHT + SHELL_TOPBAR_SAFE_TOP_GAP + SHELL_TOPBAR_SAFE_BOTTOM_GAP;
    if eff_top_inset > 0.0 {
        return (
            eff_top_inset + safe_bar_content_h,
            Edges::new(
                eff_top_inset + SHELL_TOPBAR_SAFE_TOP_GAP,
                (SPACE_SM + right_inset).max(corner_h),
                SHELL_TOPBAR_SAFE_BOTTOM_GAP,
                (SPACE_SM + left_inset).max(corner_h),
            ),
        );
    }
    if corner_h > 0.0 {
        let bar_h: f32 = CHROME_LANDSCAPE_CORNER_TOP_PAD
            + SHELL_TOPBAR_CONTROL_HEIGHT
            + SHELL_TOPBAR_SAFE_BOTTOM_GAP;
        return (
            bar_h,
            Edges::new(
                CHROME_LANDSCAPE_CORNER_TOP_PAD,
                (SPACE_SM + right_inset).max(corner_h),
                SHELL_TOPBAR_SAFE_BOTTOM_GAP,
                (SPACE_SM + left_inset).max(corner_h),
            ),
        );
    }
    (
        MOBILE_HEADER_HEIGHT,
        Edges::new(0.0, SPACE_SM + right_inset, 0.0, SPACE_SM + left_inset),
    )
}

/// Computes canonical floating horizontal bottom-dock coordinates shared by standard mobile and top-safe postures.
///
/// # Arguments
///
/// - `&ShellViewportMetrics` - Live viewport, safe-area, and chrome visibility snapshot.
/// - `bool` - Whether the bottom dock is visible in this frame.
///
/// # Returns
///
/// - `BottomFloatingDockBox` - Floating bottom dock frame and content bottom scroll padding.
#[must_use]
pub(crate) fn resolve_bottom_floating_dock_box(
    metrics: &ShellViewportMetrics,
    show_dock: bool,
) -> BottomFloatingDockBox {
    let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
    let safe: SafeAreaInsets = metrics.get_safe_area();
    let right_raw: f32 = safe.get_right().max(0.0);
    let bottom_raw: f32 = safe.get_bottom().max(0.0);
    let left_raw: f32 = safe.get_left().max(0.0);
    let float_gap: f32 = if metrics.get_is_compact_bp() {
        SHELL_BOTTOM_NAV_FLOAT_COMPACT
    } else {
        SHELL_BOTTOM_NAV_FLOAT_WIDE
    };
    let dock_h: f32 = SHELL_BOTTOM_NAV_HEIGHT;
    let dock_bottom: f32 = float_gap + bottom_raw;
    let usable_w: f32 = (vp_w - left_raw - right_raw).max(200.0);
    let side_margin: f32 = if metrics.get_is_compact_bp() {
        SHELL_BOTTOM_NAV_SIDE_MARGIN
    } else {
        SHELL_BOTTOM_NAV_SIDE_MARGIN_WIDE
    };
    let min_dock_w: f32 = 240.0_f32.min((usable_w - 16.0).max(160.0));
    let dock_w: f32 = (usable_w - side_margin * 2.0).clamp(min_dock_w, SHELL_BOTTOM_NAV_MAX_WIDTH);
    let dock_left: f32 = left_raw + ((usable_w - dock_w) * 0.5).max(8.0);
    let content_extra_bottom_pad: f32 = if show_dock {
        dock_h + dock_bottom + 12.0
    } else {
        bottom_raw
    };
    BottomFloatingDockBox {
        dock_left,
        dock_bottom,
        dock_width: dock_w,
        dock_height: dock_h,
        content_extra_bottom_pad,
    }
}

/// Resolves the canonical `NavDockPresentation` (`placement`, `orientation`, `icon_only`) shared by `EuvAppShell` and `EuvBottomNav`.
///
/// # Arguments
///
/// - `Size` - Active logical viewport size.
/// - `SafeAreaInsets` - Active hardware safe-area insets.
///
/// # Returns
///
/// - `NavDockPresentation` - Dock orientation and compact icon-only state.
#[must_use]
pub fn resolve_nav_dock_presentation(
    viewport: Size,
    safe_area: SafeAreaInsets,
) -> NavDockPresentation {
    let metrics: ShellViewportMetrics = ShellViewportMetrics::new(
        viewport.get_width(),
        viewport.get_height(),
        safe_area,
        true,
        false,
        false,
        viewport.get_width() < 640.0,
    );
    let resolved: ResolvedChromeLayout = EuvChromeLayoutPolicy::resolve(&metrics);
    NavDockPresentation {
        placement: resolved.get_dock_placement(),
        orientation: resolved.get_dock_orientation(),
        icon_only: resolved.get_dock_icon_only(),
    }
}

/// Resolves unified fullscreen safe-area and display corner-radius padding for all fullscreen portals and rich components.
///
/// Keeps immersive canvases edge-to-edge while guaranteeing every close button, toolbar action, and interactive corner stays cleanly inside large curved display corners (`55..59dp`), notches, Dynamic Islands, and side signal rails.
///
/// # Arguments
///
/// - `Size` - Active logical viewport size.
/// - `SafeAreaInsets` - Hardware safe-area insets reported by the host OS.
///
/// # Returns
///
/// - `FullscreenSafeLayout` - Header, footer, and body safe padding plus corner clearance.
#[must_use]
pub fn resolve_fullscreen_safe_layout(
    viewport: Size,
    safe: SafeAreaInsets,
) -> FullscreenSafeLayout {
    let vp_w: f32 = viewport.get_width().max(CHROME_MIN_VIEWPORT_CLAMP);
    let vp_h: f32 = viewport.get_height().max(CHROME_MIN_VIEWPORT_CLAMP);
    let top_raw: f32 = safe.get_top().max(0.0);
    let right_raw: f32 = safe.get_right().max(0.0);
    let bottom_raw: f32 = safe.get_bottom().max(0.0);
    let left_raw: f32 = safe.get_left().max(0.0);
    let is_watch: bool = vp_w < CHROME_WATCH_VIEWPORT_MAX || vp_h < CHROME_WATCH_VIEWPORT_MAX;
    let has_hw_safe: bool = top_raw.max(right_raw).max(bottom_raw).max(left_raw) > 0.5;
    if is_watch {
        let dial_pad: f32 = (vp_w.min(vp_h) * 0.14).clamp(18.0, 36.0);
        let h_pad: f32 = left_raw.max(right_raw).max(dial_pad);
        let v_top: f32 = top_raw.max(dial_pad);
        let v_bot: f32 = bottom_raw.max(dial_pad);
        return FullscreenSafeLayout {
            header_padding: Edges::new(v_top, h_pad, SPACE_XS, h_pad),
            footer_padding: Edges::new(SPACE_XS, h_pad, v_bot, h_pad),
            body_padding: Edges::new(0.0, h_pad * 0.5, v_bot * 0.5, h_pad * 0.5),
            corner_clearance: dial_pad,
        };
    }
    if !has_hw_safe {
        return FullscreenSafeLayout {
            header_padding: Edges::new(SPACE_SM, SPACE_MD, SPACE_SM, SPACE_MD),
            footer_padding: Edges::new(SPACE_SM, SPACE_MD, SPACE_SM, SPACE_MD),
            body_padding: Edges::all(0.0),
            corner_clearance: 0.0,
        };
    }
    let top_clear: f32 = top_raw.max(CHROME_FULLSCREEN_CORNER_V_MIN);
    let bot_clear: f32 = bottom_raw.max(CHROME_FULLSCREEN_CORNER_V_MIN);
    let left_clear: f32 = left_raw.max(CHROME_FULLSCREEN_CORNER_H_MIN);
    let right_clear: f32 = right_raw.max(CHROME_FULLSCREEN_CORNER_H_MIN);
    let header_padding: Edges = Edges::new(
        top_clear + SPACE_SM,
        right_clear + SPACE_SM,
        SPACE_SM,
        left_clear + SPACE_SM,
    );
    let footer_padding: Edges = Edges::new(
        SPACE_SM,
        right_clear + SPACE_SM,
        bot_clear + SPACE_SM,
        left_clear + SPACE_SM,
    );
    let body_padding: Edges = Edges::new(0.0, right_raw, bottom_raw, left_raw);
    FullscreenSafeLayout {
        header_padding,
        footer_padding,
        body_padding,
        corner_clearance: CHROME_FULLSCREEN_CORNER_H_MIN,
    }
}