Use Style struct pattern instead of trait for all widgets

This commit is contained in:
Héctor Ramón Jiménez 2024-03-06 20:30:58 +01:00
parent 8a63774b24
commit 34e7c6593a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
25 changed files with 466 additions and 282 deletions

View file

@ -28,7 +28,7 @@ pub struct Tooltip<
gap: f32,
padding: f32,
snap_within_viewport: bool,
style: fn(&Theme, container::Status) -> container::Appearance,
style: container::Style<Theme>,
}
impl<'a, Message, Theme, Renderer> Tooltip<'a, Message, Theme, Renderer>
@ -47,7 +47,7 @@ where
position: Position,
) -> Self
where
Theme: container::Style,
container::Style<Theme>: Default,
{
Tooltip {
content: content.into(),
@ -56,7 +56,7 @@ where
gap: 0.0,
padding: Self::DEFAULT_PADDING,
snap_within_viewport: true,
style: Theme::style(),
style: container::Style::default(),
}
}
@ -83,7 +83,7 @@ where
mut self,
style: fn(&Theme, container::Status) -> container::Appearance,
) -> Self {
self.style = style;
self.style = style.into();
self
}
}
@ -309,7 +309,7 @@ where
positioning: Position,
gap: f32,
padding: f32,
style: fn(&Theme, container::Status) -> container::Appearance,
style: container::Style<Theme>,
}
impl<'a, 'b, Message, Theme, Renderer>
@ -424,7 +424,7 @@ where
layout: Layout<'_>,
cursor_position: mouse::Cursor,
) {
let style = (self.style)(theme, container::Status::Idle);
let style = self.style.resolve(theme, container::Status::Idle);
container::draw_background(renderer, &style, layout.bounds());