euv-core 0.48.3

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Computes shape-aware logical `SafeAreaInsets` for a smartwatch display (`Round`, `Squircle`, or `Rectangular`).
///
/// For `WearableShape::Round`, calculates the exact maximum inscribed square clearance inside the circle
/// (`margin = diameter * (1.0 - 1.0 / SQRT_2) * 0.5`), adding non-square aspect centering and optional bottom chin clearance.
///
/// # Arguments
///
/// - `WearableShape` - Physical watch screen geometry.
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Logical viewport height in dp.
/// - `f32` - Optional flat-tire bottom chin height in logical dp.
///
/// # Returns
///
/// - `SafeAreaInsets` - Sanitized inscribed safe-area insets in logical dp.
#[must_use]
pub fn compute_wearable_safe_area(
    shape: WearableShape,
    logical_width: f32,
    logical_height: f32,
    chin_height_dp: f32,
) -> SafeAreaInsets {
    let w: f32 = if logical_width.is_finite() {
        logical_width.max(1.0)
    } else {
        WEARABLE_REF_DIAL_DP
    };
    let h: f32 = if logical_height.is_finite() {
        logical_height.max(1.0)
    } else {
        WEARABLE_REF_DIAL_DP
    };
    let chin: f32 = if chin_height_dp.is_finite() && chin_height_dp > 0.0 {
        chin_height_dp.min(h * 0.35)
    } else {
        0.0
    };
    match shape {
        WearableShape::Round => {
            let diameter: f32 = w.min(h);
            let inscribed_side: f32 = diameter / SQRT_2;
            let horiz: f32 = ((w - inscribed_side) * 0.5).max(0.0);
            let vert: f32 = ((h - inscribed_side) * 0.5).max(0.0);
            let bottom: f32 = vert.max(chin);
            SafeAreaInsets::new(vert, horiz, bottom, horiz)
        }
        WearableShape::Squircle => {
            let short_edge: f32 = w.min(h);
            let corner_radius: f32 = short_edge * WEARABLE_SQUIRCLE_RADIUS_RATIO;
            let corner_inset: f32 = (corner_radius * (1.0 - (1.0 / SQRT_2))).max(0.0);
            let top: f32 = corner_inset.max(WEARABLE_RECT_TOP_INSET_DP);
            let bottom: f32 = corner_inset.max(chin);
            SafeAreaInsets::new(top, corner_inset, bottom, corner_inset)
        }
        WearableShape::Rectangular => {
            let bottom: f32 = WEARABLE_RECT_BOTTOM_INSET_DP.max(chin);
            SafeAreaInsets::new(
                WEARABLE_RECT_TOP_INSET_DP,
                WEARABLE_RECT_SIDE_INSET_DP,
                bottom,
                WEARABLE_RECT_SIDE_INSET_DP,
            )
        }
    }
}

/// Computes the deterministic compact UI scaling factor for small smartwatch screens relative to the 210dp reference dial.
///
/// # Arguments
///
/// - `f32` - Logical viewport width in dp.
/// - `f32` - Logical viewport height in dp.
///
/// # Returns
///
/// - `f32` - Clamped compact viewport scaling multiplier in `[0.72, 1.20]`.
#[must_use]
pub fn compute_wearable_compact_scale(logical_width: f32, logical_height: f32) -> f32 {
    let short_edge: f32 = if logical_width.is_finite() && logical_height.is_finite() {
        logical_width.min(logical_height).max(80.0)
    } else {
        WEARABLE_REF_DIAL_DP
    };
    (short_edge / WEARABLE_REF_DIAL_DP)
        .clamp(WEARABLE_MIN_COMPACT_SCALE, WEARABLE_MAX_COMPACT_SCALE)
}