feat: support for custom & system themes + move cosmic-theme to libcosmic

This commit is contained in:
Ashley Wulber 2023-05-22 13:05:33 -04:00
parent 259bba4d19
commit bf1c474d08
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
26 changed files with 2639 additions and 44 deletions

View file

@ -3,6 +3,7 @@
#![allow(clippy::module_name_repetitions)]
pub use cosmic_config;
pub use cosmic_theme;
pub use iced;
pub use iced_runtime;
@ -12,7 +13,6 @@ pub use iced_style;
pub use iced_widget;
#[cfg(feature = "winit")]
pub use iced_winit;
#[cfg(feature = "applet")]
pub mod applet;
pub mod executor;

View file

@ -7,6 +7,7 @@ mod segmented_button;
use std::hash::Hash;
use std::hash::Hasher;
use std::rc::Rc;
use std::sync::Arc;
pub use self::segmented_button::SegmentedButton;
@ -32,10 +33,10 @@ use iced_style::toggler;
use iced_core::{Background, Color};
use palette::Srgba;
type CosmicColor = ::palette::rgb::Srgba;
type CosmicComponent = cosmic_theme::Component<CosmicColor>;
type CosmicTheme = cosmic_theme::Theme<CosmicColor>;
type CosmicThemeCss = cosmic_theme::Theme<cosmic_theme::util::CssColor>;
pub type CosmicColor = ::palette::rgb::Srgba;
pub type CosmicComponent = cosmic_theme::Component<CosmicColor>;
pub type CosmicTheme = cosmic_theme::Theme<CosmicColor>;
pub type CosmicThemeCss = cosmic_theme::Theme<cosmic_theme::util::CssColor>;
lazy_static::lazy_static! {
pub static ref COSMIC_DARK: CosmicTheme = CosmicThemeCss::dark_default().into_srgba();
@ -56,16 +57,17 @@ lazy_static::lazy_static! {
};
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub enum ThemeType {
#[default]
Dark,
Light,
HighContrastDark,
HighContrastLight,
Custom(Arc<CosmicTheme>),
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
#[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct Theme {
pub theme_type: ThemeType,
pub layer: cosmic_theme::Layer,
@ -79,6 +81,7 @@ impl Theme {
ThemeType::Light => &COSMIC_LIGHT,
ThemeType::HighContrastDark => &COSMIC_HC_DARK,
ThemeType::HighContrastLight => &COSMIC_HC_LIGHT,
ThemeType::Custom(ref t) => t.as_ref(),
}
}
@ -114,6 +117,14 @@ impl Theme {
}
}
#[must_use]
pub fn custom(theme: Arc<CosmicTheme>) -> Self {
Self {
theme_type: ThemeType::Custom(theme),
..Default::default()
}
}
/// get current container
/// can be used in a component that is intended to be a child of a `CosmicContainer`
#[must_use]