refactor opaque fallback
This commit is contained in:
parent
d0b164d216
commit
19142fd38e
12 changed files with 345 additions and 161 deletions
|
|
@ -46,6 +46,7 @@ pub static TRANSPARENT_COMPONENT: LazyLock<Component> = LazyLock::new(|| Compone
|
|||
pub(crate) static THEME: Mutex<Theme> = Mutex::new(Theme {
|
||||
theme_type: ThemeType::Dark,
|
||||
layer: cosmic_theme::Layer::Background,
|
||||
transparent: false,
|
||||
});
|
||||
|
||||
/// Currently-defined theme.
|
||||
|
|
@ -209,6 +210,7 @@ impl ThemeType {
|
|||
pub struct Theme {
|
||||
pub theme_type: ThemeType,
|
||||
pub layer: cosmic_theme::Layer,
|
||||
pub transparent: bool,
|
||||
}
|
||||
|
||||
impl Theme {
|
||||
|
|
@ -279,9 +281,9 @@ impl Theme {
|
|||
/// can be used in a component that is intended to be a child of a `CosmicContainer`
|
||||
pub fn current_container(&self) -> &cosmic_theme::Container {
|
||||
match self.layer {
|
||||
cosmic_theme::Layer::Background => &self.cosmic().background,
|
||||
cosmic_theme::Layer::Primary => &self.cosmic().primary,
|
||||
cosmic_theme::Layer::Secondary => &self.cosmic().secondary,
|
||||
cosmic_theme::Layer::Background => &self.cosmic().background(self.transparent),
|
||||
cosmic_theme::Layer::Primary => &self.cosmic().primary(self.transparent),
|
||||
cosmic_theme::Layer::Secondary => &self.cosmic().secondary(self.transparent),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,29 +292,6 @@ impl Theme {
|
|||
pub fn set_theme(&mut self, theme: ThemeType) {
|
||||
self.theme_type = theme;
|
||||
}
|
||||
|
||||
pub fn into_opaque(&self) -> Self {
|
||||
let mut new_theme = Theme {
|
||||
theme_type: match &self.theme_type {
|
||||
ThemeType::System { theme, prefer_dark } => {
|
||||
let mut new_t = (**theme).clone();
|
||||
new_t.background.base.alpha = 1.0;
|
||||
new_t.primary.base.alpha = 1.0;
|
||||
new_t.secondary.base.alpha = 1.0;
|
||||
ThemeType::System {
|
||||
theme: Arc::new(new_t),
|
||||
prefer_dark: *prefer_dark,
|
||||
}
|
||||
}
|
||||
other => other.clone(),
|
||||
},
|
||||
layer: self.layer,
|
||||
};
|
||||
let cosmic = new_theme.cosmic();
|
||||
// copy theme but make all container colors opaque
|
||||
|
||||
new_theme
|
||||
}
|
||||
}
|
||||
|
||||
impl LayeredTheme for Theme {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue