Make Color optional instead of Default
This commit is contained in:
parent
8879ccb5f5
commit
ee2d40d77f
4 changed files with 15 additions and 24 deletions
|
|
@ -72,7 +72,7 @@ impl text::Renderer<Color> for Renderer<'_> {
|
||||||
bounds: iced::Rectangle<f32>,
|
bounds: iced::Rectangle<f32>,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: f32,
|
size: f32,
|
||||||
color: Color,
|
color: Option<Color>,
|
||||||
horizontal_alignment: text::HorizontalAlignment,
|
horizontal_alignment: text::HorizontalAlignment,
|
||||||
_vertical_alignment: text::VerticalAlignment,
|
_vertical_alignment: text::VerticalAlignment,
|
||||||
) {
|
) {
|
||||||
|
|
@ -101,7 +101,7 @@ impl text::Renderer<Color> for Renderer<'_> {
|
||||||
x: bounds.x,
|
x: bounds.x,
|
||||||
y: bounds.y,
|
y: bounds.y,
|
||||||
},
|
},
|
||||||
Some(color),
|
color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ pub struct Checkbox<Color, Message> {
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
on_toggle: Box<dyn Fn(bool) -> Message>,
|
on_toggle: Box<dyn Fn(bool) -> Message>,
|
||||||
label: String,
|
label: String,
|
||||||
label_color: Color,
|
label_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color, Message> std::fmt::Debug for Checkbox<Color, Message>
|
impl<Color, Message> std::fmt::Debug for Checkbox<Color, Message>
|
||||||
|
|
@ -63,10 +63,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color, Message> Checkbox<Color, Message>
|
impl<Color, Message> Checkbox<Color, Message> {
|
||||||
where
|
|
||||||
Color: Default,
|
|
||||||
{
|
|
||||||
/// Creates a new [`Checkbox`].
|
/// Creates a new [`Checkbox`].
|
||||||
///
|
///
|
||||||
/// It expects:
|
/// It expects:
|
||||||
|
|
@ -85,7 +82,7 @@ where
|
||||||
is_checked,
|
is_checked,
|
||||||
on_toggle: Box::new(f),
|
on_toggle: Box::new(f),
|
||||||
label: String::from(label),
|
label: String::from(label),
|
||||||
label_color: Color::default(),
|
label_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +91,7 @@ where
|
||||||
/// [`Color`]: ../../../../graphics/struct.Color.html
|
/// [`Color`]: ../../../../graphics/struct.Color.html
|
||||||
/// [`Checkbox`]: struct.Checkbox.html
|
/// [`Checkbox`]: struct.Checkbox.html
|
||||||
pub fn label_color(mut self, color: Color) -> Self {
|
pub fn label_color(mut self, color: Color) -> Self {
|
||||||
self.label_color = color;
|
self.label_color = Some(color);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ pub struct Radio<Color, Message> {
|
||||||
is_selected: bool,
|
is_selected: bool,
|
||||||
on_click: Message,
|
on_click: Message,
|
||||||
label: String,
|
label: String,
|
||||||
label_color: Color,
|
label_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color, Message> std::fmt::Debug for Radio<Color, Message>
|
impl<Color, Message> std::fmt::Debug for Radio<Color, Message>
|
||||||
|
|
@ -72,10 +72,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color, Message> Radio<Color, Message>
|
impl<Color, Message> Radio<Color, Message> {
|
||||||
where
|
|
||||||
Color: Default,
|
|
||||||
{
|
|
||||||
/// Creates a new [`Radio`] button.
|
/// Creates a new [`Radio`] button.
|
||||||
///
|
///
|
||||||
/// It expects:
|
/// It expects:
|
||||||
|
|
@ -95,7 +92,7 @@ where
|
||||||
is_selected: Some(value) == selected,
|
is_selected: Some(value) == selected,
|
||||||
on_click: f(value),
|
on_click: f(value),
|
||||||
label: String::from(label),
|
label: String::from(label),
|
||||||
label_color: Color::default(),
|
label_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +101,7 @@ where
|
||||||
/// [`Color`]: ../../../../graphics/struct.Color.html
|
/// [`Color`]: ../../../../graphics/struct.Color.html
|
||||||
/// [`Radio`]: struct.Radio.html
|
/// [`Radio`]: struct.Radio.html
|
||||||
pub fn label_color(mut self, color: Color) -> Self {
|
pub fn label_color(mut self, color: Color) -> Self {
|
||||||
self.label_color = color;
|
self.label_color = Some(color);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,13 @@ use std::hash::Hash;
|
||||||
pub struct Text<Color> {
|
pub struct Text<Color> {
|
||||||
content: String,
|
content: String,
|
||||||
size: u16,
|
size: u16,
|
||||||
color: Color,
|
color: Option<Color>,
|
||||||
style: Style,
|
style: Style,
|
||||||
horizontal_alignment: HorizontalAlignment,
|
horizontal_alignment: HorizontalAlignment,
|
||||||
vertical_alignment: VerticalAlignment,
|
vertical_alignment: VerticalAlignment,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color> Text<Color>
|
impl<Color> Text<Color> {
|
||||||
where
|
|
||||||
Color: Default,
|
|
||||||
{
|
|
||||||
/// Create a new fragment of [`Text`] with the given contents.
|
/// Create a new fragment of [`Text`] with the given contents.
|
||||||
///
|
///
|
||||||
/// [`Text`]: struct.Text.html
|
/// [`Text`]: struct.Text.html
|
||||||
|
|
@ -44,7 +41,7 @@ where
|
||||||
Text {
|
Text {
|
||||||
content: String::from(label),
|
content: String::from(label),
|
||||||
size: 20,
|
size: 20,
|
||||||
color: Color::default(),
|
color: None,
|
||||||
style: Style::default().fill_width(),
|
style: Style::default().fill_width(),
|
||||||
horizontal_alignment: HorizontalAlignment::Left,
|
horizontal_alignment: HorizontalAlignment::Left,
|
||||||
vertical_alignment: VerticalAlignment::Top,
|
vertical_alignment: VerticalAlignment::Top,
|
||||||
|
|
@ -64,7 +61,7 @@ where
|
||||||
/// [`Text`]: struct.Text.html
|
/// [`Text`]: struct.Text.html
|
||||||
/// [`Color`]: ../../../graphics/struct.Color.html
|
/// [`Color`]: ../../../graphics/struct.Color.html
|
||||||
pub fn color(mut self, color: Color) -> Self {
|
pub fn color(mut self, color: Color) -> Self {
|
||||||
self.color = color;
|
self.color = Some(color);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,7 +177,7 @@ pub trait Renderer<Color> {
|
||||||
bounds: Rectangle<f32>,
|
bounds: Rectangle<f32>,
|
||||||
content: &str,
|
content: &str,
|
||||||
size: f32,
|
size: f32,
|
||||||
color: Color,
|
color: Option<Color>,
|
||||||
horizontal_alignment: HorizontalAlignment,
|
horizontal_alignment: HorizontalAlignment,
|
||||||
vertical_alignment: VerticalAlignment,
|
vertical_alignment: VerticalAlignment,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue