summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-01-20 18:34:15 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-01-20 18:34:15 +0700
commit93285d85b0413553286f8cc48cba4036260e5be1 (patch)
tree900fa17b6d81a5dc15ffdb29507c3fe15e9c99d6 /native
parenta3744ec97a462557ab9a3d2509f02263f425fd28 (diff)
downloadiced-93285d85b0413553286f8cc48cba4036260e5be1.tar.gz
iced-93285d85b0413553286f8cc48cba4036260e5be1.tar.bz2
iced-93285d85b0413553286f8cc48cba4036260e5be1.zip
Remove ambiguous `text_color` attributes for `Checkbox` and `Radio`
Instead, always use a `StyleSheet`.
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/checkbox.rs14
-rw-r--r--native/src/widget/radio.rs30
2 files changed, 14 insertions, 30 deletions
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index a314140c..fff65a40 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -10,8 +10,8 @@ use crate::text;
use crate::touch;
use crate::widget::{self, Row, Text};
use crate::{
- Alignment, Clipboard, Color, Element, Hasher, Layout, Length, Point,
- Rectangle, Shell, Widget,
+ Alignment, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle,
+ Shell, Widget,
};
pub use iced_style::checkbox::{Style, StyleSheet};
@@ -43,7 +43,6 @@ pub struct Checkbox<'a, Message, Renderer: text::Renderer> {
spacing: u16,
text_size: Option<u16>,
font: Renderer::Font,
- text_color: Option<Color>,
style_sheet: Box<dyn StyleSheet + 'a>,
}
@@ -75,7 +74,6 @@ impl<'a, Message, Renderer: text::Renderer> Checkbox<'a, Message, Renderer> {
spacing: Self::DEFAULT_SPACING,
text_size: None,
font: Renderer::Font::default(),
- text_color: None,
style_sheet: Default::default(),
}
}
@@ -112,12 +110,6 @@ impl<'a, Message, Renderer: text::Renderer> Checkbox<'a, Message, Renderer> {
self
}
- /// Sets the text color of the [`Checkbox`] button.
- pub fn text_color(mut self, color: Color) -> Self {
- self.text_color = Some(color);
- self
- }
-
/// Sets the style of the [`Checkbox`].
pub fn style(
mut self,
@@ -264,7 +256,7 @@ where
&self.label,
self.font.clone(),
self.text_size,
- self.text_color.or(Some(custom_style.text_color)),
+ custom_style.text_color,
alignment::Horizontal::Left,
alignment::Vertical::Center,
);
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index c6cc46ed..c4992764 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -51,7 +51,6 @@ pub struct Radio<'a, Message, Renderer: text::Renderer> {
size: u16,
spacing: u16,
text_size: Option<u16>,
- text_color: Option<Color>,
font: Renderer::Font,
style_sheet: Box<dyn StyleSheet + 'a>,
}
@@ -92,7 +91,6 @@ where
size: Self::DEFAULT_SIZE,
spacing: Self::DEFAULT_SPACING, //15
text_size: None,
- text_color: None,
font: Default::default(),
style_sheet: Default::default(),
}
@@ -122,12 +120,6 @@ where
self
}
- /// Sets the text color of the [`Radio`] button.
- pub fn text_color(mut self, color: Color) -> Self {
- self.text_color = Some(color);
- self
- }
-
/// Sets the text font of the [`Radio`] button.
pub fn font(mut self, font: Renderer::Font) -> Self {
self.font = font;
@@ -231,6 +223,12 @@ where
let mut children = layout.children();
+ let custom_style = if is_mouse_over {
+ self.style_sheet.hovered()
+ } else {
+ self.style_sheet.active()
+ };
+
{
let layout = children.next().unwrap();
let bounds = layout.bounds();
@@ -238,20 +236,14 @@ where
let size = bounds.width;
let dot_size = size / 2.0;
- let style = if is_mouse_over {
- self.style_sheet.hovered()
- } else {
- self.style_sheet.active()
- };
-
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: size / 2.0,
- border_width: style.border_width,
- border_color: style.border_color,
+ border_width: custom_style.border_width,
+ border_color: custom_style.border_color,
},
- style.background,
+ custom_style.background,
);
if self.is_selected {
@@ -267,7 +259,7 @@ where
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
- style.dot_color,
+ custom_style.dot_color,
);
}
}
@@ -282,7 +274,7 @@ where
&self.label,
self.font.clone(),
self.text_size,
- self.text_color,
+ custom_style.text_color,
alignment::Horizontal::Left,
alignment::Vertical::Center,
);