refactor: cosmic-config granular key updates and remove unused generics from cosmic-theme

This commit is contained in:
Ashley Wulber 2023-12-12 19:53:17 -05:00 committed by Michael Murphy
parent ef657fb19d
commit a4d1b1b651
18 changed files with 233 additions and 699 deletions

View file

@ -9,4 +9,4 @@ proc-macro = true
[dependencies]
syn = "1.0"
quote = "1.0"
quote = "1.0"

View file

@ -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<T: AsRef<str>>(&mut self, config: &cosmic_config::Config, changed_keys: &[T]) -> (Vec<cosmic_config::Error>, 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)
}
}
};

View file

@ -325,7 +325,7 @@ impl<'a> ConfigSet for ConfigTransaction<'a> {
#[cfg(feature = "subscription")]
pub enum ConfigState<T> {
Init(Cow<'static, str>, u64, bool),
Waiting(T, RecommendedWatcher, mpsc::Receiver<()>, Config),
Waiting(T, RecommendedWatcher, mpsc::Receiver<Vec<String>>, Config),
Failed,
}
@ -342,6 +342,12 @@ where
{
fn write_entry(&self, config: &Config) -> Result<(), crate::Error>;
fn get_entry(config: &Config) -> Result<Self, (Vec<crate::Error>, Self)>;
/// Returns the keys that were updated
fn update_keys<T: AsRef<str>>(
&mut self,
config: &Config,
changed_keys: &[T],
) -> (Vec<crate::Error>, 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,

View file

@ -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";

View file

@ -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<CssColor> =
pub static ref LIGHT_PALETTE: CosmicPalette =
ron::from_str(include_str!("light.ron")).unwrap();
/// built in dark palette
pub static ref DARK_PALETTE: CosmicPalette<CssColor> =
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<C> {
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub enum CosmicPalette {
/// Dark mode
Dark(CosmicPaletteInner<C>),
Dark(CosmicPaletteInner),
/// Light mode
Light(CosmicPaletteInner<C>),
Light(CosmicPaletteInner),
/// High contrast light mode
HighContrastLight(CosmicPaletteInner<C>),
HighContrastLight(CosmicPaletteInner),
/// High contrast dark mode
HighContrastDark(CosmicPaletteInner<C>),
HighContrastDark(CosmicPaletteInner),
}
impl<C> CosmicPalette<C> {
impl CosmicPalette {
/// extract the inner palette
pub fn inner(self) -> CosmicPaletteInner<C> {
pub fn inner(self) -> CosmicPaletteInner {
match self {
CosmicPalette::Dark(p) => p,
CosmicPalette::Light(p) => p,
@ -40,8 +36,8 @@ impl<C> CosmicPalette<C> {
}
}
impl<C> AsMut<CosmicPaletteInner<C>> for CosmicPalette<C> {
fn as_mut(&mut self) -> &mut CosmicPaletteInner<C> {
impl AsMut<CosmicPaletteInner> for CosmicPalette {
fn as_mut(&mut self) -> &mut CosmicPaletteInner {
match self {
CosmicPalette::Dark(p) => p,
CosmicPalette::Light(p) => p,
@ -51,11 +47,8 @@ impl<C> AsMut<CosmicPaletteInner<C>> for CosmicPalette<C> {
}
}
impl<C> AsRef<CosmicPaletteInner<C>> for CosmicPalette<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + Serialize + DeserializeOwned,
{
fn as_ref(&self) -> &CosmicPaletteInner<C> {
impl AsRef<CosmicPaletteInner> for CosmicPalette {
fn as_ref(&self) -> &CosmicPaletteInner {
match self {
CosmicPalette::Dark(p) => p,
CosmicPalette::Light(p) => p,
@ -65,10 +58,7 @@ where
}
}
impl<C> CosmicPalette<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + Serialize + DeserializeOwned,
{
impl CosmicPalette {
/// check if the palette is dark
pub fn is_dark(&self) -> bool {
match self {
@ -86,156 +76,105 @@ where
}
}
impl<C> Default for CosmicPalette<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + 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<C> {
#[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<CosmicPaletteInner<CssColor>> for CosmicPaletteInner<Srgba> {
fn from(p: CosmicPaletteInner<CssColor>) -> 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<C> CosmicPalette<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + Serialize + DeserializeOwned,
{
impl CosmicPalette {
/// name of the palette
pub fn name(&self) -> &str {
match &self {
@ -246,14 +185,3 @@ where
}
}
}
impl Into<CosmicPalette<Srgba>> for CosmicPalette<CssColor> {
fn into(self) -> CosmicPalette<Srgba> {
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()),
}
}
}

View file

@ -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)))

View file

@ -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<C> {
#[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<C>,
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<C> Container<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + Serialize + DeserializeOwned,
{
impl Container {
/// convert to srgba
pub fn into_srgba(self) -> Container<Srgba> {
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<C>, 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<C> {
#[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<C> Component<C>
where
C: Clone + fmt::Debug + Default + Into<Srgba> + From<Srgba> + 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<Srgba> {
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;

View file

@ -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)))

View file

@ -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<C> {
#[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<C>,
pub background: Container,
/// primary element colors
pub primary: Container<C>,
pub primary: Container,
/// secondary element colors
pub secondary: Container<C>,
pub secondary: Container,
/// accent element colors
pub accent: Component<C>,
pub accent: Component,
/// suggested element colors
pub success: Component<C>,
pub success: Component,
/// destructive element colors
pub destructive: Component<C>,
pub destructive: Component,
/// warning element colors
pub warning: Component<C>,
pub warning: Component,
/// accent button element colors
pub accent_button: Component<C>,
pub accent_button: Component,
/// suggested button element colors
pub success_button: Component<C>,
pub success_button: Component,
/// destructive button element colors
pub destructive_button: Component<C>,
pub destructive_button: Component,
/// warning button element colors
pub warning_button: Component<C>,
pub warning_button: Component,
/// icon button element colors
pub icon_button: Component<C>,
pub icon_button: Component,
/// link button element colors
pub link_button: Component<C>,
pub link_button: Component,
/// text button element colors
pub text_button: Component<C>,
pub text_button: Component,
/// button component styling
pub button: Component<C>,
pub button: Component,
/// palette
pub palette: CosmicPaletteInner<C>,
pub palette: CosmicPaletteInner,
/// spacing
pub spacing: Spacing,
/// corner radii
@ -86,149 +93,7 @@ pub struct Theme<C> {
pub is_frosted: bool,
}
impl cosmic_config::CosmicConfigEntry for Theme<Srgba> {
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, (Vec<cosmic_config::Error>, Self)> {
let mut default = Self::default();
let mut errors = Vec::new();
match config.get::<String>("name") {
Ok(name) => default.name = name,
Err(e) => errors.push(e),
}
match config.get::<Container<Srgba>>("background") {
Ok(background) => default.background = background,
Err(e) => errors.push(e),
}
match config.get::<Container<Srgba>>("primary") {
Ok(primary) => default.primary = primary,
Err(e) => errors.push(e),
}
match config.get::<Container<Srgba>>("secondary") {
Ok(secondary) => default.secondary = secondary,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("accent") {
Ok(accent) => default.accent = accent,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("success") {
Ok(success) => default.success = success,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("destructive") {
Ok(destructive) => default.destructive = destructive,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("warning") {
Ok(warning) => default.warning = warning,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("success_button") {
Ok(b) => default.success_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("accent_button") {
Ok(b) => default.accent_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("destructive_button") {
Ok(b) => default.destructive_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("warning_button") {
Ok(warning) => default.warning_button = warning,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("icon_button") {
Ok(b) => default.link_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("link_button") {
Ok(b) => default.link_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("text_button") {
Ok(b) => default.text_button = b,
Err(e) => errors.push(e),
}
match config.get::<Component<Srgba>>("button") {
Ok(b) => default.button = b,
Err(e) => errors.push(e),
}
match config.get::<CosmicPaletteInner<Srgba>>("palette") {
Ok(palette) => default.palette = palette,
Err(e) => errors.push(e),
}
match config.get::<bool>("is_dark") {
Ok(is_dark) => default.is_dark = is_dark,
Err(e) => errors.push(e),
}
match config.get::<bool>("is_high_contrast") {
Ok(is_high_contrast) => default.is_high_contrast = is_high_contrast,
Err(e) => errors.push(e),
}
match config.get::<Spacing>("spacing") {
Ok(spacing) => default.spacing = spacing,
Err(e) => errors.push(e),
}
match config.get::<CornerRadii>("corner_radii") {
Ok(corner_radii) => default.corner_radii = corner_radii,
Err(e) => errors.push(e),
}
match config.get::<u32>("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::<Option<Srgb>>("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<Srgba> {
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<C> Theme<C> {
impl Theme {
/// version of the theme
pub fn version() -> u64 {
1
@ -260,9 +125,7 @@ impl<C> Theme<C> {
pub fn light_config() -> Result<Config, cosmic_config::Error> {
Config::new(LIGHT_THEME_ID, Self::version())
}
}
impl Theme<Srgba> {
/// get the built in light theme
pub fn light_default() -> Self {
LIGHT_PALETTE.clone().into()
@ -510,12 +373,9 @@ impl Theme<Srgba> {
}
}
impl<C> From<CosmicPalette<C>> for Theme<Srgba>
where
CosmicPalette<C>: Into<CosmicPalette<Srgba>>,
{
fn from(p: CosmicPalette<C>) -> Self {
ThemeBuilder::palette(p.into()).build()
impl From<CosmicPalette> 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<Srgba>,
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<Srgba> = 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<Srgba> = 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<Srgba>) -> 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<Srgba> {
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<Srgba> = Theme {
let mut theme: Theme = Theme {
name: palette.name().to_string(),
primary: Container::new(
primary_component,

View file

@ -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<Srgba> 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<Srgba> 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,
)
}
}

View file

@ -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
}

View file

@ -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,

View file

@ -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;

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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,

View file

@ -133,6 +133,17 @@ impl Default for Model<usize> {
}
}
impl Default for Model<u64> {
fn default() -> Self {
Self {
value: 0,
step: 1,
min: u64::MIN,
max: u64::MAX,
}
}
}
impl Default for Model<Decimal> {
fn default() -> Self {
Self {