summaryrefslogtreecommitdiffstats
path: root/widget/src/pane_grid.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-06 20:30:58 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-06 20:30:58 +0100
commit34e7c6593a9e0f56cee5db18b7258717cf6bc11b (patch)
tree7c65a58e9052f2f95a0025355679b13c7002eeab /widget/src/pane_grid.rs
parent8a63774b24488f71147a728123551ae72c080d14 (diff)
downloadiced-34e7c6593a9e0f56cee5db18b7258717cf6bc11b.tar.gz
iced-34e7c6593a9e0f56cee5db18b7258717cf6bc11b.tar.bz2
iced-34e7c6593a9e0f56cee5db18b7258717cf6bc11b.zip
Use `Style` struct pattern instead of trait for all widgets
Diffstat (limited to 'widget/src/pane_grid.rs')
-rw-r--r--widget/src/pane_grid.rs36
1 files changed, 24 insertions, 12 deletions
diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs
index 62067e66..ae9cd825 100644
--- a/widget/src/pane_grid.rs
+++ b/widget/src/pane_grid.rs
@@ -112,7 +112,7 @@ pub struct PaneGrid<
on_click: Option<Box<dyn Fn(Pane) -> Message + 'a>>,
on_drag: Option<Box<dyn Fn(DragEvent) -> Message + 'a>>,
on_resize: Option<(f32, Box<dyn Fn(ResizeEvent) -> Message + 'a>)>,
- style: fn(&Theme) -> Appearance,
+ style: Style<Theme>,
}
impl<'a, Message, Theme, Renderer> PaneGrid<'a, Message, Theme, Renderer>
@@ -128,7 +128,7 @@ where
view: impl Fn(Pane, &'a T, bool) -> Content<'a, Message, Theme, Renderer>,
) -> Self
where
- Theme: Style,
+ Style<Theme>: Default,
{
let contents = if let Some((pane, pane_state)) =
state.maximized.and_then(|pane| {
@@ -160,7 +160,7 @@ where
on_click: None,
on_drag: None,
on_resize: None,
- style: Theme::style(),
+ style: Style::default(),
}
}
@@ -221,7 +221,7 @@ where
/// Sets the style of the [`PaneGrid`].
pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
- self.style = style;
+ self.style = Style(style);
self
}
@@ -679,7 +679,7 @@ where
None
};
- let appearance = (self.style)(theme);
+ let appearance = (self.style.0)(theme);
for ((id, (content, tree)), pane_layout) in
contents.zip(layout.children())
@@ -1147,15 +1147,27 @@ pub struct Line {
pub width: f32,
}
-/// The definiton of the default style of a [`PaneGrid`].
-pub trait Style {
- /// Returns the default style of a [`PaneGrid`].
- fn style() -> fn(&Self) -> Appearance;
+/// The style of a [`PaneGrid`].
+#[derive(Debug, PartialEq, Eq)]
+pub struct Style<Theme>(fn(&Theme) -> Appearance);
+
+impl<Theme> Clone for Style<Theme> {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+impl<Theme> Copy for Style<Theme> {}
+
+impl Default for Style<Theme> {
+ fn default() -> Self {
+ Style(default)
+ }
}
-impl Style for Theme {
- fn style() -> fn(&Self) -> Appearance {
- default
+impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
+ fn from(f: fn(&Theme) -> Appearance) -> Self {
+ Style(f)
}
}