use super::*;
#[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,
)
}
}
}
#[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)
}