euv-core 0.46.1

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 capsule-safe logical `SafeAreaInsets` combining status bar, notch safe area, and floating capsule pill clearance.
///
/// # Arguments
///
/// - `&MiniAppSystemInfo` - Normalized host Mini-Program system metrics.
/// - `bool` - When `true`, expands top safe inset to clear the bottom edge of the floating capsule button.
///
/// # Returns
///
/// - `SafeAreaInsets` - Sanitized safe-area insets in logical dp.
#[must_use]
pub fn resolve_miniapp_safe_area(
    info: &MiniAppSystemInfo,
    include_capsule_clearance: bool,
) -> SafeAreaInsets {
    let raw: SafeAreaInsets = info.get_safe_area();
    let status_h: f32 = if info.get_status_bar_height().is_finite() {
        info.get_status_bar_height().max(0.0)
    } else {
        0.0
    };
    let capsule_bottom: f32 = if include_capsule_clearance
        && info.get_capsule().get_bottom().is_finite()
        && info.get_capsule().get_bottom() > 0.0
    {
        info.get_capsule().get_bottom() + MINIAPP_CAPSULE_BOTTOM_GAP_DP
    } else {
        0.0
    };
    let top: f32 = raw.get_top().max(0.0).max(status_h).max(capsule_bottom);
    let right: f32 = raw.get_right().max(0.0);
    let bottom: f32 = raw.get_bottom().max(0.0);
    let left: f32 = raw.get_left().max(0.0);
    SafeAreaInsets::new(top, right, bottom, left)
}

/// Maps a Mini-Program `onMemoryWarning` level integer into canonical `MemoryPressure`.
///
/// # Arguments
///
/// - `i32` - Vendor memory warning level (`>= 10` critical, `> 0` warning, `0` normal).
///
/// # Returns
///
/// - `MemoryPressure` - Normalized memory pressure severity.
#[must_use]
pub const fn miniapp_memory_level_to_pressure(level: i32) -> MemoryPressure {
    if level >= 10 {
        MemoryPressure::Critical
    } else if level > 0 {
        MemoryPressure::Warning
    } else {
        MemoryPressure::Normal
    }
}