summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-31 17:14:10 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-31 17:14:10 +0700
commitbd7b086ec1f9d428945f05fb12bda157f9e77dfd (patch)
tree4be12be5f1c96d54233633ba14bd6e0360a7fa7f
parentd758006ee91aa0fdb70eaa67abbfad36be02c7be (diff)
downloadiced-bd7b086ec1f9d428945f05fb12bda157f9e77dfd.tar.gz
iced-bd7b086ec1f9d428945f05fb12bda157f9e77dfd.tar.bz2
iced-bd7b086ec1f9d428945f05fb12bda157f9e77dfd.zip
Reintroduce `Box` for `style_sheet` in `Radio`
-rw-r--r--examples/scrollable/src/main.rs2
-rw-r--r--examples/scrollable/src/style.rs4
-rw-r--r--examples/styling/src/main.rs6
-rw-r--r--native/src/widget/radio.rs9
-rw-r--r--style/src/radio.rs13
-rw-r--r--web/src/widget/radio.rs9
6 files changed, 29 insertions, 14 deletions
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 2eaf197e..272f0ce2 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -76,7 +76,7 @@ impl Sandbox for ScrollableDemo {
Some(*theme),
Message::ThemeChanged,
)
- .style(theme.clone().into()),
+ .style(*theme),
)
},
);
diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs
index 068483cb..3c8e5234 100644
--- a/examples/scrollable/src/style.rs
+++ b/examples/scrollable/src/style.rs
@@ -25,11 +25,11 @@ impl<'a> From<Theme> for Box<dyn container::StyleSheet + 'a> {
}
}
-impl From<Theme> for &'static dyn radio::StyleSheet {
+impl<'a> From<Theme> for Box<dyn radio::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => &dark::Radio,
+ Theme::Dark => dark::Radio.into(),
}
}
}
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 3692ad1e..73f965d9 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -64,7 +64,7 @@ impl Sandbox for Styling {
Some(self.theme),
Message::ThemeChanged,
)
- .style(self.theme.into()),
+ .style(self.theme),
)
},
);
@@ -185,11 +185,11 @@ mod style {
}
}
- impl From<Theme> for &'static dyn radio::StyleSheet {
+ impl<'a> From<Theme> for Box<dyn radio::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => &dark::Radio,
+ Theme::Dark => dark::Radio.into(),
}
}
}
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index afe85b76..eb732dc3 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -53,7 +53,7 @@ pub struct Radio<'a, Message, Renderer: text::Renderer> {
text_size: Option<u16>,
text_color: Option<Color>,
font: Renderer::Font,
- style_sheet: &'a dyn StyleSheet,
+ style_sheet: Box<dyn StyleSheet + 'a>,
}
impl<'a, Message, Renderer: text::Renderer> Radio<'a, Message, Renderer>
@@ -135,8 +135,11 @@ where
}
/// Sets the style of the [`Radio`] button.
- pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self {
- self.style_sheet = style_sheet;
+ pub fn style(
+ mut self,
+ style_sheet: impl Into<Box<dyn StyleSheet + 'a>>,
+ ) -> Self {
+ self.style_sheet = style_sheet.into();
self
}
}
diff --git a/style/src/radio.rs b/style/src/radio.rs
index add12754..724ae807 100644
--- a/style/src/radio.rs
+++ b/style/src/radio.rs
@@ -37,8 +37,17 @@ impl StyleSheet for Default {
}
}
-impl std::default::Default for &'static dyn StyleSheet {
+impl std::default::Default for Box<dyn StyleSheet> {
fn default() -> Self {
- &Default
+ Box::new(Default)
+ }
+}
+
+impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
+where
+ T: StyleSheet + 'a,
+{
+ fn from(style_sheet: T) -> Self {
+ Box::new(style_sheet)
}
}
diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs
index 5e9eaa3f..03b2922b 100644
--- a/web/src/widget/radio.rs
+++ b/web/src/widget/radio.rs
@@ -38,7 +38,7 @@ pub struct Radio<'a, Message> {
id: Option<String>,
name: Option<String>,
#[allow(dead_code)]
- style_sheet: &'a dyn StyleSheet,
+ style_sheet: Box<dyn StyleSheet + 'a>,
}
impl<'a, Message> Radio<'a, Message> {
@@ -71,8 +71,11 @@ impl<'a, Message> Radio<'a, Message> {
}
/// Sets the style of the [`Radio`] button.
- pub fn style(mut self, style_sheet: &'a dyn StyleSheet) -> Self {
- self.style_sheet = style_sheet;
+ pub fn style(
+ mut self,
+ style_sheet: impl Into<Box<dyn StyleSheet + 'a>>,
+ ) -> Self {
+ self.style_sheet = style_sheet.into();
self
}