Add size, spacing, and text_size properties to Checkbox

This commit is contained in:
Clark Moody 2020-02-17 17:40:01 -06:00
parent 5345ac785b
commit 668f627532
1 changed files with 38 additions and 7 deletions

View File

@ -30,7 +30,10 @@ pub struct Checkbox<Message, Renderer: self::Renderer> {
is_checked: bool, is_checked: bool,
on_toggle: Box<dyn Fn(bool) -> Message>, on_toggle: Box<dyn Fn(bool) -> Message>,
label: String, label: String,
size: u16,
width: Length, width: Length,
spacing: u16,
text_size: u16,
style: Renderer::Style, style: Renderer::Style,
} }
@ -53,11 +56,22 @@ impl<Message, Renderer: self::Renderer> Checkbox<Message, Renderer> {
is_checked, is_checked,
on_toggle: Box::new(f), on_toggle: Box::new(f),
label: String::from(label), label: String::from(label),
size: 20,
width: Length::Shrink, width: Length::Shrink,
spacing: 15,
text_size: 20,
style: Renderer::Style::default(), style: Renderer::Style::default(),
} }
} }
/// Sets the size of the [`Checkbox`].
///
/// [`Checkbox`]: struct.Checkbox.html
pub fn size(mut self, size: u16) -> Self {
self.size = size;
self
}
/// Sets the width of the [`Checkbox`]. /// Sets the width of the [`Checkbox`].
/// ///
/// [`Checkbox`]: struct.Checkbox.html /// [`Checkbox`]: struct.Checkbox.html
@ -66,6 +80,22 @@ impl<Message, Renderer: self::Renderer> Checkbox<Message, Renderer> {
self self
} }
/// Sets the spacing between the [`Checkbox`] and the text.
///
/// [`Checkbox`]: struct.Checkbox.html
pub fn spacing(mut self, spacing: u16) -> Self {
self.spacing = spacing;
self
}
/// Sets the text size of the [`Checkbox`].
///
/// [`Checkbox`]: struct.Checkbox.html
pub fn text_size(mut self, text_size: u16) -> Self {
self.text_size = text_size;
self
}
/// Sets the style of the [`Checkbox`]. /// Sets the style of the [`Checkbox`].
/// ///
/// [`Checkbox`]: struct.Checkbox.html /// [`Checkbox`]: struct.Checkbox.html
@ -93,18 +123,19 @@ where
renderer: &Renderer, renderer: &Renderer,
limits: &layout::Limits, limits: &layout::Limits,
) -> layout::Node { ) -> layout::Node {
let size = self::Renderer::default_size(renderer);
Row::<(), Renderer>::new() Row::<(), Renderer>::new()
.width(self.width) .width(self.width)
.spacing(15) .spacing(self.spacing)
.align_items(Align::Center) .align_items(Align::Center)
.push( .push(
Row::new() Row::new()
.width(Length::Units(size as u16)) .width(Length::Units(self.size))
.height(Length::Units(size as u16)), .height(Length::Units(self.size)),
) )
.push(Text::new(&self.label).width(self.width)) .push(
Text::new(&self.label)
.width(self.width)
.size(self.text_size))
.layout(renderer, limits) .layout(renderer, limits)
} }
@ -151,7 +182,7 @@ where
defaults, defaults,
label_layout.bounds(), label_layout.bounds(),
&self.label, &self.label,
text::Renderer::default_size(renderer), self.text_size,
Font::Default, Font::Default,
None, None,
HorizontalAlignment::Left, HorizontalAlignment::Left,