Skip to content

Commit 61e3d85

Browse files
authored
Merge pull request #2163 from hicaru/svg_hover
added svg hover, for styles impl
2 parents 070abff + b083eda commit 61e3d85

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

style/src/svg.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ pub trait StyleSheet {
2020

2121
/// Produces the [`Appearance`] of the svg.
2222
fn appearance(&self, style: &Self::Style) -> Appearance;
23+
24+
/// Produces the hovered [`Appearance`] of a svg content.
25+
fn hovered(&self, style: &Self::Style) -> Appearance;
2326
}

style/src/theme.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,10 @@ impl svg::StyleSheet for Theme {
939939
Svg::Custom(custom) => custom.appearance(self),
940940
}
941941
}
942+
943+
fn hovered(&self, style: &Self::Style) -> svg::Appearance {
944+
self.appearance(style)
945+
}
942946
}
943947

944948
impl svg::StyleSheet for fn(&Theme) -> svg::Appearance {
@@ -947,6 +951,10 @@ impl svg::StyleSheet for fn(&Theme) -> svg::Appearance {
947951
fn appearance(&self, style: &Self::Style) -> svg::Appearance {
948952
(self)(style)
949953
}
954+
955+
fn hovered(&self, style: &Self::Style) -> svg::Appearance {
956+
self.appearance(style)
957+
}
950958
}
951959

952960
/// The style of a scrollable.

widget/src/svg.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,15 @@ where
141141
theme: &Renderer::Theme,
142142
_style: &renderer::Style,
143143
layout: Layout<'_>,
144-
_cursor: mouse::Cursor,
144+
cursor: mouse::Cursor,
145145
_viewport: &Rectangle,
146146
) {
147147
let Size { width, height } = renderer.dimensions(&self.handle);
148148
let image_size = Size::new(width as f32, height as f32);
149149

150150
let bounds = layout.bounds();
151151
let adjusted_fit = self.content_fit.fit(image_size, bounds.size());
152+
let is_mouse_over = cursor.is_over(bounds);
152153

153154
let render = |renderer: &mut Renderer| {
154155
let offset = Vector::new(
@@ -162,7 +163,11 @@ where
162163
..bounds
163164
};
164165

165-
let appearance = theme.appearance(&self.style);
166+
let appearance = if is_mouse_over {
167+
theme.hovered(&self.style)
168+
} else {
169+
theme.appearance(&self.style)
170+
};
166171

167172
renderer.draw(
168173
self.handle.clone(),

0 commit comments

Comments
 (0)