diff --git a/style/src/svg.rs b/style/src/svg.rs index 9378c1a728..5053f9f8cc 100644 --- a/style/src/svg.rs +++ b/style/src/svg.rs @@ -20,4 +20,7 @@ pub trait StyleSheet { /// Produces the [`Appearance`] of the svg. fn appearance(&self, style: &Self::Style) -> Appearance; + + /// Produces the hovered [`Appearance`] of a svg content. + fn hovered(&self, style: &Self::Style) -> Appearance; } diff --git a/style/src/theme.rs b/style/src/theme.rs index 470107283e..4af07794d7 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -909,6 +909,10 @@ impl svg::StyleSheet for Theme { Svg::Custom(custom) => custom.appearance(self), } } + + fn hovered(&self, style: &Self::Style) -> svg::Appearance { + self.appearance(style) + } } impl svg::StyleSheet for fn(&Theme) -> svg::Appearance { @@ -917,6 +921,10 @@ impl svg::StyleSheet for fn(&Theme) -> svg::Appearance { fn appearance(&self, style: &Self::Style) -> svg::Appearance { (self)(style) } + + fn hovered(&self, style: &Self::Style) -> svg::Appearance { + self.appearance(style) + } } /// The style of a scrollable. diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 2d01d1ab0a..05c9265bc5 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -145,7 +145,7 @@ where theme: &Renderer::Theme, _style: &renderer::Style, layout: Layout<'_>, - _cursor: mouse::Cursor, + cursor: mouse::Cursor, _viewport: &Rectangle, ) { let Size { width, height } = renderer.dimensions(&self.handle); @@ -153,6 +153,7 @@ where let bounds = layout.bounds(); let adjusted_fit = self.content_fit.fit(image_size, bounds.size()); + let is_mouse_over = cursor.is_over(bounds); let render = |renderer: &mut Renderer| { let offset = Vector::new( @@ -166,7 +167,11 @@ where ..bounds }; - let appearance = theme.appearance(&self.style); + let appearance = if is_mouse_over { + theme.hovered(&self.style) + } else { + theme.appearance(&self.style) + }; renderer.draw( self.handle.clone(),