feat: add native material backgrounds

This commit is contained in:
2026-11-09 09:52:29 +07:00
parent 8c438ed8a6
commit 7784e8d570
14 changed files with 279 additions and 36 deletions
+43
View File
@@ -3,6 +3,8 @@
use gpui::{Hsla, hsla, rgb};
use crate::ThemeVariant;
fn hex(hex: u32) -> Hsla {
rgb(hex).into()
}
@@ -115,3 +117,44 @@ impl ColorTokens {
}
}
}
/// The translucent paints surfaces lay over a native window material.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MaterialTokens {
/// The window-sized fill the material shows through.
pub background: Hsla,
/// The hover wash over material surfaces.
pub hover: Hsla,
/// The selected-row fill over material surfaces.
pub selection: Hsla,
}
impl MaterialTokens {
/// Derives the material paints from the resolved palette.
pub(crate) fn derive(
colors: &ColorTokens,
selection: Hsla,
variant: ThemeVariant,
translucent: bool,
) -> Self {
if !translucent {
return Self {
background: colors.background,
hover: colors.muted,
selection,
};
}
// Light tints heavier than dark: the blur carries less contrast there.
let background_alpha = match variant {
ThemeVariant::Light => 0.6,
ThemeVariant::Dark => 0.5,
};
Self {
background: colors.background.alpha(background_alpha),
// A foreground wash keeps hover visible over any backdrop hue.
hover: colors.foreground.alpha(0.06),
selection: selection.alpha(0.85),
}
}
}