diff --git a/cosmic-config-derive/Cargo.toml b/cosmic-config-derive/Cargo.toml index 44f960e..46d7965 100644 --- a/cosmic-config-derive/Cargo.toml +++ b/cosmic-config-derive/Cargo.toml @@ -9,4 +9,4 @@ proc-macro = true [dependencies] syn = "1.0" -quote = "1.0" +quote = "1.0" \ No newline at end of file diff --git a/cosmic-config-derive/src/lib.rs b/cosmic-config-derive/src/lib.rs index 0e27afb..76db752 100644 --- a/cosmic-config-derive/src/lib.rs +++ b/cosmic-config-derive/src/lib.rs @@ -14,7 +14,6 @@ pub fn cosmic_config_entry_derive(input: TokenStream) -> TokenStream { fn impl_cosmic_config_entry_macro(ast: &syn::DeriveInput) -> TokenStream { let name = &ast.ident; - // let generics = &ast.generics; // Get the fields of the struct let fields = match ast.data { @@ -43,20 +42,25 @@ fn impl_cosmic_config_entry_macro(ast: &syn::DeriveInput) -> TokenStream { } }); - // // Get the existing where clause or create a new one if it doesn't exist - // let mut where_clause = ast - // .generics - // .where_clause - // .clone() - // .unwrap_or_else(|| parse_quote!(where)); - - // // Add your additional constraints to the where clause - // // Here, we add the constraint 'T: Debug' to all generic parameters - // for param in ast.generics.params.iter() { - // where_clause - // .predicates - // .push(parse_quote!(#param: ::std::default::Default + ::serde::Serialize + ::serde::de::DeserializeOwned)); - // } + let update_each_config_field = fields.iter().map(|field| { + let field_name = &field.ident; + let field_type = &field.ty; + quote! { + stringify!(#field_name) => { + match cosmic_config::ConfigGet::get::<#field_type>(config, stringify!(#field_name)) { + Ok(value) => { + if self.#field_name != value { + keys.push(stringify!(#field_name)); + } + self.#field_name = value; + }, + Err(e) => { + errors.push(e); + } + } + } + } + }); let gen = quote! { impl CosmicConfigEntry for #name { @@ -78,6 +82,18 @@ fn impl_cosmic_config_entry_macro(ast: &syn::DeriveInput) -> TokenStream { Err((errors, default)) } } + + fn update_keys>(&mut self, config: &cosmic_config::Config, changed_keys: &[T]) -> (Vec, Vec<&str>){ + let mut keys = Vec::with_capacity(changed_keys.len()); + let mut errors = Vec::new(); + for key in changed_keys.iter() { + match key.as_ref() { + #(#update_each_config_field)* + _ => (), + } + } + (errors, keys) + } } }; diff --git a/cosmic-config/src/lib.rs b/cosmic-config/src/lib.rs index 8ff3d8d..203b6da 100644 --- a/cosmic-config/src/lib.rs +++ b/cosmic-config/src/lib.rs @@ -325,7 +325,7 @@ impl<'a> ConfigSet for ConfigTransaction<'a> { #[cfg(feature = "subscription")] pub enum ConfigState { Init(Cow<'static, str>, u64, bool), - Waiting(T, RecommendedWatcher, mpsc::Receiver<()>, Config), + Waiting(T, RecommendedWatcher, mpsc::Receiver>, Config), Failed, } @@ -342,6 +342,12 @@ where { fn write_entry(&self, config: &Config) -> Result<(), crate::Error>; fn get_entry(config: &Config) -> Result, Self)>; + /// Returns the keys that were updated + fn update_keys>( + &mut self, + config: &Config, + changed_keys: &[T], + ) -> (Vec, Vec<&str>); } #[cfg(feature = "subscription")] @@ -409,9 +415,9 @@ async fn start_listening< Ok(c) => c, Err(_) => return ConfigState::Failed, }; - let watcher = match config.watch(move |_helper, _keys| { + let watcher = match config.watch(move |_helper, keys| { let mut tx = tx.clone(); - let _ = tx.try_send(()); + let _ = tx.try_send(keys.to_vec()); }) { Ok(w) => w, Err(_) => return ConfigState::Failed, @@ -428,24 +434,19 @@ async fn start_listening< } } } - ConfigState::Waiting(mut old, watcher, mut rx, config) => match rx.next().await { - Some(_) => match T::get_entry(&config) { - Ok(t) => { - if t != old { - old = t; - _ = output.send((id, Ok(old.clone()))).await; - } - ConfigState::Waiting(old, watcher, rx, config) - } - Err((errors, t)) => { - if t != old { - old = t; - _ = output.send((id, Err((errors, old.clone())))).await; - } - ConfigState::Waiting(old, watcher, rx, config) - } - }, + ConfigState::Waiting(mut conf_data, watcher, mut rx, config) => match rx.next().await { + Some(keys) => { + let (errors, changed) = conf_data.update_keys(&config, &keys); + if !changed.is_empty() { + if errors.is_empty() { + _ = output.send((id, Ok(conf_data.clone()))).await; + } else { + _ = output.send((id, Err((errors, conf_data.clone())))).await; + } + } + ConfigState::Waiting(conf_data, watcher, rx, config) + } None => ConfigState::Failed, }, ConfigState::Failed => pending().await, diff --git a/cosmic-theme/src/lib.rs b/cosmic-theme/src/lib.rs index 782d15f..6c46cb3 100644 --- a/cosmic-theme/src/lib.rs +++ b/cosmic-theme/src/lib.rs @@ -7,7 +7,6 @@ //! pub use model::*; -pub use output::*; mod model; mod output; @@ -16,8 +15,6 @@ mod output; pub mod composite; /// get color steps pub mod steps; -/// utilities -pub mod util; /// name of cosmic theme pub const NAME: &'static str = "com.system76.CosmicTheme"; diff --git a/cosmic-theme/src/model/cosmic_palette.rs b/cosmic-theme/src/model/cosmic_palette.rs index 6109208..6933c99 100644 --- a/cosmic-theme/src/model/cosmic_palette.rs +++ b/cosmic-theme/src/model/cosmic_palette.rs @@ -1,36 +1,32 @@ -use std::fmt; - use lazy_static::lazy_static; use palette::Srgba; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; - -use crate::util::CssColor; +use serde::{Deserialize, Serialize}; lazy_static! { /// built in light palette - pub static ref LIGHT_PALETTE: CosmicPalette = + pub static ref LIGHT_PALETTE: CosmicPalette = ron::from_str(include_str!("light.ron")).unwrap(); /// built in dark palette - pub static ref DARK_PALETTE: CosmicPalette = + pub static ref DARK_PALETTE: CosmicPalette = ron::from_str(include_str!("dark.ron")).unwrap(); } /// Palette type -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub enum CosmicPalette { +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub enum CosmicPalette { /// Dark mode - Dark(CosmicPaletteInner), + Dark(CosmicPaletteInner), /// Light mode - Light(CosmicPaletteInner), + Light(CosmicPaletteInner), /// High contrast light mode - HighContrastLight(CosmicPaletteInner), + HighContrastLight(CosmicPaletteInner), /// High contrast dark mode - HighContrastDark(CosmicPaletteInner), + HighContrastDark(CosmicPaletteInner), } -impl CosmicPalette { +impl CosmicPalette { /// extract the inner palette - pub fn inner(self) -> CosmicPaletteInner { + pub fn inner(self) -> CosmicPaletteInner { match self { CosmicPalette::Dark(p) => p, CosmicPalette::Light(p) => p, @@ -40,8 +36,8 @@ impl CosmicPalette { } } -impl AsMut> for CosmicPalette { - fn as_mut(&mut self) -> &mut CosmicPaletteInner { +impl AsMut for CosmicPalette { + fn as_mut(&mut self) -> &mut CosmicPaletteInner { match self { CosmicPalette::Dark(p) => p, CosmicPalette::Light(p) => p, @@ -51,11 +47,8 @@ impl AsMut> for CosmicPalette { } } -impl AsRef> for CosmicPalette -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ - fn as_ref(&self) -> &CosmicPaletteInner { +impl AsRef for CosmicPalette { + fn as_ref(&self) -> &CosmicPaletteInner { match self { CosmicPalette::Dark(p) => p, CosmicPalette::Light(p) => p, @@ -65,10 +58,7 @@ where } } -impl CosmicPalette -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ +impl CosmicPalette { /// check if the palette is dark pub fn is_dark(&self) -> bool { match self { @@ -86,156 +76,105 @@ where } } -impl Default for CosmicPalette -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ +impl Default for CosmicPalette { fn default() -> Self { CosmicPalette::Dark(Default::default()) } } /// The palette for Cosmic Theme, from which all color properties are derived -#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] -pub struct CosmicPaletteInner { +#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] +pub struct CosmicPaletteInner { /// name of the palette pub name: String, /// basic palette /// blue: colors used for various points of emphasis in the UI - pub blue: C, + pub blue: Srgba, /// red: colors used for various points of emphasis in the UI - pub red: C, + pub red: Srgba, /// green: colors used for various points of emphasis in the UI - pub green: C, + pub green: Srgba, /// yellow: colors used for various points of emphasis in the UI - pub yellow: C, + pub yellow: Srgba, /// surface grays /// colors used for three levels of surfaces in the UI - pub gray_1: C, + pub gray_1: Srgba, /// colors used for three levels of surfaces in the UI - pub gray_2: C, + pub gray_2: Srgba, /// colors used for three levels of surfaces in the UI - pub gray_3: C, + pub gray_3: Srgba, /// System Neutrals /// A wider spread of dark colors for more general use. - pub neutral_0: C, + pub neutral_0: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_1: C, + pub neutral_1: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_2: C, + pub neutral_2: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_3: C, + pub neutral_3: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_4: C, + pub neutral_4: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_5: C, + pub neutral_5: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_6: C, + pub neutral_6: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_7: C, + pub neutral_7: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_8: C, + pub neutral_8: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_9: C, + pub neutral_9: Srgba, /// A wider spread of dark colors for more general use. - pub neutral_10: C, + pub neutral_10: Srgba, // Utility Colors /// Utility bright green - pub bright_green: C, + pub bright_green: Srgba, /// Utility bright red - pub bright_red: C, + pub bright_red: Srgba, /// Utility bright orange - pub bright_orange: C, + pub bright_orange: Srgba, /// Extended Color Palette /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_warm_grey: C, + pub ext_warm_grey: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_orange: C, + pub ext_orange: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_yellow: C, + pub ext_yellow: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_blue: C, + pub ext_blue: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_purple: C, + pub ext_purple: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_pink: C, + pub ext_pink: Srgba, /// Colors used for themes, app icons, illustrations, and other brand purposes. - pub ext_indigo: C, + pub ext_indigo: Srgba, /// Potential Accent Color Combos - pub accent_blue: C, + pub accent_blue: Srgba, /// Potential Accent Color Combos - pub accent_red: C, + pub accent_red: Srgba, /// Potential Accent Color Combos - pub accent_green: C, + pub accent_green: Srgba, /// Potential Accent Color Combos - pub accent_warm_grey: C, + pub accent_warm_grey: Srgba, /// Potential Accent Color Combos - pub accent_orange: C, + pub accent_orange: Srgba, /// Potential Accent Color Combos - pub accent_yellow: C, + pub accent_yellow: Srgba, /// Potential Accent Color Combos - pub accent_purple: C, + pub accent_purple: Srgba, /// Potential Accent Color Combos - pub accent_pink: C, + pub accent_pink: Srgba, /// Potential Accent Color Combos - pub accent_indigo: C, + pub accent_indigo: Srgba, } -impl From> for CosmicPaletteInner { - fn from(p: CosmicPaletteInner) -> Self { - CosmicPaletteInner { - name: p.name, - blue: p.blue.into(), - red: p.red.into(), - green: p.green.into(), - yellow: p.yellow.into(), - gray_1: p.gray_1.into(), - gray_2: p.gray_2.into(), - gray_3: p.gray_3.into(), - neutral_0: p.neutral_0.into(), - neutral_1: p.neutral_1.into(), - neutral_2: p.neutral_2.into(), - neutral_3: p.neutral_3.into(), - neutral_4: p.neutral_4.into(), - neutral_5: p.neutral_5.into(), - neutral_6: p.neutral_6.into(), - neutral_7: p.neutral_7.into(), - neutral_8: p.neutral_8.into(), - neutral_9: p.neutral_9.into(), - neutral_10: p.neutral_10.into(), - bright_green: p.bright_green.into(), - bright_red: p.bright_red.into(), - bright_orange: p.bright_orange.into(), - ext_warm_grey: p.ext_warm_grey.into(), - ext_orange: p.ext_orange.into(), - ext_yellow: p.ext_yellow.into(), - ext_blue: p.ext_blue.into(), - ext_purple: p.ext_purple.into(), - ext_pink: p.ext_pink.into(), - ext_indigo: p.ext_indigo.into(), - accent_blue: p.accent_blue.into(), - accent_red: p.accent_red.into(), - accent_green: p.accent_green.into(), - accent_warm_grey: p.accent_warm_grey.into(), - accent_orange: p.accent_orange.into(), - accent_yellow: p.accent_yellow.into(), - accent_purple: p.accent_purple.into(), - accent_pink: p.accent_pink.into(), - accent_indigo: p.accent_indigo.into(), - } - } -} - -impl CosmicPalette -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ +impl CosmicPalette { /// name of the palette pub fn name(&self) -> &str { match &self { @@ -246,14 +185,3 @@ where } } } - -impl Into> for CosmicPalette { - fn into(self) -> CosmicPalette { - match self { - CosmicPalette::Dark(p) => CosmicPalette::Dark(p.into()), - CosmicPalette::Light(p) => CosmicPalette::Light(p.into()), - CosmicPalette::HighContrastLight(p) => CosmicPalette::HighContrastLight(p.into()), - CosmicPalette::HighContrastDark(p) => CosmicPalette::HighContrastDark(p.into()), - } - } -} diff --git a/cosmic-theme/src/model/dark.ron b/cosmic-theme/src/model/dark.ron index b24cea4..604e442 100644 --- a/cosmic-theme/src/model/dark.ron +++ b/cosmic-theme/src/model/dark.ron @@ -1,116 +1 @@ -Dark ( - ( - name: "cosmic-dark", - blue: ( - c: "#94EBEB", - ), - red: ( - c: "#FFB5B5", - ), - green: ( - c: "#ACF7D2", - ), - yellow: ( - c: "#FFF19E", - ), - gray_1: ( - c: "#1B1B1B", - ), - gray_2: ( - c: "#262626", - ), - gray_3: ( - c: "#303030", - ), - neutral_0: ( - c: "#000000", - ), - neutral_1: ( - c: "#1B1B1B", - ), - neutral_2: ( - c: "#303030", - ), - neutral_3: ( - c: "#474747", - ), - neutral_4: ( - c: "#5E5E5E", - ), - neutral_5: ( - c: "#777777", - ), - neutral_6: ( - c: "#919191", - ), - neutral_7: ( - c: "#ABABAB", - ), - neutral_8: ( - c: "#C6C6C6", - ), - neutral_9: ( - c: "#E2E2E2", - ), - neutral_10: ( - c: "#FFFFFF", - ), - bright_green: ( - c: "#5EDB8C", - ), - bright_red: ( - c: "#FFA090", - ), - bright_orange: ( - c: "#FFA37D", - ), - ext_warm_grey: ( - c: "#9B8E8A", - ), - ext_orange: ( - c: "#FFAD00", - ), - ext_yellow: ( - c: "#FEDB40", - ), - ext_blue: ( - c: "#48B9C7", - ), - ext_purple: ( - c: "#CF7DFF", - ), - ext_pink: ( - c: "#F93A83", - ), - ext_indigo: ( - c: "#3E88FF", - ), - accent_blue: ( - c: "#63D0DF", - ), - accent_green: ( - c: "#92CF9C", - ), - accent_warm_grey: ( - c: "#CABAB4", - ), - accent_orange: ( - c: "#FFAD00", - ), - accent_yellow: ( - c: "#F7E062", - ), - accent_purple: ( - c: "#E79CFE", - ), - accent_pink: ( - c: "#FF9CB1", - ), - accent_red: ( - c: "#FDA1A0", - ), - accent_indigo: ( - c: "#A1C0EB", - ), - ) -) +Dark((name:"cosmic-dark",blue:(red:0.5803922,green:0.92156863,blue:0.92156863,alpha:1.0),red:(red:1.0,green:0.70980394,blue:0.70980394,alpha:1.0),green:(red:0.6745098,green:0.96862745,blue:0.8235294,alpha:1.0),yellow:(red:1.0,green:0.94509804,blue:0.61960787,alpha:1.0),gray_1:(red:0.105882354,green:0.105882354,blue:0.105882354,alpha:1.0),gray_2:(red:0.14901961,green:0.14901961,blue:0.14901961,alpha:1.0),gray_3:(red:0.1882353,green:0.1882353,blue:0.1882353,alpha:1.0),neutral_0:(red:0.0,green:0.0,blue:0.0,alpha:1.0),neutral_1:(red:0.105882354,green:0.105882354,blue:0.105882354,alpha:1.0),neutral_2:(red:0.1882353,green:0.1882353,blue:0.1882353,alpha:1.0),neutral_3:(red:0.2784314,green:0.2784314,blue:0.2784314,alpha:1.0),neutral_4:(red:0.36862746,green:0.36862746,blue:0.36862746,alpha:1.0),neutral_5:(red:0.46666667,green:0.46666667,blue:0.46666667,alpha:1.0),neutral_6:(red:0.5686275,green:0.5686275,blue:0.5686275,alpha:1.0),neutral_7:(red:0.67058825,green:0.67058825,blue:0.67058825,alpha:1.0),neutral_8:(red:0.7764706,green:0.7764706,blue:0.7764706,alpha:1.0),neutral_9:(red:0.8862745,green:0.8862745,blue:0.8862745,alpha:1.0),neutral_10:(red:1.0,green:1.0,blue:1.0,alpha:1.0),bright_green:(red:0.36862746,green:0.85882354,blue:0.54901963,alpha:1.0),bright_red:(red:1.0,green:0.627451,blue:0.5647059,alpha:1.0),bright_orange:(red:1.0,green:0.6392157,blue:0.49019608,alpha:1.0),ext_warm_grey:(red:0.60784316,green:0.5568628,blue:0.5411765,alpha:1.0),ext_orange:(red:1.0,green:0.6784314,blue:0.0,alpha:1.0),ext_yellow:(red:0.99607843,green:0.85882354,blue:0.2509804,alpha:1.0),ext_blue:(red:0.28235295,green:0.7254902,blue:0.78039217,alpha:1.0),ext_purple:(red:0.8117647,green:0.49019608,blue:1.0,alpha:1.0),ext_pink:(red:0.9764706,green:0.22745098,blue:0.5137255,alpha:1.0),ext_indigo:(red:0.24313726,green:0.53333336,blue:1.0,alpha:1.0),accent_blue:(red:0.3882353,green:0.8156863,blue:0.8745098,alpha:1.0),accent_red:(red:0.99215686,green:0.6313726,blue:0.627451,alpha:1.0),accent_green:(red:0.57254905,green:0.8117647,blue:0.6117647,alpha:1.0),accent_warm_grey:(red:0.7921569,green:0.7294118,blue:0.7058824,alpha:1.0),accent_orange:(red:1.0,green:0.6784314,blue:0.0,alpha:1.0),accent_yellow:(red:0.96862745,green:0.8784314,blue:0.38431373,alpha:1.0),accent_purple:(red:0.90588236,green:0.6117647,blue:0.99607843,alpha:1.0),accent_pink:(red:1.0,green:0.6117647,blue:0.69411767,alpha:1.0),accent_indigo:(red:0.6313726,green:0.7529412,blue:0.92156863,alpha:1.0))) \ No newline at end of file diff --git a/cosmic-theme/src/model/derivation.rs b/cosmic-theme/src/model/derivation.rs index 1fd4fb8..599a086 100644 --- a/cosmic-theme/src/model/derivation.rs +++ b/cosmic-theme/src/model/derivation.rs @@ -1,28 +1,24 @@ use palette::Srgba; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::fmt; +use serde::{Deserialize, Serialize}; use crate::composite::over; /// Theme Container colors of a theme, can be a theme background container, primary container, or secondary container -#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] -pub struct Container { +#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] +pub struct Container { /// the color of the container - pub base: C, + pub base: Srgba, /// the color of components in the container - pub component: Component, + pub component: Component, /// the color of dividers in the container - pub divider: C, + pub divider: Srgba, /// the color of text in the container - pub on: C, + pub on: Srgba, } -impl Container -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ +impl Container { /// convert to srgba - pub fn into_srgba(self) -> Container { + pub fn into_srgba(self) -> Container { Container { base: self.base.into(), component: self.component.into_srgba(), @@ -31,7 +27,7 @@ where } } - pub(crate) fn new(component: Component, bg: C, on_bg: C) -> Self { + pub(crate) fn new(component: Component, bg: Srgba, on_bg: Srgba) -> Self { let mut divider_c: Srgba = on_bg.clone().into(); divider_c.alpha = 0.2; @@ -46,40 +42,37 @@ where } /// The colors for a widget of the Cosmic theme -#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize, Eq)] -pub struct Component { +#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct Component { /// The base color of the widget - pub base: C, + pub base: Srgba, /// The color of the widget when it is hovered - pub hover: C, + pub hover: Srgba, /// the color of the widget when it is pressed - pub pressed: C, + pub pressed: Srgba, /// the color of the widget when it is selected - pub selected: C, + pub selected: Srgba, /// the color of the widget when it is selected - pub selected_text: C, + pub selected_text: Srgba, /// the color of the widget when it is focused - pub focus: C, + pub focus: Srgba, /// the color of dividers for this widget - pub divider: C, + pub divider: Srgba, /// the color of text for this widget - pub on: C, + pub on: Srgba, // the color of text with opacity 80 for this widget - // pub text_opacity_80: C, + // pub text_opacity_80: Srgba, /// the color of the widget when it is disabled - pub disabled: C, + pub disabled: Srgba, /// the color of text in the widget when it is disabled - pub on_disabled: C, + pub on_disabled: Srgba, /// the color of the border for the widget - pub border: C, + pub border: Srgba, /// the color of the border for the widget when it is disabled - pub disabled_border: C, + pub disabled_border: Srgba, } -impl Component -where - C: Clone + fmt::Debug + Default + Into + From + Serialize + DeserializeOwned, -{ +impl Component { /// get @hover_state_color pub fn hover_state_color(&self) -> Srgba { self.hover.clone().into() @@ -101,7 +94,7 @@ where self.focus.clone().into() } /// convert to srgba - pub fn into_srgba(self) -> Component { + pub fn into_srgba(self) -> Component { Component { base: self.base.into(), hover: self.hover.into(), @@ -119,7 +112,13 @@ where } /// helper for producing a component from a base color a neutral and an accent - pub fn colored_component(base: C, neutral: C, accent: C, hovered: C, pressed: C) -> Self { + pub fn colored_component( + base: Srgba, + neutral: Srgba, + accent: Srgba, + hovered: Srgba, + pressed: Srgba, + ) -> Self { let base: Srgba = base.into(); let mut base_50 = base.clone(); base_50.alpha *= 0.5; @@ -146,44 +145,42 @@ where /// helper for producing a button component pub fn colored_button( - base: C, - overlay: C, - on_button: C, - accent: C, - hovered: C, - pressed: C, + base: Srgba, + overlay: Srgba, + on_button: Srgba, + accent: Srgba, + hovered: Srgba, + pressed: Srgba, ) -> Self { let mut component = Component::colored_component(base, overlay, accent, hovered, pressed); component.on = on_button.clone(); - let mut on_disabled = on_button.into(); + let mut on_disabled = on_button; on_disabled.alpha = 0.5; - component.on_disabled = on_disabled.into(); + component.on_disabled = on_disabled; component } /// helper for producing a component color theme pub fn component( - base: C, - accent: C, - on_component: C, - hovered: C, - pressed: C, + base: Srgba, + accent: Srgba, + on_component: Srgba, + hovered: Srgba, + pressed: Srgba, is_high_contrast: bool, - border: C, + border: Srgba, ) -> Self { - let base = base.into(); let mut base_50 = base.clone(); base_50.alpha *= 0.5; - let mut on_20 = on_component.clone().into(); + let mut on_20 = on_component.clone(); let mut on_50 = on_20.clone(); on_20.alpha = 0.2; on_50.alpha = 0.5; - let border = border.into(); let mut disabled_border = border; disabled_border.alpha *= 0.5; diff --git a/cosmic-theme/src/model/light.ron b/cosmic-theme/src/model/light.ron index 07b5a64..7de84a0 100644 --- a/cosmic-theme/src/model/light.ron +++ b/cosmic-theme/src/model/light.ron @@ -1,116 +1 @@ -Light ( - ( - name: "cosmic-light", - blue: ( - c: "#00496D", - ), - red: ( - c: "#A0252B", - ), - green: ( - c: "#3B6E43", - ), - yellow: ( - c: "#966800", - ), - gray_1: ( - c: "#DDDDDD", - ), - gray_2: ( - c: "#E8E8E8", - ), - gray_3: ( - c: "#F3F3F3", - ), - neutral_0: ( - c: "#FFFFFF", - ), - neutral_1: ( - c: "#E2E2E2", - ), - neutral_2: ( - c: "#C6C6C6", - ), - neutral_3: ( - c: "#ABABAB", - ), - neutral_4: ( - c: "#919191", - ), - neutral_5: ( - c: "#777777", - ), - neutral_6: ( - c: "#5E5E5E", - ), - neutral_7: ( - c: "#474747", - ), - neutral_8: ( - c: "#303030", - ), - neutral_9: ( - c: "#1B1B1B", - ), - neutral_10: ( - c: "#000000", - ), - bright_green: ( - c: "#00572C", - ), - bright_red: ( - c: "#890418", - ), - bright_orange: ( - c: "#792C00", - ), - ext_warm_grey: ( - c: "#9B8E8A", - ), - ext_orange: ( - c: "#FBB86C", - ), - ext_yellow: ( - c: "#F7E062", - ), - ext_blue: ( - c: "#6ACAD8", - ), - ext_purple: ( - c: "#D58CFF", - ), - ext_pink: ( - c: "#FF9CDD", - ), - ext_indigo: ( - c: "#95C4FC", - ), - accent_blue: ( - c: "#00525A", - ), - accent_red: ( - c: "#78292E", - ), - accent_green: ( - c: "#185529", - ), - accent_warm_grey: ( - c: "#554742", - ), - accent_orange: ( - c: "#624000", - ), - accent_yellow: ( - c: "#534800", - ), - accent_purple: ( - c: "#68217C", - ), - accent_pink: ( - c: "#86043A", - ), - accent_indigo: ( - c: "#2E496D", - ), - ) -) +Light((name:"cosmic-light",blue:(red:0.0,green:0.28627452,blue:0.42745098,alpha:1.0),red:(red:0.627451,green:0.14509805,blue:0.16862746,alpha:1.0),green:(red:0.23137255,green:0.43137255,blue:0.2627451,alpha:1.0),yellow:(red:0.5882353,green:0.40784314,blue:0.0,alpha:1.0),gray_1:(red:0.8666667,green:0.8666667,blue:0.8666667,alpha:1.0),gray_2:(red:0.9098039,green:0.9098039,blue:0.9098039,alpha:1.0),gray_3:(red:0.9529412,green:0.9529412,blue:0.9529412,alpha:1.0),neutral_0:(red:1.0,green:1.0,blue:1.0,alpha:1.0),neutral_1:(red:0.8862745,green:0.8862745,blue:0.8862745,alpha:1.0),neutral_2:(red:0.7764706,green:0.7764706,blue:0.7764706,alpha:1.0),neutral_3:(red:0.67058825,green:0.67058825,blue:0.67058825,alpha:1.0),neutral_4:(red:0.5686275,green:0.5686275,blue:0.5686275,alpha:1.0),neutral_5:(red:0.46666667,green:0.46666667,blue:0.46666667,alpha:1.0),neutral_6:(red:0.36862746,green:0.36862746,blue:0.36862746,alpha:1.0),neutral_7:(red:0.2784314,green:0.2784314,blue:0.2784314,alpha:1.0),neutral_8:(red:0.1882353,green:0.1882353,blue:0.1882353,alpha:1.0),neutral_9:(red:0.105882354,green:0.105882354,blue:0.105882354,alpha:1.0),neutral_10:(red:0.0,green:0.0,blue:0.0,alpha:1.0),bright_green:(red:0.0,green:0.34117648,blue:0.17254902,alpha:1.0),bright_red:(red:0.5372549,green:0.015686275,blue:0.09411765,alpha:1.0),bright_orange:(red:0.4745098,green:0.17254902,blue:0.0,alpha:1.0),ext_warm_grey:(red:0.60784316,green:0.5568628,blue:0.5411765,alpha:1.0),ext_orange:(red:0.9843137,green:0.72156864,blue:0.42352942,alpha:1.0),ext_yellow:(red:0.96862745,green:0.8784314,blue:0.38431373,alpha:1.0),ext_blue:(red:0.41568628,green:0.7921569,blue:0.84705883,alpha:1.0),ext_purple:(red:0.8352941,green:0.54901963,blue:1.0,alpha:1.0),ext_pink:(red:1.0,green:0.6117647,blue:0.8666667,alpha:1.0),ext_indigo:(red:0.58431375,green:0.76862746,blue:0.9882353,alpha:1.0),accent_blue:(red:0.0,green:0.32156864,blue:0.3529412,alpha:1.0),accent_red:(red:0.47058824,green:0.16078432,blue:0.18039216,alpha:1.0),accent_green:(red:0.09411765,green:0.33333334,blue:0.16078432,alpha:1.0),accent_warm_grey:(red:0.33333334,green:0.2784314,blue:0.25882354,alpha:1.0),accent_orange:(red:0.38431373,green:0.2509804,blue:0.0,alpha:1.0),accent_yellow:(red:0.3254902,green:0.28235295,blue:0.0,alpha:1.0),accent_purple:(red:0.40784314,green:0.12941177,blue:0.4862745,alpha:1.0),accent_pink:(red:0.5254902,green:0.015686275,blue:0.22745098,alpha:1.0),accent_indigo:(red:0.18039216,green:0.28627452,blue:0.42745098,alpha:1.0))) \ No newline at end of file diff --git a/cosmic-theme/src/model/theme.rs b/cosmic-theme/src/model/theme.rs index f0be9d6..d454f30 100644 --- a/cosmic-theme/src/model/theme.rs +++ b/cosmic-theme/src/model/theme.rs @@ -2,7 +2,7 @@ use crate::{ composite::over, steps::*, Component, Container, CornerRadii, CosmicPalette, CosmicPaletteInner, Spacing, ThemeMode, DARK_PALETTE, LIGHT_PALETTE, NAME, }; -use cosmic_config::{Config, ConfigGet, ConfigSet, CosmicConfigEntry}; +use cosmic_config::{Config, CosmicConfigEntry}; use palette::{IntoColor, Srgb, Srgba}; use serde::{Deserialize, Serialize}; use std::num::NonZeroUsize; @@ -32,42 +32,49 @@ pub enum Layer { } /// Cosmic Theme data structure with all colors and its name -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] -pub struct Theme { +#[derive( + Clone, + Debug, + Serialize, + Deserialize, + PartialEq, + cosmic_config::cosmic_config_derive::CosmicConfigEntry, +)] +pub struct Theme { /// name of the theme pub name: String, /// background element colors - pub background: Container, + pub background: Container, /// primary element colors - pub primary: Container, + pub primary: Container, /// secondary element colors - pub secondary: Container, + pub secondary: Container, /// accent element colors - pub accent: Component, + pub accent: Component, /// suggested element colors - pub success: Component, + pub success: Component, /// destructive element colors - pub destructive: Component, + pub destructive: Component, /// warning element colors - pub warning: Component, + pub warning: Component, /// accent button element colors - pub accent_button: Component, + pub accent_button: Component, /// suggested button element colors - pub success_button: Component, + pub success_button: Component, /// destructive button element colors - pub destructive_button: Component, + pub destructive_button: Component, /// warning button element colors - pub warning_button: Component, + pub warning_button: Component, /// icon button element colors - pub icon_button: Component, + pub icon_button: Component, /// link button element colors - pub link_button: Component, + pub link_button: Component, /// text button element colors - pub text_button: Component, + pub text_button: Component, /// button component styling - pub button: Component, + pub button: Component, /// palette - pub palette: CosmicPaletteInner, + pub palette: CosmicPaletteInner, /// spacing pub spacing: Spacing, /// corner radii @@ -86,149 +93,7 @@ pub struct Theme { pub is_frosted: bool, } -impl cosmic_config::CosmicConfigEntry for Theme { - fn write_entry(&self, config: &Config) -> Result<(), cosmic_config::Error> { - let self_ = self.clone(); - // TODO do as transaction - let tx = config.transaction(); - - tx.set("name", self_.name)?; - tx.set("background", self_.background)?; - tx.set("primary", self_.primary)?; - tx.set("secondary", self_.secondary)?; - tx.set("accent", self_.accent)?; - tx.set("success", self_.success)?; - tx.set("destructive", self_.destructive)?; - tx.set("warning", self_.warning)?; - tx.set("accent_button", self_.accent_button)?; - tx.set("success_button", self_.success_button)?; - tx.set("warning_button", self_.warning_button)?; - tx.set("destructive_button", self_.destructive_button)?; - tx.set("icon_button", self_.icon_button)?; - tx.set("link_button", self_.link_button)?; - tx.set("text_button", self_.text_button)?; - tx.set("button", self_.button)?; - tx.set("palette", self_.palette)?; - tx.set("is_dark", self_.is_dark)?; - tx.set("is_high_contrast", self_.is_high_contrast)?; - tx.set("spacing", self_.spacing)?; - tx.set("corner_radii", self_.corner_radii)?; - tx.set("active_hint", self_.active_hint)?; - tx.set("gaps", self_.gaps)?; - tx.set("window_hint", self_.window_hint)?; - - tx.commit() - } - - fn get_entry(config: &Config) -> Result, Self)> { - let mut default = Self::default(); - let mut errors = Vec::new(); - - match config.get::("name") { - Ok(name) => default.name = name, - Err(e) => errors.push(e), - } - match config.get::>("background") { - Ok(background) => default.background = background, - Err(e) => errors.push(e), - } - match config.get::>("primary") { - Ok(primary) => default.primary = primary, - Err(e) => errors.push(e), - } - match config.get::>("secondary") { - Ok(secondary) => default.secondary = secondary, - Err(e) => errors.push(e), - } - match config.get::>("accent") { - Ok(accent) => default.accent = accent, - Err(e) => errors.push(e), - } - match config.get::>("success") { - Ok(success) => default.success = success, - Err(e) => errors.push(e), - } - match config.get::>("destructive") { - Ok(destructive) => default.destructive = destructive, - Err(e) => errors.push(e), - } - match config.get::>("warning") { - Ok(warning) => default.warning = warning, - Err(e) => errors.push(e), - } - match config.get::>("success_button") { - Ok(b) => default.success_button = b, - Err(e) => errors.push(e), - } - match config.get::>("accent_button") { - Ok(b) => default.accent_button = b, - Err(e) => errors.push(e), - } - match config.get::>("destructive_button") { - Ok(b) => default.destructive_button = b, - Err(e) => errors.push(e), - } - match config.get::>("warning_button") { - Ok(warning) => default.warning_button = warning, - Err(e) => errors.push(e), - } - match config.get::>("icon_button") { - Ok(b) => default.link_button = b, - Err(e) => errors.push(e), - } - match config.get::>("link_button") { - Ok(b) => default.link_button = b, - Err(e) => errors.push(e), - } - match config.get::>("text_button") { - Ok(b) => default.text_button = b, - Err(e) => errors.push(e), - } - match config.get::>("button") { - Ok(b) => default.button = b, - Err(e) => errors.push(e), - } - match config.get::>("palette") { - Ok(palette) => default.palette = palette, - Err(e) => errors.push(e), - } - match config.get::("is_dark") { - Ok(is_dark) => default.is_dark = is_dark, - Err(e) => errors.push(e), - } - match config.get::("is_high_contrast") { - Ok(is_high_contrast) => default.is_high_contrast = is_high_contrast, - Err(e) => errors.push(e), - } - match config.get::("spacing") { - Ok(spacing) => default.spacing = spacing, - Err(e) => errors.push(e), - } - match config.get::("corner_radii") { - Ok(corner_radii) => default.corner_radii = corner_radii, - Err(e) => errors.push(e), - } - match config.get::("active_hint") { - Ok(active_hint) => default.active_hint = active_hint, - Err(e) => errors.push(e), - } - match config.get::<(u32, u32)>("gaps") { - Ok(gaps) => default.gaps = gaps, - Err(e) => errors.push(e), - } - match config.get::>("window_hint") { - Ok(window_hint) => default.window_hint = window_hint, - Err(e) => errors.push(e), - } - if errors.is_empty() { - Ok(default) - } else { - Err((errors, default)) - } - } -} - -impl Default for Theme { +impl Default for Theme { fn default() -> Self { Self::dark_default() } @@ -240,7 +105,7 @@ pub trait LayeredTheme { fn set_layer(&mut self, layer: Layer); } -impl Theme { +impl Theme { /// version of the theme pub fn version() -> u64 { 1 @@ -260,9 +125,7 @@ impl Theme { pub fn light_config() -> Result { Config::new(LIGHT_THEME_ID, Self::version()) } -} -impl Theme { /// get the built in light theme pub fn light_default() -> Self { LIGHT_PALETTE.clone().into() @@ -510,12 +373,9 @@ impl Theme { } } -impl From> for Theme -where - CosmicPalette: Into>, -{ - fn from(p: CosmicPalette) -> Self { - ThemeBuilder::palette(p.into()).build() +impl From for Theme { + fn from(p: CosmicPalette) -> Self { + ThemeBuilder::palette(p).build() } } @@ -530,7 +390,7 @@ where )] pub struct ThemeBuilder { /// override the palette for the builder - pub palette: CosmicPalette, + pub palette: CosmicPalette, /// override spacing for the builder pub spacing: Spacing, /// override corner radii for the builder @@ -606,7 +466,7 @@ impl ThemeBuilder { /// Get a builder that is initialized with the default dark high contrast theme pub fn dark_high_contrast() -> Self { - let palette: CosmicPalette = DARK_PALETTE.to_owned().into(); + let palette: CosmicPalette = DARK_PALETTE.to_owned().into(); Self { palette: CosmicPalette::HighContrastDark(palette.inner()), ..Default::default() @@ -615,7 +475,7 @@ impl ThemeBuilder { /// Get a builder that is initialized with the default light high contrast theme pub fn light_high_contrast() -> Self { - let palette: CosmicPalette = LIGHT_PALETTE.to_owned().into(); + let palette: CosmicPalette = LIGHT_PALETTE.to_owned().into(); Self { palette: CosmicPalette::HighContrastLight(palette.inner()), ..Default::default() @@ -623,7 +483,7 @@ impl ThemeBuilder { } /// Get a builder that is initialized with the provided palette - pub fn palette(palette: CosmicPalette) -> Self { + pub fn palette(palette: CosmicPalette) -> Self { Self { palette, ..Default::default() @@ -691,7 +551,7 @@ impl ThemeBuilder { } /// build the theme - pub fn build(self) -> Theme { + pub fn build(self) -> Theme { let Self { mut palette, spacing, @@ -861,7 +721,7 @@ impl ThemeBuilder { button_hovered_overlay.alpha = 0.2; button_pressed_overlay.alpha = 0.5; - let mut theme: Theme = Theme { + let mut theme: Theme = Theme { name: palette.name().to_string(), primary: Container::new( primary_component, diff --git a/cosmic-theme/src/util.rs b/cosmic-theme/src/util.rs deleted file mode 100644 index 762017d..0000000 --- a/cosmic-theme/src/util.rs +++ /dev/null @@ -1,33 +0,0 @@ -use csscolorparser::Color; -use palette::Srgba; -use serde::{Deserialize, Serialize}; - -/// utility wrapper for serializing and deserializing colors with arbitrary CSS -#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] -pub struct CssColor { - c: Color, -} - -impl From for CssColor { - fn from(c: Srgba) -> Self { - Self { - c: Color { - r: c.red as f64, - g: c.green as f64, - b: c.blue as f64, - a: c.alpha as f64, - }, - } - } -} - -impl Into for CssColor { - fn into(self) -> Srgba { - Srgba::new( - self.c.r as f32, - self.c.g as f32, - self.c.b as f32, - self.c.a as f32, - ) - } -} diff --git a/examples/multi-window/src/window.rs b/examples/multi-window/src/window.rs index 4c9b140..b9b29c8 100644 --- a/examples/multi-window/src/window.rs +++ b/examples/multi-window/src/window.rs @@ -6,7 +6,7 @@ use cosmic::{ iced_core::{id, Alignment, Length, Point}, iced_widget::{column, container, scrollable, text, text_input}, widget::{button, cosmic_container}, - Command, + ApplicationExt, Command, }; #[derive(Debug, Clone, PartialEq)] @@ -107,6 +107,7 @@ impl cosmic::Application for MultiWindow { input_value: String::new(), }, ); + _ = self.set_window_title(format!("window_{}", count), id); spawn_window } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index db69117..0208dd6 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -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; -pub type CosmicTheme = cosmic_theme::Theme; +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 = 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 { - config_subscription::<_, crate::cosmic_theme::Theme>( + 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 cosmic_theme::LIGHT_THEME_ID } .into(), - crate::cosmic_theme::Theme::::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::::dark_config() + crate::cosmic_theme::Theme::dark_config() } else { - crate::cosmic_theme::Theme::::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 { + 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 { + 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, diff --git a/src/theme/style/button.rs b/src/theme/style/button.rs index 8ec901d..efa0abd 100644 --- a/src/theme/style/button.rs +++ b/src/theme/style/button.rs @@ -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>) -> (Color, Option, Option), + color: impl Fn(&Component) -> (Color, Option, Option), ) -> Appearance { let cosmic = theme.cosmic(); let mut corner_radii = &cosmic.corner_radii.radius_xl; diff --git a/src/theme/style/iced.rs b/src/theme/style/iced.rs index 3624c40..603f5a7 100644 --- a/src/theme/style/iced.rs +++ b/src/theme/style/iced.rs @@ -520,8 +520,7 @@ impl slider::StyleSheet for Theme { Slider::Standard => //TODO: no way to set rail thickness { - let cosmic: &cosmic_theme::Theme> = - self.cosmic(); + let cosmic: &cosmic_theme::Theme = self.cosmic(); slider::Appearance { rail: Rail { diff --git a/src/theme/style/segmented_button.rs b/src/theme/style/segmented_button.rs index cd6344d..8d6b2c1 100644 --- a/src/theme/style/segmented_button.rs +++ b/src/theme/style/segmented_button.rs @@ -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>) -> 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>, - ) -> 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>, - 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>, - 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>) -> 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>, - ) -> 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 { diff --git a/src/widget/context_drawer/overlay.rs b/src/widget/context_drawer/overlay.rs index a66f390..1096c89 100644 --- a/src/widget/context_drawer/overlay.rs +++ b/src/widget/context_drawer/overlay.rs @@ -34,7 +34,7 @@ where let mut node = self .content .as_widget() - .layout(&mut self.tree, renderer, &limits); + .layout(self.tree, renderer, &limits); let node_size = node.size(); node.move_to(Point { diff --git a/src/widget/menu/menu_inner.rs b/src/widget/menu/menu_inner.rs index a0f3439..a731c98 100644 --- a/src/widget/menu/menu_inner.rs +++ b/src/widget/menu/menu_inner.rs @@ -484,8 +484,8 @@ where (root, Vec::new()), |(menu_root, mut nodes), (_i, ms)| { let slice = ms.slice(bounds, overlay_offset, self.item_height); - let start_index = slice.start_index; - let end_index = slice.end_index; + let _start_index = slice.start_index; + let _end_index = slice.end_index; let children_node = ms.layout( overlay_offset, slice, diff --git a/src/widget/spin_button/model.rs b/src/widget/spin_button/model.rs index 2f4c7ef..e617bc8 100644 --- a/src/widget/spin_button/model.rs +++ b/src/widget/spin_button/model.rs @@ -133,6 +133,17 @@ impl Default for Model { } } +impl Default for Model { + fn default() -> Self { + Self { + value: 0, + step: 1, + min: u64::MIN, + max: u64::MAX, + } + } +} + impl Default for Model { fn default() -> Self { Self {