diff options
author | 2021-11-15 15:35:27 +0700 | |
---|---|---|
committer | 2021-11-15 15:35:27 +0700 | |
commit | 27bc2b90867c3c846934c888322ae9d4804296e4 (patch) | |
tree | fa78f9fdd6020ecd7e18c681b88a1ce3846d79ce | |
parent | 04f3a3d81b07733794a657652dc070e90e3b3306 (diff) | |
parent | 1a6c912332b619bcb70df8ee99808175b7d4aad0 (diff) | |
download | iced-27bc2b90867c3c846934c888322ae9d4804296e4.tar.gz iced-27bc2b90867c3c846934c888322ae9d4804296e4.tar.bz2 iced-27bc2b90867c3c846934c888322ae9d4804296e4.zip |
Merge pull request #1116 from gonsor/checkbox_text_color
Add checkbox text_color styling
-rw-r--r-- | examples/styling/src/main.rs | 1 | ||||
-rw-r--r-- | native/src/widget/checkbox.rs | 24 | ||||
-rw-r--r-- | style/src/checkbox.rs | 2 |
3 files changed, 15 insertions, 12 deletions
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 4e319285..065764b3 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -528,6 +528,7 @@ mod style { background: if is_checked { ACTIVE } else { SURFACE } .into(), checkmark_color: Color::WHITE, + text_color: Color::BLACK, border_radius: 2.0, border_width: 1.0, border_color: ACTIVE, diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 0d4a43ec..81611426 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -216,24 +216,24 @@ where let mut children = layout.children(); + let custom_style = if is_mouse_over { + self.style_sheet.hovered(self.is_checked) + } else { + self.style_sheet.active(self.is_checked) + }; + { let layout = children.next().unwrap(); let bounds = layout.bounds(); - let style = if is_mouse_over { - self.style_sheet.hovered(self.is_checked) - } else { - self.style_sheet.active(self.is_checked) - }; - renderer.fill_quad( renderer::Quad { bounds, - border_radius: style.border_radius, - border_width: style.border_width, - border_color: style.border_color, + border_radius: custom_style.border_radius, + border_width: custom_style.border_width, + border_color: custom_style.border_color, }, - style.background, + custom_style.background, ); if self.is_checked { @@ -246,7 +246,7 @@ where y: bounds.center_y(), ..bounds }, - color: style.checkmark_color, + color: custom_style.checkmark_color, horizontal_alignment: alignment::Horizontal::Center, vertical_alignment: alignment::Vertical::Center, }); @@ -263,7 +263,7 @@ where &self.label, self.font, self.text_size, - self.text_color, + self.text_color.or(Some(custom_style.text_color)), alignment::Horizontal::Left, alignment::Vertical::Center, ); diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs index f8bc6241..77aae42b 100644 --- a/style/src/checkbox.rs +++ b/style/src/checkbox.rs @@ -6,6 +6,7 @@ use iced_core::{Background, Color}; pub struct Style { pub background: Background, pub checkmark_color: Color, + pub text_color: Color, pub border_radius: f32, pub border_width: f32, pub border_color: Color, @@ -25,6 +26,7 @@ impl StyleSheet for Default { Style { background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), checkmark_color: Color::from_rgb(0.3, 0.3, 0.3), + text_color: Color::BLACK, border_radius: 5.0, border_width: 1.0, border_color: Color::from_rgb(0.6, 0.6, 0.6), |