added svg hover, for styles impl

This commit is contained in:
hicaru 2023-12-12 14:02:15 +05:00
parent dd249a1d11
commit b54f27d30d
3 changed files with 18 additions and 2 deletions

View file

@ -20,4 +20,7 @@ pub trait StyleSheet {
/// Produces the [`Appearance`] of the svg. /// Produces the [`Appearance`] of the svg.
fn appearance(&self, style: &Self::Style) -> Appearance; fn appearance(&self, style: &Self::Style) -> Appearance;
/// Produces the hovered [`Appearance`] of a svg content.
fn hovered(&self, style: &Self::Style) -> Appearance;
} }

View file

@ -909,6 +909,10 @@ impl svg::StyleSheet for Theme {
Svg::Custom(custom) => custom.appearance(self), 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 { 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 { fn appearance(&self, style: &Self::Style) -> svg::Appearance {
(self)(style) (self)(style)
} }
fn hovered(&self, style: &Self::Style) -> svg::Appearance {
self.appearance(style)
}
} }
/// The style of a scrollable. /// The style of a scrollable.

View file

@ -145,7 +145,7 @@ where
theme: &Renderer::Theme, theme: &Renderer::Theme,
_style: &renderer::Style, _style: &renderer::Style,
layout: Layout<'_>, layout: Layout<'_>,
_cursor: mouse::Cursor, cursor: mouse::Cursor,
_viewport: &Rectangle, _viewport: &Rectangle,
) { ) {
let Size { width, height } = renderer.dimensions(&self.handle); let Size { width, height } = renderer.dimensions(&self.handle);
@ -153,6 +153,7 @@ where
let bounds = layout.bounds(); let bounds = layout.bounds();
let adjusted_fit = self.content_fit.fit(image_size, bounds.size()); 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 render = |renderer: &mut Renderer| {
let offset = Vector::new( let offset = Vector::new(
@ -166,7 +167,11 @@ where
..bounds ..bounds
}; };
let appearance = theme.appearance(&self.style); let appearance = if is_mouse_over {
theme.appearance(&self.style)
} else {
theme.hovered(&self.style)
};
renderer.draw( renderer.draw(
self.handle.clone(), self.handle.clone(),