chore(cosmic-theme): fix linter warnings in derivation module

This commit is contained in:
Michael Aaron Murphy 2024-03-05 15:13:34 +01:00 committed by Jeremy Soller
parent 736eca1150
commit ed03565c0d

View file

@ -5,6 +5,7 @@ use crate::composite::over;
/// Theme Container colors of a theme, can be a theme background container, primary container, or secondary container /// Theme Container colors of a theme, can be a theme background container, primary container, or secondary container
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
#[must_use]
pub struct Container { pub struct Container {
/// the color of the container /// the color of the container
pub base: Srgba, pub base: Srgba,
@ -17,32 +18,22 @@ pub struct Container {
} }
impl Container { impl Container {
/// convert to srgba pub(crate) fn new(component: Component, base: Srgba, on: Srgba) -> Self {
pub fn into_srgba(self) -> Container { let mut divider_c = base;
Container {
base: self.base.into(),
component: self.component.into_srgba(),
divider: self.divider.into(),
on: self.on.into(),
}
}
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; divider_c.alpha = 0.2;
let divider = over(divider_c.clone(), bg.clone());
Self { Self {
base: bg, base,
component, component,
divider: divider.into(), divider: over(divider_c, base),
on: on_bg, on,
} }
} }
} }
/// The colors for a widget of the Cosmic theme /// The colors for a widget of the Cosmic theme
#[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)] #[derive(Clone, PartialEq, Debug, Default, Deserialize, Serialize)]
#[must_use]
pub struct Component { pub struct Component {
/// The base color of the widget /// The base color of the widget
pub base: Srgba, pub base: Srgba,
@ -72,43 +63,32 @@ pub struct Component {
pub disabled_border: Srgba, pub disabled_border: Srgba,
} }
#[allow(clippy::must_use_candidate)]
#[allow(clippy::doc_markdown)]
impl Component { impl Component {
/// get @hover_state_color /// get @hover_state_color
pub fn hover_state_color(&self) -> Srgba { pub fn hover_state_color(&self) -> Srgba {
self.hover.clone().into() self.hover
} }
/// get @pressed_state_color /// get @pressed_state_color
pub fn pressed_state_color(&self) -> Srgba { pub fn pressed_state_color(&self) -> Srgba {
self.pressed.clone().into() self.pressed
} }
/// get @selected_state_color /// get @selected_state_color
pub fn selected_state_color(&self) -> Srgba { pub fn selected_state_color(&self) -> Srgba {
self.selected.clone().into() self.selected
} }
/// get @selected_state_text_color /// get @selected_state_text_color
pub fn selected_state_text_color(&self) -> Srgba { pub fn selected_state_text_color(&self) -> Srgba {
self.selected_text.clone().into() self.selected_text
} }
/// get @focus_color /// get @focus_color
pub fn focus_color(&self) -> Srgba { pub fn focus_color(&self) -> Srgba {
self.focus.clone().into() self.focus
}
/// convert to srgba
pub fn into_srgba(self) -> Component {
Component {
base: self.base.into(),
hover: self.hover.into(),
pressed: self.pressed.into(),
selected: self.selected.into(),
selected_text: self.selected_text.into(),
focus: self.focus.into(),
divider: self.divider.into(),
on: self.on.into(),
disabled: self.disabled.into(),
on_disabled: self.on_disabled.into(),
border: self.border.into(),
disabled_border: self.disabled_border.into(),
}
} }
/// helper for producing a component from a base color a neutral and an accent /// helper for producing a component from a base color a neutral and an accent
@ -119,27 +99,27 @@ impl Component {
hovered: Srgba, hovered: Srgba,
pressed: Srgba, pressed: Srgba,
) -> Self { ) -> Self {
let base: Srgba = base.into(); let base: Srgba = base;
let mut base_50 = base.clone(); let mut base_50 = base;
base_50.alpha *= 0.5; base_50.alpha *= 0.5;
let on_20 = neutral.clone(); let on_20 = neutral;
let mut on_50: Srgba = on_20.clone().into(); let mut on_50: Srgba = on_20;
on_50.alpha = 0.5; on_50.alpha = 0.5;
Component { Component {
base: base.clone().into(), base,
hover: over(hovered.clone(), base).into(), hover: over(hovered, base),
pressed: over(pressed, base).into(), pressed: over(pressed, base),
selected: over(hovered, base).into(), selected: over(hovered, base),
selected_text: accent.clone(), selected_text: accent,
divider: on_20, divider: on_20,
on: neutral, on: neutral,
disabled: over(base_50, base).into(), disabled: over(base_50, base),
on_disabled: over(on_50, base).into(), on_disabled: over(on_50, base),
focus: accent, focus: accent,
border: base.into(), border: base,
disabled_border: base_50.into(), disabled_border: base_50,
} }
} }
@ -153,7 +133,7 @@ impl Component {
pressed: Srgba, pressed: Srgba,
) -> Self { ) -> Self {
let mut component = Component::colored_component(base, overlay, accent, hovered, pressed); let mut component = Component::colored_component(base, overlay, accent, hovered, pressed);
component.on = on_button.clone(); component.on = on_button;
let mut on_disabled = on_button; let mut on_disabled = on_button;
on_disabled.alpha = 0.5; on_disabled.alpha = 0.5;
@ -163,6 +143,7 @@ impl Component {
} }
/// helper for producing a component color theme /// helper for producing a component color theme
#[allow(clippy::self_named_constructors)]
pub fn component( pub fn component(
base: Srgba, base: Srgba,
accent: Srgba, accent: Srgba,
@ -172,11 +153,11 @@ impl Component {
is_high_contrast: bool, is_high_contrast: bool,
border: Srgba, border: Srgba,
) -> Self { ) -> Self {
let mut base_50 = base.clone(); let mut base_50 = base;
base_50.alpha *= 0.5; base_50.alpha *= 0.5;
let mut on_20 = on_component.clone(); let mut on_20 = on_component;
let mut on_50 = on_20.clone(); let mut on_50 = on_20;
on_20.alpha = 0.2; on_20.alpha = 0.2;
on_50.alpha = 0.5; on_50.alpha = 0.5;
@ -185,34 +166,30 @@ impl Component {
disabled_border.alpha *= 0.5; disabled_border.alpha *= 0.5;
Component { Component {
base: base.clone().into(), base,
hover: if base.alpha < 0.001 { hover: if base.alpha < 0.001 {
hovered.clone() hovered
} else { } else {
over(hovered.clone(), base).into() over(hovered, base)
}, },
pressed: if base.alpha < 0.001 { pressed: if base.alpha < 0.001 {
pressed.clone() pressed
} else { } else {
over(pressed.clone(), base).into() over(pressed, base)
}, },
selected: if base.alpha < 0.001 { selected: if base.alpha < 0.001 {
hovered.clone() hovered
} else { } else {
over(hovered.clone(), base).into() over(hovered, base)
}, },
selected_text: accent.clone(), selected_text: accent,
focus: accent.clone(), focus: accent,
divider: if is_high_contrast { divider: if is_high_contrast { on_50 } else { on_20 },
on_50.clone().into() on: on_component,
} else { disabled: over(base_50, base),
on_20.into() on_disabled: over(on_50, base),
}, border,
on: on_component.clone(), disabled_border,
disabled: over(base_50, base).into(),
on_disabled: over(on_50, base).into(),
border: border.into(),
disabled_border: disabled_border.into(),
} }
} }
} }