summaryrefslogtreecommitdiff
path: root/crates/material_theme/src
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-04-22 14:33:36 +0200
committerpml68 <contact@pml68.dev>2025-04-22 14:33:36 +0200
commitc3c05cef555de305729e53cef8b8e660e31eaf27 (patch)
treea8f590846fe9b122361a12607e49e1be91d5bc72 /crates/material_theme/src
parentfeat: use `pane_grid::Controls` for PaneGrid titlebar controls (diff)
downloadiced-builder-c3c05cef555de305729e53cef8b8e660e31eaf27.tar.gz
refactor: apply some clippy suggestions
Diffstat (limited to 'crates/material_theme/src')
-rw-r--r--crates/material_theme/src/button.rs4
-rw-r--r--crates/material_theme/src/checkbox.rs6
-rw-r--r--crates/material_theme/src/lib.rs5
-rw-r--r--crates/material_theme/src/utils.rs6
4 files changed, 14 insertions, 7 deletions
diff --git a/crates/material_theme/src/button.rs b/crates/material_theme/src/button.rs
index 21d77b7..e1369eb 100644
--- a/crates/material_theme/src/button.rs
+++ b/crates/material_theme/src/button.rs
@@ -143,7 +143,7 @@ pub fn outlined(theme: &Theme, status: Status) -> Style {
Status::Active | Status::Pressed | Status::Hovered => Border {
color: outline,
width: 1.0,
- radius: 400.0.into(),
+ radius: 400.into(),
},
Status::Disabled => Border {
color: Color {
@@ -151,7 +151,7 @@ pub fn outlined(theme: &Theme, status: Status) -> Style {
..disabled
},
width: 1.0,
- radius: 400.0.into(),
+ radius: 400.into(),
},
};
diff --git a/crates/material_theme/src/checkbox.rs b/crates/material_theme/src/checkbox.rs
index ac1f974..ff038b0 100644
--- a/crates/material_theme/src/checkbox.rs
+++ b/crates/material_theme/src/checkbox.rs
@@ -18,7 +18,7 @@ impl Catalog for Theme {
pub fn styled(
background_color: Color,
- background_hover: Option<Color>,
+ background_unchecked: Option<Color>,
icon_color: Color,
border_color: Color,
text_color: Option<Color>,
@@ -28,7 +28,7 @@ pub fn styled(
background: Background::Color(if is_checked {
background_color
} else {
- background_hover.unwrap_or(Color::TRANSPARENT)
+ background_unchecked.unwrap_or(Color::TRANSPARENT)
}),
icon_color,
border: if is_checked {
@@ -37,7 +37,7 @@ pub fn styled(
Border {
color: border_color,
width: 2.0,
- radius: border::radius(2),
+ radius: 2.into(),
}
},
text_color,
diff --git a/crates/material_theme/src/lib.rs b/crates/material_theme/src/lib.rs
index 416c958..13f13b1 100644
--- a/crates/material_theme/src/lib.rs
+++ b/crates/material_theme/src/lib.rs
@@ -24,6 +24,7 @@ pub mod slider;
#[cfg(feature = "svg")]
pub mod svg;
pub mod text;
+pub mod text_editor;
pub mod text_input;
pub mod toggler;
pub mod utils;
@@ -59,7 +60,7 @@ impl Clone for Theme {
}
fn clone_from(&mut self, source: &Self) {
- self.name = source.name.clone();
+ self.name.clone_from(&source.name);
self.colorscheme = source.colorscheme;
}
}
@@ -142,6 +143,7 @@ pub struct ColorScheme {
pub scrim: Color,
}
+#[allow(clippy::cast_precision_loss)]
macro_rules! from_argb {
($hex:expr) => {{
let hex = $hex as u32;
@@ -155,6 +157,7 @@ macro_rules! from_argb {
}};
}
+#[allow(clippy::cast_precision_loss)]
impl ColorScheme {
const DARK: Self = Self {
primary: Primary {
diff --git a/crates/material_theme/src/utils.rs b/crates/material_theme/src/utils.rs
index f35396f..5ad137e 100644
--- a/crates/material_theme/src/utils.rs
+++ b/crates/material_theme/src/utils.rs
@@ -1,5 +1,7 @@
use iced_widget::core::{Color, Shadow, Vector};
+const COLOR_ERROR_MARGIN: f32 = 0.0001;
+
pub const HOVERED_LAYER_OPACITY: f32 = 0.08;
pub const PRESSED_LAYER_OPACITY: f32 = 0.1;
@@ -95,7 +97,9 @@ pub fn mix(color1: Color, color2: Color, p2: f32) -> Color {
let p1 = 1.0 - p2;
- if color1.a != 1.0 || color2.a != 1.0 {
+ if (color1.a - 1.0).abs() > COLOR_ERROR_MARGIN
+ || (color2.a - 1.0) > 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);