summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/game_of_life/src/main.rs2
-rw-r--r--examples/pane_grid/src/main.rs8
-rw-r--r--examples/scrollable/src/main.rs4
-rw-r--r--examples/scrollable/src/style.rs4
-rw-r--r--examples/styling/src/main.rs6
-rw-r--r--examples/tooltip/src/main.rs2
-rw-r--r--native/src/widget/container.rs9
-rw-r--r--native/src/widget/pane_grid/content.rs9
-rw-r--r--native/src/widget/pane_grid/title_bar.rs9
-rw-r--r--native/src/widget/tooltip.rs9
-rw-r--r--style/src/container.rs13
-rw-r--r--web/src/widget/container.rs6
12 files changed, 51 insertions, 30 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 3b5bfa5a..01dcadc6 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -150,7 +150,7 @@ impl Application for GameOfLife {
Container::new(content)
.width(Length::Fill)
.height(Length::Fill)
- .style(&style::Container)
+ .style(style::Container)
.into()
}
}
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs
index 844b604d..8225e9e7 100644
--- a/examples/pane_grid/src/main.rs
+++ b/examples/pane_grid/src/main.rs
@@ -178,9 +178,9 @@ impl Application for Example {
.controls(pane.controls.view(id, total_panes, pane.is_pinned))
.padding(10)
.style(if is_focused {
- &style::TitleBar::Focused
+ style::TitleBar::Focused
} else {
- &style::TitleBar::Active
+ style::TitleBar::Active
});
pane_grid::Content::new(pane.content.view(
@@ -190,9 +190,9 @@ impl Application for Example {
))
.title_bar(title_bar)
.style(if is_focused {
- &style::Pane::Focused
+ style::Pane::Focused
} else {
- &style::Pane::Active
+ style::Pane::Active
})
})
.width(Length::Fill)
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 2f1c5676..2eaf197e 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -164,7 +164,7 @@ impl Sandbox for ScrollableDemo {
Container::new(scrollable)
.width(Length::Fill)
.height(Length::Fill)
- .style(theme.clone().into()),
+ .style(*theme),
)
.push(ProgressBar::new(
0.0..=1.0,
@@ -190,7 +190,7 @@ impl Sandbox for ScrollableDemo {
.height(Length::Fill)
.center_x()
.center_y()
- .style(self.theme.into())
+ .style(self.theme)
.into()
}
}
diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs
index d7d64374..068483cb 100644
--- a/examples/scrollable/src/style.rs
+++ b/examples/scrollable/src/style.rs
@@ -16,11 +16,11 @@ impl Default for Theme {
}
}
-impl From<Theme> for &'static dyn container::StyleSheet {
+impl<'a> From<Theme> for Box<dyn container::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => &dark::Container,
+ Theme::Dark => dark::Container.into(),
}
}
}
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index e8829b53..3692ad1e 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -149,7 +149,7 @@ impl Sandbox for Styling {
.height(Length::Fill)
.center_x()
.center_y()
- .style(self.theme.into())
+ .style(self.theme)
.into()
}
}
@@ -176,11 +176,11 @@ mod style {
}
}
- impl From<Theme> for &'static dyn container::StyleSheet {
+ impl<'a> From<Theme> for Box<dyn container::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
- Theme::Dark => &dark::Container,
+ Theme::Dark => dark::Container.into(),
}
}
}
diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs
index cb2f81df..cfeaf6a6 100644
--- a/examples/tooltip/src/main.rs
+++ b/examples/tooltip/src/main.rs
@@ -115,7 +115,7 @@ fn tooltip<'a>(
)
.gap(5)
.padding(10)
- .style(&style::Tooltip)
+ .style(style::Tooltip)
.into()
}
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index 006e07c6..5ad07d6d 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -28,7 +28,7 @@ pub struct Container<'a, Message, Renderer> {
max_height: u32,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
- style_sheet: &'a dyn StyleSheet,
+ style_sheet: Box<dyn StyleSheet + 'a>,
content: Element<'a, Message, Renderer>,
}
@@ -109,8 +109,11 @@ where
}
/// Sets the style of the [`Container`].
- 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/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs
index 83d96917..d8da6d33 100644
--- a/native/src/widget/pane_grid/content.rs
+++ b/native/src/widget/pane_grid/content.rs
@@ -14,7 +14,7 @@ use crate::{Clipboard, Element, Hasher, Layout, Point, Rectangle, Size};
pub struct Content<'a, Message, Renderer> {
title_bar: Option<TitleBar<'a, Message, Renderer>>,
body: Element<'a, Message, Renderer>,
- style_sheet: &'a dyn container::StyleSheet,
+ style_sheet: Box<dyn container::StyleSheet + 'a>,
}
impl<'a, Message, Renderer> Content<'a, Message, Renderer>
@@ -40,8 +40,11 @@ where
}
/// Sets the style of the [`Content`].
- pub fn style(mut self, style_sheet: &'a dyn container::StyleSheet) -> Self {
- self.style_sheet = style_sheet;
+ pub fn style(
+ mut self,
+ style_sheet: impl Into<Box<dyn container::StyleSheet + 'a>>,
+ ) -> Self {
+ self.style_sheet = style_sheet.into();
self
}
}
diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs
index 2d66ba6c..ffd59488 100644
--- a/native/src/widget/pane_grid/title_bar.rs
+++ b/native/src/widget/pane_grid/title_bar.rs
@@ -17,7 +17,7 @@ pub struct TitleBar<'a, Message, Renderer> {
controls: Option<Element<'a, Message, Renderer>>,
padding: Padding,
always_show_controls: bool,
- style_sheet: &'a dyn container::StyleSheet,
+ style_sheet: Box<dyn container::StyleSheet + 'a>,
}
impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
@@ -54,8 +54,11 @@ where
}
/// Sets the style of the [`TitleBar`].
- pub fn style(mut self, style: &'a dyn container::StyleSheet) -> Self {
- self.style_sheet = style;
+ pub fn style(
+ mut self,
+ style: impl Into<Box<dyn container::StyleSheet + 'a>>,
+ ) -> Self {
+ self.style_sheet = style.into();
self
}
diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs
index a7f3a042..5a6cd923 100644
--- a/native/src/widget/tooltip.rs
+++ b/native/src/widget/tooltip.rs
@@ -20,7 +20,7 @@ pub struct Tooltip<'a, Message, Renderer: text::Renderer> {
content: Element<'a, Message, Renderer>,
tooltip: Text<Renderer>,
position: Position,
- style_sheet: &'a dyn container::StyleSheet,
+ style_sheet: Box<dyn container::StyleSheet + 'a>,
gap: u16,
padding: u16,
}
@@ -77,8 +77,11 @@ where
}
/// Sets the style of the [`Tooltip`].
- pub fn style(mut self, style_sheet: &'a dyn container::StyleSheet) -> Self {
- self.style_sheet = style_sheet;
+ pub fn style(
+ mut self,
+ style_sheet: impl Into<Box<dyn container::StyleSheet + 'a>>,
+ ) -> Self {
+ self.style_sheet = style_sheet.into();
self
}
}
diff --git a/style/src/container.rs b/style/src/container.rs
index 6b0a129b..a5dc700e 100644
--- a/style/src/container.rs
+++ b/style/src/container.rs
@@ -43,8 +43,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/container.rs b/web/src/widget/container.rs
index e61600c4..8e345b9a 100644
--- a/web/src/widget/container.rs
+++ b/web/src/widget/container.rs
@@ -19,7 +19,7 @@ pub struct Container<'a, Message> {
max_height: u32,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
- style_sheet: &'a dyn StyleSheet,
+ style_sheet: Box<dyn StyleSheet + 'a>,
content: Element<'a, Message>,
}
@@ -89,8 +89,8 @@ impl<'a, Message> Container<'a, Message> {
}
/// Sets the style of the [`Container`].
- pub fn style(mut self, style: &'a dyn StyleSheet) -> Self {
- self.style_sheet = style;
+ pub fn style(mut self, style: impl Into<Box<dyn StyleSheet + 'a>>) -> Self {
+ self.style_sheet = style.into();
self
}
}