From 0ceee1cf3ae49f5bd0e3f2b346a4b34076e4523a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 03:28:43 +0200 Subject: Implement image support for `canvas` widget --- graphics/src/image.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'graphics/src/image.rs') diff --git a/graphics/src/image.rs b/graphics/src/image.rs index 318592be..0e8f2fe3 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -23,6 +23,12 @@ pub enum Image { /// The opacity of the image. opacity: f32, + + /// If set to `true`, the image will be snapped to the pixel grid. + /// + /// This can avoid graphical glitches, specially when using a + /// [`image::FilterMethod::Nearest`]. + snap: bool, }, /// A vector image. Vector { -- cgit From 92bd3ecd6b4a6618f0fc725dea3694c3b40e5314 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 04:30:12 +0200 Subject: Introduce `Image` struct in `core::image` --- graphics/src/image.rs | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'graphics/src/image.rs') diff --git a/graphics/src/image.rs b/graphics/src/image.rs index 0e8f2fe3..2e4f4b5a 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -8,28 +8,8 @@ use crate::core::{image, svg, Color, Radians, Rectangle}; #[derive(Debug, Clone, PartialEq)] pub enum Image { /// A raster image. - Raster { - /// The handle of a raster image. - handle: image::Handle, + Raster(image::Image, Rectangle), - /// The filter method of a raster image. - filter_method: image::FilterMethod, - - /// The bounds of the image. - bounds: Rectangle, - - /// The rotation of the image. - rotation: Radians, - - /// The opacity of the image. - opacity: f32, - - /// If set to `true`, the image will be snapped to the pixel grid. - /// - /// This can avoid graphical glitches, specially when using a - /// [`image::FilterMethod::Nearest`]. - snap: bool, - }, /// A vector image. Vector { /// The handle of a vector image. @@ -53,10 +33,8 @@ impl Image { /// Returns the bounds of the [`Image`]. pub fn bounds(&self) -> Rectangle { match self { - Image::Raster { - bounds, rotation, .. - } - | Image::Vector { + Image::Raster(image, bounds) => bounds.rotate(image.rotation), + Image::Vector { bounds, rotation, .. } => bounds.rotate(*rotation), } -- cgit From d4b08462e5a25929ec4df32f242898986902af56 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 4 Aug 2024 04:52:55 +0200 Subject: Introduce `Svg` struct in `core::svg` --- graphics/src/image.rs | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'graphics/src/image.rs') diff --git a/graphics/src/image.rs b/graphics/src/image.rs index 2e4f4b5a..67a5e0cf 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -2,7 +2,9 @@ #[cfg(feature = "image")] pub use ::image as image_rs; -use crate::core::{image, svg, Color, Radians, Rectangle}; +use crate::core::image; +use crate::core::svg; +use crate::core::Rectangle; /// A raster or vector image. #[derive(Debug, Clone, PartialEq)] @@ -11,22 +13,7 @@ pub enum Image { Raster(image::Image, Rectangle), /// A vector image. - Vector { - /// The handle of a vector image. - handle: svg::Handle, - - /// The [`Color`] filter - color: Option, - - /// The bounds of the image. - bounds: Rectangle, - - /// The rotation of the image. - rotation: Radians, - - /// The opacity of the image. - opacity: f32, - }, + Vector(svg::Svg, Rectangle), } impl Image { @@ -34,9 +21,7 @@ impl Image { pub fn bounds(&self) -> Rectangle { match self { Image::Raster(image, bounds) => bounds.rotate(image.rotation), - Image::Vector { - bounds, rotation, .. - } => bounds.rotate(*rotation), + Image::Vector(svg, bounds) => bounds.rotate(svg.rotation), } } } -- cgit