From b54f27d30deec672012c4a63c65d34641b40a9d5 Mon Sep 17 00:00:00 2001 From: hicaru Date: Tue, 12 Dec 2023 14:02:15 +0500 Subject: added svg hover, for styles impl --- widget/src/svg.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'widget/src/svg.rs') diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 2d01d1ab..f9b16e1a 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.appearance(&self.style) + } else { + theme.hovered(&self.style) + }; renderer.draw( self.handle.clone(), -- cgit From 0655a20ad119e2e9790afcc45039fd4ac0e7d432 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 16 Mar 2023 20:23:25 +0100 Subject: Make `Shrink` have priority over `Fill` in layout --- widget/src/svg.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'widget/src/svg.rs') diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 2d01d1ab..8367ad18 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -115,10 +115,7 @@ where let image_size = Size::new(width as f32, height as f32); // The size to be available to the widget prior to `Shrink`ing - let raw_size = limits - .width(self.width) - .height(self.height) - .resolve(image_size); + let raw_size = limits.resolve(image_size, self.width, self.height); // The uncropped size of the image when fit to the bounds above let full_size = self.content_fit.fit(image_size, raw_size); -- cgit From b083eda663b8939e1c3e86b5ce2cb5fa8fc80ccb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 9 Jan 2024 02:03:13 +0100 Subject: Fix `Svg` styling --- widget/src/svg.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'widget/src/svg.rs') diff --git a/widget/src/svg.rs b/widget/src/svg.rs index f9b16e1a..05c9265b 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -168,9 +168,9 @@ where }; let appearance = if is_mouse_over { - theme.appearance(&self.style) - } else { theme.hovered(&self.style) + } else { + theme.appearance(&self.style) }; renderer.draw( -- cgit From d278bfd21d0399009e652560afb9a4d185e92637 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Jan 2024 17:46:33 +0100 Subject: Replace `width` and `height` with `Widget::size` --- widget/src/svg.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'widget/src/svg.rs') diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 8367ad18..75ab238a 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -96,12 +96,11 @@ where Renderer: svg::Renderer, Renderer::Theme: iced_style::svg::StyleSheet, { - fn width(&self) -> Length { - self.width - } - - fn height(&self) -> Length { - self.height + fn size(&self) -> Size { + Size { + width: self.width, + height: self.height, + } } fn layout( -- cgit From d62bb8193c1c43f565fcc5c52293d564c91e215d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Jan 2024 06:35:33 +0100 Subject: Introduce useful helpers in `layout` module --- widget/src/svg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget/src/svg.rs') diff --git a/widget/src/svg.rs b/widget/src/svg.rs index 75ab238a..830abb0f 100644 --- a/widget/src/svg.rs +++ b/widget/src/svg.rs @@ -114,7 +114,7 @@ where let image_size = Size::new(width as f32, height as f32); // The size to be available to the widget prior to `Shrink`ing - let raw_size = limits.resolve(image_size, self.width, self.height); + let raw_size = limits.resolve(self.width, self.height, image_size); // The uncropped size of the image when fit to the bounds above let full_size = self.content_fit.fit(image_size, raw_size); -- cgit