summaryrefslogtreecommitdiffstats
path: root/widget/src/tooltip.rs
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/tooltip.rs')
-rw-r--r--widget/src/tooltip.rs41
1 files changed, 27 insertions, 14 deletions
diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs
index 32c962fc..39f2e07d 100644
--- a/widget/src/tooltip.rs
+++ b/widget/src/tooltip.rs
@@ -20,6 +20,7 @@ pub struct Tooltip<
Theme = crate::Theme,
Renderer = crate::Renderer,
> where
+ Theme: container::Catalog,
Renderer: text::Renderer,
{
content: Element<'a, Message, Theme, Renderer>,
@@ -28,11 +29,12 @@ pub struct Tooltip<
gap: f32,
padding: f32,
snap_within_viewport: bool,
- style: container::Style<'a, Theme>,
+ class: Theme::Class<'a>,
}
impl<'a, Message, Theme, Renderer> Tooltip<'a, Message, Theme, Renderer>
where
+ Theme: container::Catalog,
Renderer: text::Renderer,
{
/// The default padding of a [`Tooltip`] drawn by this renderer.
@@ -45,10 +47,7 @@ where
content: impl Into<Element<'a, Message, Theme, Renderer>>,
tooltip: impl Into<Element<'a, Message, Theme, Renderer>>,
position: Position,
- ) -> Self
- where
- Theme: container::DefaultStyle + 'a,
- {
+ ) -> Self {
Tooltip {
content: content.into(),
tooltip: tooltip.into(),
@@ -56,7 +55,7 @@ where
gap: 0.0,
padding: Self::DEFAULT_PADDING,
snap_within_viewport: true,
- style: Box::new(Theme::default_style),
+ class: Theme::default(),
}
}
@@ -79,11 +78,23 @@ where
}
/// Sets the style of the [`Tooltip`].
+ #[must_use]
pub fn style(
mut self,
- style: impl Fn(&Theme, container::Status) -> container::Appearance + 'a,
- ) -> Self {
- self.style = Box::new(style);
+ style: impl Fn(&Theme) -> container::Style + 'a,
+ ) -> Self
+ where
+ Theme::Class<'a>: From<container::StyleFn<'a, Theme>>,
+ {
+ self.class = (Box::new(style) as container::StyleFn<'a, Theme>).into();
+ self
+ }
+
+ /// Sets the style class of the [`Tooltip`].
+ #[cfg(feature = "advanced")]
+ #[must_use]
+ pub fn class(mut self, class: impl Into<Theme::Class<'a>>) -> Self {
+ self.class = class.into();
self
}
}
@@ -91,6 +102,7 @@ where
impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
for Tooltip<'a, Message, Theme, Renderer>
where
+ Theme: container::Catalog,
Renderer: text::Renderer,
{
fn children(&self) -> Vec<widget::Tree> {
@@ -239,7 +251,7 @@ where
positioning: self.position,
gap: self.gap,
padding: self.padding,
- style: &self.style,
+ class: &self.class,
})))
} else {
None
@@ -262,7 +274,7 @@ impl<'a, Message, Theme, Renderer> From<Tooltip<'a, Message, Theme, Renderer>>
for Element<'a, Message, Theme, Renderer>
where
Message: 'a,
- Theme: 'a,
+ Theme: container::Catalog + 'a,
Renderer: text::Renderer + 'a,
{
fn from(
@@ -299,6 +311,7 @@ enum State {
struct Overlay<'a, 'b, Message, Theme, Renderer>
where
+ Theme: container::Catalog,
Renderer: text::Renderer,
{
position: Point,
@@ -310,14 +323,14 @@ where
positioning: Position,
gap: f32,
padding: f32,
- style:
- &'b (dyn Fn(&Theme, container::Status) -> container::Appearance + 'a),
+ class: &'b Theme::Class<'a>,
}
impl<'a, 'b, Message, Theme, Renderer>
overlay::Overlay<Message, Theme, Renderer>
for Overlay<'a, 'b, Message, Theme, Renderer>
where
+ Theme: container::Catalog,
Renderer: text::Renderer,
{
fn layout(&mut self, renderer: &Renderer, bounds: Size) -> layout::Node {
@@ -426,7 +439,7 @@ where
layout: Layout<'_>,
cursor_position: mouse::Cursor,
) {
- let style = (self.style)(theme, container::Status::Idle);
+ let style = theme.style(self.class);
container::draw_background(renderer, &style, layout.bounds());