summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-05-15 14:58:28 +0200
committerLibravatar GitHub <noreply@github.com>2020-05-15 14:58:28 +0200
commit33448508a524db6447b380cc236be6f0d5ca8a86 (patch)
tree357be3339543673c996eefddd62708ed3c607fb0
parente89e521e2b673b4bc65853b960535abb8b05edfc (diff)
parent175f5d71f487c6cb0ed41d560fd130ea7bdfa5c7 (diff)
downloadiced-33448508a524db6447b380cc236be6f0d5ca8a86.tar.gz
iced-33448508a524db6447b380cc236be6f0d5ca8a86.tar.bz2
iced-33448508a524db6447b380cc236be6f0d5ca8a86.zip
Merge pull request #345 from AberrantWolf/master
Update `Radio` to have the same layout members and fns as `Checkbox`
Diffstat (limited to '')
-rw-r--r--native/src/renderer/null.rs5
-rw-r--r--native/src/widget/radio.rs75
-rw-r--r--wgpu/src/renderer/widget/radio.rs5
3 files changed, 66 insertions, 19 deletions
diff --git a/native/src/renderer/null.rs b/native/src/renderer/null.rs
index 2c7babdb..19689d30 100644
--- a/native/src/renderer/null.rs
+++ b/native/src/renderer/null.rs
@@ -161,9 +161,8 @@ impl button::Renderer for Null {
impl radio::Renderer for Null {
type Style = ();
- fn default_size(&self) -> u32 {
- 20
- }
+ const DEFAULT_SIZE: u16 = 20;
+ const DEFAULT_SPACING: u16 = 15;
fn draw(
&mut self,
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index ab5bcf32..d07a9012 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -34,14 +34,20 @@ use std::hash::Hash;
///
/// ![Radio buttons drawn by `iced_wgpu`](https://github.com/hecrj/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/radio.png?raw=true)
#[allow(missing_debug_implementations)]
-pub struct Radio<Message, Renderer: self::Renderer> {
+pub struct Radio<Message, Renderer: self::Renderer + text::Renderer> {
is_selected: bool,
on_click: Message,
label: String,
+ width: Length,
+ size: u16,
+ spacing: u16,
+ text_size: u16,
style: Renderer::Style,
}
-impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
+impl<Message, Renderer: self::Renderer + text::Renderer>
+ Radio<Message, Renderer>
+{
/// Creates a new [`Radio`] button.
///
/// It expects:
@@ -66,10 +72,46 @@ impl<Message, Renderer: self::Renderer> Radio<Message, Renderer> {
is_selected: Some(value) == selected,
on_click: f(value),
label: label.into(),
+ width: Length::Shrink,
+ size: <Renderer as self::Renderer>::DEFAULT_SIZE,
+ spacing: Renderer::DEFAULT_SPACING, //15
+ text_size: <Renderer as text::Renderer>::DEFAULT_SIZE,
style: Renderer::Style::default(),
}
}
+ /// Sets the size of the [`Radio`] button.
+ ///
+ /// [`Radio`]: struct.Radio.html
+ pub fn size(mut self, size: u16) -> Self {
+ self.size = size;
+ self
+ }
+
+ /// Sets the width of the [`Radio`] button.
+ ///
+ /// [`Radio`]: struct.Radio.html
+ pub fn width(mut self, width: Length) -> Self {
+ self.width = width;
+ self
+ }
+
+ /// Sets the spacing between the [`Radio`] button and the text.
+ ///
+ /// [`Radio`]: struct.Radio.html
+ pub fn spacing(mut self, spacing: u16) -> Self {
+ self.spacing = spacing;
+ self
+ }
+
+ /// Sets the text size of the [`Radio`] button.
+ ///
+ /// [`Radio`]: struct.Radio.html
+ pub fn text_size(mut self, text_size: u16) -> Self {
+ self.text_size = text_size;
+ self
+ }
+
/// Sets the style of the [`Radio`] button.
///
/// [`Radio`]: struct.Radio.html
@@ -85,7 +127,7 @@ where
Message: Clone,
{
fn width(&self) -> Length {
- Length::Fill
+ self.width
}
fn height(&self) -> Length {
@@ -97,18 +139,20 @@ where
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
- let size = self::Renderer::default_size(renderer);
-
Row::<(), Renderer>::new()
- .width(Length::Fill)
- .spacing(15)
+ .width(self.width)
+ .spacing(self.spacing)
.align_items(Align::Center)
.push(
Row::new()
- .width(Length::Units(size as u16))
- .height(Length::Units(size as u16)),
+ .width(Length::Units(self.size))
+ .height(Length::Units(self.size)),
+ )
+ .push(
+ Text::new(&self.label)
+ .width(self.width)
+ .size(self.text_size),
)
- .push(Text::new(&self.label))
.layout(renderer, limits)
}
@@ -150,7 +194,7 @@ where
defaults,
label_layout.bounds(),
&self.label,
- <Renderer as text::Renderer>::DEFAULT_SIZE,
+ self.text_size,
Default::default(),
None,
HorizontalAlignment::Left,
@@ -188,10 +232,15 @@ pub trait Renderer: crate::Renderer {
/// The style supported by this renderer.
type Style: Default;
- /// Returns the default size of a [`Radio`] button.
+ /// The default size of a [`Radio`] button.
+ ///
+ /// [`Radio`]: struct.Radio.html
+ const DEFAULT_SIZE: u16;
+
+ /// The default spacing of a [`Radio`] button.
///
/// [`Radio`]: struct.Radio.html
- fn default_size(&self) -> u32;
+ const DEFAULT_SPACING: u16;
/// Draws a [`Radio`] button.
///
diff --git a/wgpu/src/renderer/widget/radio.rs b/wgpu/src/renderer/widget/radio.rs
index 2f1461db..cee0deb6 100644
--- a/wgpu/src/renderer/widget/radio.rs
+++ b/wgpu/src/renderer/widget/radio.rs
@@ -7,9 +7,8 @@ const DOT_SIZE: f32 = SIZE / 2.0;
impl radio::Renderer for Renderer {
type Style = Box<dyn StyleSheet>;
- fn default_size(&self) -> u32 {
- SIZE as u32
- }
+ const DEFAULT_SIZE: u16 = SIZE as u16;
+ const DEFAULT_SPACING: u16 = 15;
fn draw(
&mut self,