summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:52:55 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-08-04 04:52:55 +0200
commitd4b08462e5a25929ec4df32f242898986902af56 (patch)
tree4c6aaf8519b416ebf075fd780e533543416cc81e
parent8708101c892540ffc966cf7ee9d66ca5cd2e8ca6 (diff)
downloadiced-d4b08462e5a25929ec4df32f242898986902af56.tar.gz
iced-d4b08462e5a25929ec4df32f242898986902af56.tar.bz2
iced-d4b08462e5a25929ec4df32f242898986902af56.zip
Introduce `Svg` struct in `core::svg`
-rw-r--r--core/src/image.rs4
-rw-r--r--core/src/lib.rs1
-rw-r--r--core/src/renderer/null.rs13
-rw-r--r--core/src/svg.rs69
-rw-r--r--graphics/src/geometry.rs2
-rw-r--r--graphics/src/geometry/frame.rs28
-rw-r--r--graphics/src/image.rs25
-rw-r--r--renderer/src/fallback.rs36
-rw-r--r--tiny_skia/src/engine.rs16
-rw-r--r--tiny_skia/src/geometry.rs30
-rw-r--r--tiny_skia/src/layer.rs35
-rw-r--r--tiny_skia/src/lib.rs18
-rw-r--r--wgpu/src/geometry.rs40
-rw-r--r--wgpu/src/image/mod.rs19
-rw-r--r--wgpu/src/layer.rs33
-rw-r--r--wgpu/src/lib.rs18
-rw-r--r--widget/src/image.rs6
-rw-r--r--widget/src/svg.rs10
18 files changed, 146 insertions, 257 deletions
diff --git a/core/src/image.rs b/core/src/image.rs
index 99d7f3ef..f985636a 100644
--- a/core/src/image.rs
+++ b/core/src/image.rs
@@ -16,7 +16,7 @@ pub struct Image<H = Handle> {
/// The filter method of the image.
pub filter_method: FilterMethod,
- /// The rotation to be applied to the image, from its center.
+ /// The rotation to be applied to the image; on its center.
pub rotation: Radians,
/// The opacity of the image.
@@ -26,7 +26,7 @@ pub struct Image<H = Handle> {
/// If set to `true`, the image will be snapped to the pixel grid.
///
- /// This can avoid graphical glitches, specially when using a
+ /// This can avoid graphical glitches, specially when using
/// [`FilterMethod::Nearest`].
pub snap: bool,
}
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 0e17d430..df599f45 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -70,6 +70,7 @@ pub use rotation::Rotation;
pub use shadow::Shadow;
pub use shell::Shell;
pub use size::Size;
+pub use svg::Svg;
pub use text::Text;
pub use theme::Theme;
pub use transformation::Transformation;
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs
index 3c6f8be0..e3a07280 100644
--- a/core/src/renderer/null.rs
+++ b/core/src/renderer/null.rs
@@ -4,8 +4,7 @@ use crate::renderer::{self, Renderer};
use crate::svg;
use crate::text::{self, Text};
use crate::{
- Background, Color, Font, Pixels, Point, Radians, Rectangle, Size,
- Transformation,
+ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
};
impl Renderer for () {
@@ -192,13 +191,5 @@ impl svg::Renderer for () {
Size::default()
}
- fn draw_svg(
- &mut self,
- _handle: svg::Handle,
- _color: Option<Color>,
- _bounds: Rectangle,
- _rotation: Radians,
- _opacity: f32,
- ) {
- }
+ fn draw_svg(&mut self, _svg: svg::Svg, _bounds: Rectangle) {}
}
diff --git a/core/src/svg.rs b/core/src/svg.rs
index 946b8156..ac19b223 100644
--- a/core/src/svg.rs
+++ b/core/src/svg.rs
@@ -7,6 +7,66 @@ use std::hash::{Hash, Hasher as _};
use std::path::PathBuf;
use std::sync::Arc;
+/// A raster image that can be drawn.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Svg<H = Handle> {
+ /// The handle of the [`Svg`].
+ pub handle: H,
+
+ /// The [`Color`] filter to be applied to the [`Svg`].
+ ///
+ /// If some [`Color`] is set, the whole [`Svg`] will be
+ /// painted with it—ignoring any intrinsic colors.
+ ///
+ /// This can be useful for coloring icons programmatically
+ /// (e.g. with a theme).
+ pub color: Option<Color>,
+
+ /// The rotation to be applied to the image; on its center.
+ pub rotation: Radians,
+
+ /// The opacity of the [`Svg`].
+ ///
+ /// 0 means transparent. 1 means opaque.
+ pub opacity: f32,
+}
+
+impl Svg<Handle> {
+ /// Creates a new [`Svg`] with the given handle.
+ pub fn new(handle: impl Into<Handle>) -> Self {
+ Self {
+ handle: handle.into(),
+ color: None,
+ rotation: Radians(0.0),
+ opacity: 1.0,
+ }
+ }
+
+ /// Sets the [`Color`] filter of the [`Svg`].
+ pub fn color(mut self, color: impl Into<Color>) -> Self {
+ self.color = Some(color.into());
+ self
+ }
+
+ /// Sets the rotation of the [`Svg`].
+ pub fn rotation(mut self, rotation: impl Into<Radians>) -> Self {
+ self.rotation = rotation.into();
+ self
+ }
+
+ /// Sets the opacity of the [`Svg`].
+ pub fn opacity(mut self, opacity: impl Into<f32>) -> Self {
+ self.opacity = opacity.into();
+ self
+ }
+}
+
+impl From<&Handle> for Svg {
+ fn from(handle: &Handle) -> Self {
+ Svg::new(handle.clone())
+ }
+}
+
/// A handle of Svg data.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Handle {
@@ -95,12 +155,5 @@ pub trait Renderer: crate::Renderer {
fn measure_svg(&self, handle: &Handle) -> Size<u32>;
/// Draws an SVG with the given [`Handle`], an optional [`Color`] filter, and inside the provided `bounds`.
- fn draw_svg(
- &mut self,
- handle: Handle,
- color: Option<Color>,
- bounds: Rectangle,
- rotation: Radians,
- opacity: f32,
- );
+ fn draw_svg(&mut self, svg: Svg, bounds: Rectangle);
}
diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs
index c7515e46..2b4b45a6 100644
--- a/graphics/src/geometry.rs
+++ b/graphics/src/geometry.rs
@@ -16,7 +16,7 @@ pub use stroke::{LineCap, LineDash, LineJoin, Stroke};
pub use style::Style;
pub use text::Text;
-pub use crate::core::Image;
+pub use crate::core::{Image, Svg};
pub use crate::gradient::{self, Gradient};
use crate::cache::Cached;
diff --git a/graphics/src/geometry/frame.rs b/graphics/src/geometry/frame.rs
index 1a7af8e6..f3c0817c 100644
--- a/graphics/src/geometry/frame.rs
+++ b/graphics/src/geometry/frame.rs
@@ -1,7 +1,6 @@
//! Draw and generate geometry.
-use crate::core::svg;
-use crate::core::{Color, Point, Radians, Rectangle, Size, Vector};
-use crate::geometry::{self, Fill, Image, Path, Stroke, Text};
+use crate::core::{Point, Radians, Rectangle, Size, Vector};
+use crate::geometry::{self, Fill, Image, Path, Stroke, Svg, Text};
/// The region of a surface that can be used to draw geometry.
#[allow(missing_debug_implementations)]
@@ -206,15 +205,7 @@ pub trait Backend: Sized {
);
fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>);
-
- fn draw_svg(
- &mut self,
- handle: &svg::Handle,
- bounds: Rectangle,
- color: Option<Color>,
- rotation: Radians,
- opacity: f32,
- );
+ fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>);
fn into_geometry(self) -> Self::Geometry;
}
@@ -262,17 +253,8 @@ impl Backend for () {
) {
}
- fn into_geometry(self) -> Self::Geometry {}
-
fn draw_image(&mut self, _bounds: Rectangle, _image: impl Into<Image>) {}
+ fn draw_svg(&mut self, _bounds: Rectangle, _svg: impl Into<Svg>) {}
- fn draw_svg(
- &mut self,
- _handle: &svg::Handle,
- _bounds: Rectangle,
- _color: Option<Color>,
- _rotation: Radians,
- _opacity: f32,
- ) {
- }
+ fn into_geometry(self) -> Self::Geometry {}
}
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<Color>,
-
- /// 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),
}
}
}
diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs
index dc8a4107..fbd285db 100644
--- a/renderer/src/fallback.rs
+++ b/renderer/src/fallback.rs
@@ -3,8 +3,7 @@ use crate::core::image;
use crate::core::renderer;
use crate::core::svg;
use crate::core::{
- self, Background, Color, Image, Point, Radians, Rectangle, Size,
- Transformation,
+ self, Background, Color, Image, Point, Rectangle, Size, Svg, Transformation,
};
use crate::graphics;
use crate::graphics::compositor;
@@ -164,19 +163,8 @@ where
delegate!(self, renderer, renderer.measure_svg(handle))
}
- fn draw_svg(
- &mut self,
- handle: svg::Handle,
- color: Option<Color>,
- bounds: Rectangle,
- rotation: Radians,
- opacity: f32,
- ) {
- delegate!(
- self,
- renderer,
- renderer.draw_svg(handle, color, bounds, rotation, opacity)
- );
+ fn draw_svg(&mut self, svg: Svg, bounds: Rectangle) {
+ delegate!(self, renderer, renderer.draw_svg(svg, bounds));
}
}
@@ -425,8 +413,7 @@ where
#[cfg(feature = "geometry")]
mod geometry {
use super::Renderer;
- use crate::core::svg;
- use crate::core::{Color, Point, Radians, Rectangle, Size, Vector};
+ use crate::core::{Point, Radians, Rectangle, Size, Svg, Vector};
use crate::graphics::cache::{self, Cached};
use crate::graphics::geometry::{self, Fill, Image, Path, Stroke, Text};
@@ -561,19 +548,8 @@ mod geometry {
delegate!(self, frame, frame.draw_image(bounds, image));
}
- fn draw_svg(
- &mut self,
- handle: &svg::Handle,
- bounds: Rectangle,
- color: Option<Color>,
- rotation: Radians,
- opacity: f32,
- ) {
- delegate!(
- self,
- frame,
- frame.draw_svg(handle, bounds, color, rotation, opacity)
- );
+ fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
+ delegate!(self, frame, frame.draw_svg(bounds, svg));
}
fn push_transform(&mut self) {
diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs
index 88e8a9b1..196c36cf 100644
--- a/tiny_skia/src/engine.rs
+++ b/tiny_skia/src/engine.rs
@@ -580,13 +580,7 @@ impl Engine {
);
}
#[cfg(feature = "svg")]
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
+ Image::Vector(svg, bounds) => {
let physical_bounds = *bounds * _transformation;
if !_clip_bounds.intersects(&physical_bounds) {
@@ -597,7 +591,7 @@ impl Engine {
.then_some(_clip_mask as &_);
let center = physical_bounds.center();
- let radians = f32::from(*rotation);
+ let radians = f32::from(svg.rotation);
let transform = into_transform(_transformation).post_rotate_at(
radians.to_degrees(),
@@ -606,10 +600,10 @@ impl Engine {
);
self.vector_pipeline.draw(
- handle,
- *color,
+ &svg.handle,
+ svg.color,
physical_bounds,
- *opacity,
+ svg.opacity,
_pixels,
transform,
clip_mask,
diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs
index 7b0e68f4..659612d1 100644
--- a/tiny_skia/src/geometry.rs
+++ b/tiny_skia/src/geometry.rs
@@ -1,11 +1,10 @@
-use crate::core::svg;
use crate::core::text::LineHeight;
-use crate::core::{Color, Pixels, Point, Radians, Rectangle, Size, Vector};
+use crate::core::{self, Pixels, Point, Radians, Rectangle, Size, Svg, Vector};
use crate::graphics::cache::{self, Cached};
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::stroke::{self, Stroke};
-use crate::graphics::geometry::{self, Image, Path, Style};
-use crate::graphics::{self, Gradient, Text};
+use crate::graphics::geometry::{self, Path, Style};
+use crate::graphics::{self, Gradient, Image, Text};
use crate::Primitive;
use std::rc::Rc;
@@ -282,7 +281,7 @@ impl geometry::frame::Backend for Frame {
}
}
- fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
+ fn draw_image(&mut self, bounds: Rectangle, image: impl Into<core::Image>) {
let mut image = image.into();
let (bounds, external_rotation) =
@@ -293,24 +292,15 @@ impl geometry::frame::Backend for Frame {
self.images.push(graphics::Image::Raster(image, bounds));
}
- fn draw_svg(
- &mut self,
- handle: &svg::Handle,
- bounds: Rectangle,
- color: Option<Color>,
- rotation: Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
+ let mut svg = svg.into();
+
let (bounds, external_rotation) =
transform_rectangle(bounds, self.transform);
- self.images.push(graphics::Image::Vector {
- handle: handle.clone(),
- bounds,
- color,
- rotation: rotation + external_rotation,
- opacity,
- });
+ svg.rotation += external_rotation;
+
+ self.images.push(Image::Vector(svg, bounds));
}
}
diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs
index 5d3cb07b..bdfd4d38 100644
--- a/tiny_skia/src/layer.rs
+++ b/tiny_skia/src/layer.rs
@@ -1,7 +1,6 @@
use crate::core::renderer::Quad;
-use crate::core::svg;
use crate::core::{
- self, Background, Color, Point, Radians, Rectangle, Transformation,
+ self, Background, Color, Point, Rectangle, Svg, Transformation,
};
use crate::graphics::damage;
use crate::graphics::layer;
@@ -119,23 +118,10 @@ impl Layer {
pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
match image {
Image::Raster(raster, bounds) => {
- self.draw_raster(raster.clone(), bounds, transformation);
+ self.draw_raster(raster, bounds, transformation);
}
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
- self.draw_svg(
- handle.clone(),
- color,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ Image::Vector(svg, bounds) => {
+ self.draw_svg(svg, bounds, transformation);
}
}
}
@@ -153,20 +139,11 @@ impl Layer {
pub fn draw_svg(
&mut self,
- handle: svg::Handle,
- color: Option<Color>,
+ svg: Svg,
bounds: Rectangle,
transformation: Transformation,
- rotation: Radians,
- opacity: f32,
) {
- let svg = Image::Vector {
- handle,
- color,
- bounds: bounds * transformation,
- rotation,
- opacity,
- };
+ let svg = Image::Vector(svg, bounds * transformation);
self.images.push(svg);
}
diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs
index 00864c11..758921d4 100644
--- a/tiny_skia/src/lib.rs
+++ b/tiny_skia/src/lib.rs
@@ -396,23 +396,9 @@ impl core::svg::Renderer for Renderer {
self.engine.vector_pipeline.viewport_dimensions(handle)
}
- fn draw_svg(
- &mut self,
- handle: core::svg::Handle,
- color: Option<Color>,
- bounds: Rectangle,
- rotation: core::Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, svg: core::Svg, bounds: Rectangle) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_svg(
- handle,
- color,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ layer.draw_svg(svg, bounds, transformation);
}
}
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index 6b1bb074..be65ba36 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -1,18 +1,17 @@
//! Build and draw geometry.
-use crate::core::svg;
use crate::core::text::LineHeight;
use crate::core::{
- Color, Pixels, Point, Radians, Rectangle, Size, Transformation, Vector,
+ self, Pixels, Point, Radians, Rectangle, Size, Svg, Transformation, Vector,
};
use crate::graphics::cache::{self, Cached};
use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
- self, Image, LineCap, LineDash, LineJoin, Path, Stroke, Style,
+ self, LineCap, LineDash, LineJoin, Path, Stroke, Style,
};
use crate::graphics::gradient::{self, Gradient};
use crate::graphics::mesh::{self, Mesh};
-use crate::graphics::{self, Text};
+use crate::graphics::{Image, Text};
use crate::text;
use crate::triangle;
@@ -26,7 +25,7 @@ use std::sync::Arc;
pub enum Geometry {
Live {
meshes: Vec<Mesh>,
- images: Vec<graphics::Image>,
+ images: Vec<Image>,
text: Vec<Text>,
},
Cached(Cache),
@@ -35,7 +34,7 @@ pub enum Geometry {
#[derive(Debug, Clone)]
pub struct Cache {
pub meshes: Option<triangle::Cache>,
- pub images: Option<Arc<[graphics::Image]>>,
+ pub images: Option<Arc<[Image]>>,
pub text: Option<text::Cache>,
}
@@ -98,7 +97,7 @@ pub struct Frame {
clip_bounds: Rectangle,
buffers: BufferStack,
meshes: Vec<Mesh>,
- images: Vec<graphics::Image>,
+ images: Vec<Image>,
text: Vec<Text>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@@ -292,7 +291,7 @@ impl geometry::frame::Backend for Frame {
height: f32::INFINITY,
};
- self.text.push(graphics::Text::Cached {
+ self.text.push(Text::Cached {
content: text.content,
bounds,
color: text.color,
@@ -376,7 +375,7 @@ impl geometry::frame::Backend for Frame {
}
}
- fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
+ fn draw_image(&mut self, bounds: Rectangle, image: impl Into<core::Image>) {
let mut image = image.into();
let (bounds, external_rotation) =
@@ -384,27 +383,18 @@ impl geometry::frame::Backend for Frame {
image.rotation += external_rotation;
- self.images.push(graphics::Image::Raster(image, bounds));
+ self.images.push(Image::Raster(image, bounds));
}
- fn draw_svg(
- &mut self,
- handle: &svg::Handle,
- bounds: Rectangle,
- color: Option<Color>,
- rotation: Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
+ let mut svg = svg.into();
+
let (bounds, external_rotation) =
self.transforms.current.transform_rectangle(bounds);
- self.images.push(graphics::Image::Vector {
- handle: handle.clone(),
- color,
- bounds,
- rotation: rotation + external_rotation,
- opacity,
- });
+ svg.rotation += external_rotation;
+
+ self.images.push(Image::Vector(svg, bounds));
}
}
diff --git a/wgpu/src/image/mod.rs b/wgpu/src/image/mod.rs
index 2b0d6251..1b16022a 100644
--- a/wgpu/src/image/mod.rs
+++ b/wgpu/src/image/mod.rs
@@ -246,23 +246,22 @@ impl Pipeline {
Image::Raster { .. } => {}
#[cfg(feature = "svg")]
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
+ Image::Vector(svg, bounds) => {
let size = [bounds.width, bounds.height];
if let Some(atlas_entry) = cache.upload_vector(
- device, encoder, handle, *color, size, scale,
+ device,
+ encoder,
+ &svg.handle,
+ svg.color,
+ size,
+ scale,
) {
add_instances(
[bounds.x, bounds.y],
size,
- f32::from(*rotation),
- *opacity,
+ f32::from(svg.rotation),
+ svg.opacity,
true,
atlas_entry,
nearest_instances,
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 71fa0250..68d5a015 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -1,6 +1,5 @@
use crate::core::{
- self, renderer, Background, Color, Point, Radians, Rectangle,
- Transformation,
+ self, renderer, Background, Color, Point, Rectangle, Svg, Transformation,
};
use crate::graphics;
use crate::graphics::color;
@@ -118,21 +117,8 @@ impl Layer {
Image::Raster(image, bounds) => {
self.draw_raster(image, bounds, transformation);
}
- Image::Vector {
- handle,
- color,
- bounds,
- rotation,
- opacity,
- } => {
- self.draw_svg(
- handle.clone(),
- color,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ Image::Vector(svg, bounds) => {
+ self.draw_svg(svg, bounds, transformation);
}
}
}
@@ -150,20 +136,11 @@ impl Layer {
pub fn draw_svg(
&mut self,
- handle: crate::core::svg::Handle,
- color: Option<Color>,
+ svg: Svg,
bounds: Rectangle,
transformation: Transformation,
- rotation: Radians,
- opacity: f32,
) {
- let svg = Image::Vector {
- handle,
- color,
- bounds: bounds * transformation,
- rotation,
- opacity,
- };
+ let svg = Image::Vector(svg, bounds * transformation);
self.images.push(svg);
}
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index e5f45ad2..39167514 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -539,23 +539,9 @@ impl core::svg::Renderer for Renderer {
self.image_cache.borrow_mut().measure_svg(handle)
}
- fn draw_svg(
- &mut self,
- handle: core::svg::Handle,
- color_filter: Option<Color>,
- bounds: Rectangle,
- rotation: core::Radians,
- opacity: f32,
- ) {
+ fn draw_svg(&mut self, svg: core::Svg, bounds: Rectangle) {
let (layer, transformation) = self.layers.current_mut();
- layer.draw_svg(
- handle,
- color_filter,
- bounds,
- transformation,
- rotation,
- opacity,
- );
+ layer.draw_svg(svg, bounds, transformation);
}
}
diff --git a/widget/src/image.rs b/widget/src/image.rs
index 55dd9816..e04f2d6f 100644
--- a/widget/src/image.rs
+++ b/widget/src/image.rs
@@ -8,8 +8,8 @@ use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{
- self, ContentFit, Element, Layout, Length, Point, Rectangle, Rotation,
- Size, Vector, Widget,
+ ContentFit, Element, Layout, Length, Point, Rectangle, Rotation, Size,
+ Vector, Widget,
};
pub use image::{FilterMethod, Handle};
@@ -181,7 +181,7 @@ pub fn draw<Renderer, Handle>(
let render = |renderer: &mut Renderer| {
renderer.draw_image(
- core::Image {
+ image::Image {
handle: handle.clone(),
filter_method,
rotation: rotation.radians(),
diff --git a/widget/src/svg.rs b/widget/src/svg.rs
index 4551bcad..bec0090f 100644
--- a/widget/src/svg.rs
+++ b/widget/src/svg.rs
@@ -211,11 +211,13 @@ where
let render = |renderer: &mut Renderer| {
renderer.draw_svg(
- self.handle.clone(),
- style.color,
+ svg::Svg {
+ handle: self.handle.clone(),
+ color: style.color,
+ rotation: self.rotation.radians(),
+ opacity: self.opacity,
+ },
drawing_bounds,
- self.rotation.radians(),
- self.opacity,
);
};