Skip to content

Added text color and font options for native radio and checkbox #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions native/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::row;
use crate::text;
use crate::touch;
use crate::{
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout,
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget,
};

/// A box that can be checked.
Expand Down Expand Up @@ -39,6 +39,7 @@ pub struct Checkbox<Message, Renderer: self::Renderer + text::Renderer> {
spacing: u16,
text_size: Option<u16>,
font: Renderer::Font,
text_color: Option<Color>,
style: Renderer::Style,
}

Expand Down Expand Up @@ -66,6 +67,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
spacing: Renderer::DEFAULT_SPACING,
text_size: None,
font: Renderer::Font::default(),
text_color: None,
style: Renderer::Style::default(),
}
}
Expand Down Expand Up @@ -102,6 +104,12 @@ impl<Message, Renderer: self::Renderer + text::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, style: impl Into<Renderer::Style>) -> Self {
self.style = style.into();
Expand Down Expand Up @@ -193,7 +201,7 @@ where
&self.label,
self.text_size.unwrap_or(renderer.default_size()),
self.font,
None,
self.text_color,
HorizontalAlignment::Left,
VerticalAlignment::Center,
);
Expand Down
26 changes: 21 additions & 5 deletions native/src/widget/radio.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! Create choices using radio buttons.
use std::hash::Hash;

use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::row;
use crate::text;
use crate::touch;
use crate::{layout, Color};
use crate::{
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
};

use std::hash::Hash;

/// A circular button representing a choice.
///
/// # Example
Expand Down Expand Up @@ -47,6 +47,8 @@ pub struct Radio<Message, Renderer: self::Renderer + text::Renderer> {
size: u16,
spacing: u16,
text_size: Option<u16>,
text_color: Option<Color>,
font: Renderer::Font,
style: Renderer::Style,
}

Expand Down Expand Up @@ -81,6 +83,8 @@ where
size: <Renderer as self::Renderer>::DEFAULT_SIZE,
spacing: Renderer::DEFAULT_SPACING, //15
text_size: None,
text_color: None,
font: Default::default(),
style: Renderer::Style::default(),
}
}
Expand Down Expand Up @@ -109,6 +113,18 @@ 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;
self
}

/// Sets the style of the [`Radio`] button.
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
self.style = style.into();
Expand Down Expand Up @@ -196,8 +212,8 @@ where
label_layout.bounds(),
&self.label,
self.text_size.unwrap_or(renderer.default_size()),
Default::default(),
None,
self.font,
self.text_color,
HorizontalAlignment::Left,
VerticalAlignment::Center,
);
Expand Down