theme: add transparency knob for material fill

This commit is contained in:
2026-11-14 11:15:39 +07:00
parent 59ab6eb921
commit db41b19e4a
3 changed files with 146 additions and 8 deletions
+10 -6
View File
@@ -3,7 +3,7 @@
use gpui::{Hsla, hsla, rgb};
use crate::ThemeVariant;
use crate::{DEFAULT_TRANSPARENCY, MIN_MATERIAL_FILL_DARK, MIN_MATERIAL_FILL_LIGHT, ThemeVariant};
fn hex(hex: u32) -> Hsla {
rgb(hex).into()
@@ -136,6 +136,7 @@ impl MaterialTokens {
selection: Hsla,
variant: ThemeVariant,
translucent: bool,
transparency: Option<u8>,
) -> Self {
if !translucent {
return Self {
@@ -145,13 +146,16 @@ impl MaterialTokens {
};
}
// Light tints heavier than dark: the blur carries less contrast there.
let background_alpha = match variant {
ThemeVariant::Light => 0.6,
ThemeVariant::Dark => 0.5,
let level = transparency.unwrap_or(DEFAULT_TRANSPARENCY) as f32 / 100.0;
let floor = match variant {
ThemeVariant::Light => MIN_MATERIAL_FILL_LIGHT,
ThemeVariant::Dark => MIN_MATERIAL_FILL_DARK,
};
Self {
background: colors.background.alpha(background_alpha),
// The fill eases toward a floor instead of zero.
background: colors.background.alpha(1.0 - level * (1.0 - floor)),
// A foreground wash keeps hover visible over any backdrop hue.
hover: colors.foreground.alpha(0.06),
selection: selection.alpha(0.85),