use super::style::Look;
use crate::{
components::{appearance::Appearance, Ui},
Border, Color, CornerRadius, Gradient, Id, Interpolate, Rect, Shadow, Vec2,
};
fn surface(ui: &Ui<'_>, look: &Look, sheet: bool) -> Appearance {
let style = ui.style();
let mut body = Appearance::new(Color::TRANSPARENT, Border::NONE, style.text_color);
body.apply(style.card.surface);
body.apply(look.style.card);
if sheet {
body.apply(look.style.sheet);
}
if body.fill.start.0[3] == 0 && body.fill.end.0[3] == 0 {
body.fill = Gradient::new(style.window_fill, style.window_fill);
}
let shadow_set = style.card.surface.shadow.is_some()
|| look.style.card.shadow.is_some()
|| (sheet && look.style.sheet.shadow.is_some());
if !shadow_set {
body.shadow = Shadow {
color: Color::rgba(0, 0, 0, if sheet { 28 } else { 46 }),
offset: Vec2::new(0.0, if sheet { 3.0 } else { 8.0 }),
blur_radius: if sheet { 8.0 } else { 20.0 },
spread: 0.0,
};
}
body.opacity = style.opacity;
body.ring = None;
body
}
pub(super) fn paint_card(ui: &mut Ui<'_>, id: Id, rect: Rect, look: &Look, depth: f32) {
let t = if depth.is_finite() {
depth.clamp(0.0, 1.0)
} else {
0.0
};
let front = surface(ui, look, false);
let body = if t > 0.0 {
front.interpolate(&surface(ui, look, true), t)
} else {
front
};
let rounding = CornerRadius::all(look.rounding());
let mut paint = Vec::new();
body.paint_shadow(rect, rounding, &mut paint);
body.paint_body(rect, rounding, ui.style(), 0.0, &mut paint);
ui.context.paint(id, ui.window, ui.clip, paint);
}