refactor: cosmic-config granular key updates and remove unused generics from cosmic-theme
This commit is contained in:
parent
ef657fb19d
commit
a4d1b1b651
18 changed files with 233 additions and 699 deletions
|
|
@ -12,20 +12,20 @@ use cosmic_config::CosmicConfigEntry;
|
|||
use cosmic_theme::Component;
|
||||
use cosmic_theme::LayeredTheme;
|
||||
use iced_futures::Subscription;
|
||||
use palette::Srgba;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type CosmicColor = ::palette::rgb::Srgba;
|
||||
pub type CosmicComponent = cosmic_theme::Component<CosmicColor>;
|
||||
pub type CosmicTheme = cosmic_theme::Theme<CosmicColor>;
|
||||
pub type CosmicComponent = cosmic_theme::Component;
|
||||
pub type CosmicTheme = cosmic_theme::Theme;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref COSMIC_DARK: CosmicTheme = CosmicTheme::dark_default();
|
||||
pub static ref COSMIC_HC_DARK: CosmicTheme = CosmicTheme::high_contrast_dark_default();
|
||||
pub static ref COSMIC_LIGHT: CosmicTheme = CosmicTheme::light_default();
|
||||
pub static ref COSMIC_HC_LIGHT: CosmicTheme = CosmicTheme::high_contrast_light_default();
|
||||
pub static ref TRANSPARENT_COMPONENT: Component<CosmicColor> = Component {
|
||||
pub static ref TRANSPARENT_COMPONENT: Component = Component {
|
||||
base: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
|
||||
hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
|
||||
pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
|
||||
|
|
@ -69,7 +69,7 @@ pub fn is_high_contrast() -> bool {
|
|||
|
||||
/// Watches for changes to the system's theme preference.
|
||||
pub fn subscription(id: u64, is_dark: bool) -> Subscription<crate::theme::Theme> {
|
||||
config_subscription::<_, crate::cosmic_theme::Theme<Srgba>>(
|
||||
config_subscription::<_, crate::cosmic_theme::Theme>(
|
||||
(id, is_dark),
|
||||
if is_dark {
|
||||
cosmic_theme::DARK_THEME_ID
|
||||
|
|
@ -77,7 +77,7 @@ pub fn subscription(id: u64, is_dark: bool) -> Subscription<crate::theme::Theme>
|
|||
cosmic_theme::LIGHT_THEME_ID
|
||||
}
|
||||
.into(),
|
||||
crate::cosmic_theme::Theme::<Srgba>::version(),
|
||||
crate::cosmic_theme::Theme::version(),
|
||||
)
|
||||
.map(|(_, res)| {
|
||||
let theme = res.unwrap_or_else(|(errors, theme)| {
|
||||
|
|
@ -102,9 +102,9 @@ pub fn system_preference() -> Theme {
|
|||
};
|
||||
|
||||
let helper = if is_dark {
|
||||
crate::cosmic_theme::Theme::<Srgba>::dark_config()
|
||||
crate::cosmic_theme::Theme::dark_config()
|
||||
} else {
|
||||
crate::cosmic_theme::Theme::<Srgba>::light_config()
|
||||
crate::cosmic_theme::Theme::light_config()
|
||||
};
|
||||
|
||||
let Ok(helper) = helper else {
|
||||
|
|
@ -164,7 +164,7 @@ pub struct Theme {
|
|||
|
||||
impl Theme {
|
||||
#[must_use]
|
||||
pub fn cosmic(&self) -> &cosmic_theme::Theme<Srgba> {
|
||||
pub fn cosmic(&self) -> &cosmic_theme::Theme {
|
||||
match self.theme_type {
|
||||
ThemeType::Dark => &COSMIC_DARK,
|
||||
ThemeType::Light => &COSMIC_LIGHT,
|
||||
|
|
@ -219,7 +219,7 @@ impl Theme {
|
|||
/// get current container
|
||||
/// can be used in a component that is intended to be a child of a `CosmicContainer`
|
||||
#[must_use]
|
||||
pub fn current_container(&self) -> &cosmic_theme::Container<Srgba> {
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use cosmic_theme::Component;
|
||||
use iced_core::{Background, Color};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
|
||||
use crate::{
|
||||
theme::TRANSPARENT_COMPONENT,
|
||||
|
|
@ -40,7 +40,7 @@ pub fn appearance(
|
|||
theme: &crate::Theme,
|
||||
focused: bool,
|
||||
style: &Button,
|
||||
color: impl Fn(&Component<Alpha<Rgb, f32>>) -> (Color, Option<Color>, Option<Color>),
|
||||
color: impl Fn(&Component) -> (Color, Option<Color>, Option<Color>),
|
||||
) -> Appearance {
|
||||
let cosmic = theme.cosmic();
|
||||
let mut corner_radii = &cosmic.corner_radii.radius_xl;
|
||||
|
|
|
|||
|
|
@ -520,8 +520,7 @@ impl slider::StyleSheet for Theme {
|
|||
Slider::Standard =>
|
||||
//TODO: no way to set rail thickness
|
||||
{
|
||||
let cosmic: &cosmic_theme::Theme<palette::Alpha<palette::rgb::Rgb, f32>> =
|
||||
self.cosmic();
|
||||
let cosmic: &cosmic_theme::Theme = self.cosmic();
|
||||
|
||||
slider::Appearance {
|
||||
rail: Rail {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
use crate::widget::segmented_button::{Appearance, ItemAppearance, StyleSheet};
|
||||
use crate::{theme::Theme, widget::segmented_button::ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum SegmentedButton {
|
||||
|
|
@ -155,9 +154,8 @@ impl StyleSheet for Theme {
|
|||
mod horizontal {
|
||||
use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use palette::{rgb::Rgb, white_point::C, Alpha};
|
||||
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>) -> ItemStatusAppearance {
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance {
|
||||
let mut neutral_5 = cosmic.palette.neutral_5;
|
||||
neutral_5.alpha = 0.2;
|
||||
let rad_m = cosmic.corner_radii.radius_m;
|
||||
|
|
@ -180,9 +178,7 @@ mod horizontal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn view_switcher_active(
|
||||
cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>,
|
||||
) -> ItemStatusAppearance {
|
||||
pub fn view_switcher_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance {
|
||||
let mut neutral_5 = cosmic.palette.neutral_5;
|
||||
neutral_5.alpha = 0.2;
|
||||
let rad_s = cosmic.corner_radii.radius_s;
|
||||
|
|
@ -209,10 +205,7 @@ mod horizontal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn focus(
|
||||
cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>,
|
||||
default: &ItemStatusAppearance,
|
||||
) -> ItemStatusAppearance {
|
||||
pub fn focus(cosmic: &cosmic_theme::Theme, default: &ItemStatusAppearance) -> ItemStatusAppearance {
|
||||
// TODO: This is a hack to make the hover color lighter than the selected color
|
||||
// I'm not sure why the alpha is being applied differently here than in figma
|
||||
let mut neutral_5 = cosmic.palette.neutral_5;
|
||||
|
|
@ -224,10 +217,7 @@ pub fn focus(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn hover(
|
||||
cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>,
|
||||
default: &ItemStatusAppearance,
|
||||
) -> ItemStatusAppearance {
|
||||
pub fn hover(cosmic: &cosmic_theme::Theme, default: &ItemStatusAppearance) -> ItemStatusAppearance {
|
||||
let mut neutral_10 = cosmic.palette.neutral_10;
|
||||
neutral_10.alpha = 0.1;
|
||||
ItemStatusAppearance {
|
||||
|
|
@ -240,9 +230,8 @@ pub fn hover(
|
|||
mod vertical {
|
||||
use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance};
|
||||
use iced_core::{Background, BorderRadius};
|
||||
use palette::{rgb::Rgb, Alpha};
|
||||
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>) -> ItemStatusAppearance {
|
||||
pub fn selection_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance {
|
||||
let mut neutral_5 = cosmic.palette.neutral_5;
|
||||
neutral_5.alpha = 0.2;
|
||||
let rad_0 = cosmic.corner_radii.radius_0;
|
||||
|
|
@ -265,9 +254,7 @@ mod vertical {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn view_switcher_active(
|
||||
cosmic: &cosmic_theme::Theme<Alpha<Rgb, f32>>,
|
||||
) -> ItemStatusAppearance {
|
||||
pub fn view_switcher_active(cosmic: &cosmic_theme::Theme) -> ItemStatusAppearance {
|
||||
let mut neutral_5 = cosmic.palette.neutral_5;
|
||||
neutral_5.alpha = 0.2;
|
||||
ItemStatusAppearance {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue