Skip to content

Commit 40d21d2

Browse files
zdevwuhecrj
andauthored
Added text color and font options for native radio and checkbox (#831)
* text color and font options to radio * code formatting * code formatting * code formatting * Added text_color for native checkbox * Removed clone as color has Copy * Fix code formatting with `cargo fmt` Co-authored-by: Héctor Ramón <[email protected]>
1 parent 0ce6a2d commit 40d21d2

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

native/src/widget/checkbox.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::row;
88
use crate::text;
99
use crate::touch;
1010
use crate::{
11-
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
12-
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
11+
Align, Clipboard, Color, Element, Hasher, HorizontalAlignment, Layout,
12+
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget,
1313
};
1414

1515
/// A box that can be checked.
@@ -39,6 +39,7 @@ pub struct Checkbox<Message, Renderer: self::Renderer + text::Renderer> {
3939
spacing: u16,
4040
text_size: Option<u16>,
4141
font: Renderer::Font,
42+
text_color: Option<Color>,
4243
style: Renderer::Style,
4344
}
4445

@@ -66,6 +67,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
6667
spacing: Renderer::DEFAULT_SPACING,
6768
text_size: None,
6869
font: Renderer::Font::default(),
70+
text_color: None,
6971
style: Renderer::Style::default(),
7072
}
7173
}
@@ -102,6 +104,12 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
102104
self
103105
}
104106

107+
/// Sets the text color of the [`Checkbox`] button.
108+
pub fn text_color(mut self, color: Color) -> Self {
109+
self.text_color = Some(color);
110+
self
111+
}
112+
105113
/// Sets the style of the [`Checkbox`].
106114
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
107115
self.style = style.into();
@@ -193,7 +201,7 @@ where
193201
&self.label,
194202
self.text_size.unwrap_or(renderer.default_size()),
195203
self.font,
196-
None,
204+
self.text_color,
197205
HorizontalAlignment::Left,
198206
VerticalAlignment::Center,
199207
);

native/src/widget/radio.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! Create choices using radio buttons.
2+
use std::hash::Hash;
3+
24
use crate::event::{self, Event};
3-
use crate::layout;
45
use crate::mouse;
56
use crate::row;
67
use crate::text;
78
use crate::touch;
9+
use crate::{layout, Color};
810
use crate::{
911
Align, Clipboard, Element, Hasher, HorizontalAlignment, Layout, Length,
1012
Point, Rectangle, Row, Text, VerticalAlignment, Widget,
1113
};
1214

13-
use std::hash::Hash;
14-
1515
/// A circular button representing a choice.
1616
///
1717
/// # Example
@@ -47,6 +47,8 @@ pub struct Radio<Message, Renderer: self::Renderer + text::Renderer> {
4747
size: u16,
4848
spacing: u16,
4949
text_size: Option<u16>,
50+
text_color: Option<Color>,
51+
font: Renderer::Font,
5052
style: Renderer::Style,
5153
}
5254

@@ -81,6 +83,8 @@ where
8183
size: <Renderer as self::Renderer>::DEFAULT_SIZE,
8284
spacing: Renderer::DEFAULT_SPACING, //15
8385
text_size: None,
86+
text_color: None,
87+
font: Default::default(),
8488
style: Renderer::Style::default(),
8589
}
8690
}
@@ -109,6 +113,18 @@ where
109113
self
110114
}
111115

116+
/// Sets the text color of the [`Radio`] button.
117+
pub fn text_color(mut self, color: Color) -> Self {
118+
self.text_color = Some(color);
119+
self
120+
}
121+
122+
/// Sets the text font of the [`Radio`] button.
123+
pub fn font(mut self, font: Renderer::Font) -> Self {
124+
self.font = font;
125+
self
126+
}
127+
112128
/// Sets the style of the [`Radio`] button.
113129
pub fn style(mut self, style: impl Into<Renderer::Style>) -> Self {
114130
self.style = style.into();
@@ -196,8 +212,8 @@ where
196212
label_layout.bounds(),
197213
&self.label,
198214
self.text_size.unwrap_or(renderer.default_size()),
199-
Default::default(),
200-
None,
215+
self.font,
216+
self.text_color,
201217
HorizontalAlignment::Left,
202218
VerticalAlignment::Center,
203219
);

0 commit comments

Comments
 (0)