diff options
| author | pml68 <contact@pml68.dev> | 2025-06-27 03:32:19 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-06-27 03:32:19 +0200 |
| commit | 71d91a74918e1f848911a8e095c94cfd41bf77b1 (patch) | |
| tree | 56a280ce539c2ca2da1eb19ae015a807e69ff515 | |
| parent | feat: make `System` variant non-reactive (diff) | |
| download | iced_material-71d91a74918e1f848911a8e095c94cfd41bf77b1.tar.gz | |
feat: add rustfmt configuration
| -rw-r--r-- | rustfmt.toml | 3 | ||||
| -rw-r--r-- | src/lib.rs | 17 | ||||
| -rw-r--r-- | src/utils.rs | 19 |
3 files changed, 29 insertions, 10 deletions
diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e029395 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +edition = "2024" +group_imports = "StdExternalCrate" +max_width = 80 @@ -2,7 +2,7 @@ use std::borrow::Cow; use std::sync::LazyLock; use iced_widget::core::theme::{Base, Style}; -use iced_widget::core::{color, Color}; +use iced_widget::core::{Color, color}; use utils::{lightness, mix}; pub mod button; @@ -46,8 +46,9 @@ macro_rules! from_argb { } #[cfg(feature = "system-theme")] -pub static SYSTEM_IS_DARK: LazyLock<bool> = - LazyLock::new(|| dark_light::detect().is_ok_and(|mode| mode == dark_light::Mode::Dark)); +pub static SYSTEM_IS_DARK: LazyLock<bool> = LazyLock::new(|| { + dark_light::detect().is_ok_and(|mode| mode == dark_light::Mode::Dark) +}); #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, PartialEq)] @@ -69,7 +70,10 @@ impl Theme { Self::System, ]; - pub fn new(name: impl Into<Cow<'static, str>>, colorscheme: ColorScheme) -> Self { + pub fn new( + name: impl Into<Cow<'static, str>>, + colorscheme: ColorScheme, + ) -> Self { Self::Custom(Custom { name: name.into(), is_dark: lightness(colorscheme.surface.color) <= 0.5, @@ -77,7 +81,10 @@ impl Theme { }) } - pub const fn new_const(name: &'static str, colorscheme: ColorScheme) -> Self { + pub const fn new_const( + name: &'static str, + colorscheme: ColorScheme, + ) -> Self { Self::Custom(Custom { name: Cow::Borrowed(name), is_dark: lightness(colorscheme.surface.color) <= 0.5, diff --git a/src/utils.rs b/src/utils.rs index 7da755a..c0b0f0b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -48,7 +48,8 @@ pub fn parse_argb(s: &str) -> Option<Color> { let hex = s.strip_prefix('#').unwrap_or(s); let parse_channel = |from: usize, to: usize| { - let num = usize::from_str_radix(&hex[from..=to], 16).ok()? as f32 / 255.0; + let num = + usize::from_str_radix(&hex[from..=to], 16).ok()? as f32 / 255.0; // If we only got half a byte (one letter), expand it into a full byte (two letters) Some(if from == to { num + num * 16.0 } else { num }) @@ -114,13 +115,16 @@ pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { let p1 = 1.0 - p2; - if (color1.a - 1.0).abs() > COLOR_ERROR_MARGIN || (color2.a - 1.0).abs() > COLOR_ERROR_MARGIN { + if (color1.a - 1.0).abs() > COLOR_ERROR_MARGIN + || (color2.a - 1.0).abs() > COLOR_ERROR_MARGIN + { let a = color1.a * p1 + color2.a * p2; if a > 0.0 { let c1 = color1.into_linear().map(|c| c * color1.a * p1); let c2 = color2.into_linear().map(|c| c * color2.a * p2); - let [r, g, b] = [c1[0] + c2[0], c1[1] + c2[1], c1[2] + c2[2]].map(|u| u / a); + let [r, g, b] = + [c1[0] + c2[0], c1[1] + c2[1], c1[2] + c2[2]].map(|u| u / a); return Color::from_linear_rgba(r, g, b, a); } @@ -129,12 +133,17 @@ pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { let c1 = color1.into_linear().map(|c| c * p1); let c2 = color2.into_linear().map(|c| c * p2); - Color::from_linear_rgba(c1[0] + c2[0], c1[1] + c2[1], c1[2] + c2[2], c1[3] + c2[3]) + Color::from_linear_rgba( + c1[0] + c2[0], + c1[1] + c2[1], + c1[2] + c2[2], + c1[3] + c2[3], + ) } #[cfg(test)] mod tests { - use super::{mix, Color}; + use super::{Color, mix}; #[test] fn mixing() { |
