summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-08-04 14:52:29 +0200
committerLibravatar GitHub <noreply@github.com>2024-08-04 14:52:29 +0200
commit145c3dc8fc4f92c400fbc3f8202ed22e1d498663 (patch)
treefe48b8e7f0021100aa2a0c697437527212af3475 /widget
parent9cccaebb04944f2295cadff716d9708f4caa5642 (diff)
parentcc076903dda18f79dbd82238f7a8216bab8c679d (diff)
downloadiced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.tar.gz
iced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.tar.bz2
iced-145c3dc8fc4f92c400fbc3f8202ed22e1d498663.zip
Merge pull request #2537 from iced-rs/feature/canvas-image-support
`image` and `svg` support for `canvas`
Diffstat (limited to 'widget')
-rw-r--r--widget/src/canvas.rs4
-rw-r--r--widget/src/image.rs13
-rw-r--r--widget/src/image/viewer.rs15
-rw-r--r--widget/src/svg.rs10
4 files changed, 25 insertions, 17 deletions
diff --git a/widget/src/canvas.rs b/widget/src/canvas.rs
index 73cef087..185fa082 100644
--- a/widget/src/canvas.rs
+++ b/widget/src/canvas.rs
@@ -8,8 +8,8 @@ pub use program::Program;
pub use crate::graphics::cache::Group;
pub use crate::graphics::geometry::{
- fill, gradient, path, stroke, Fill, Gradient, LineCap, LineDash, LineJoin,
- Path, Stroke, Style, Text,
+ fill, gradient, path, stroke, Fill, Gradient, Image, LineCap, LineDash,
+ LineJoin, Path, Stroke, Style, Text,
};
use crate::core;
diff --git a/widget/src/image.rs b/widget/src/image.rs
index 80e17263..e04f2d6f 100644
--- a/widget/src/image.rs
+++ b/widget/src/image.rs
@@ -43,7 +43,7 @@ pub struct Image<Handle> {
impl<Handle> Image<Handle> {
/// Creates a new [`Image`] with the given path.
- pub fn new<T: Into<Handle>>(handle: T) -> Self {
+ pub fn new(handle: impl Into<Handle>) -> Self {
Image {
handle: handle.into(),
width: Length::Shrink,
@@ -181,11 +181,14 @@ pub fn draw<Renderer, Handle>(
let render = |renderer: &mut Renderer| {
renderer.draw_image(
- handle.clone(),
- filter_method,
+ image::Image {
+ handle: handle.clone(),
+ filter_method,
+ rotation: rotation.radians(),
+ opacity,
+ snap: true,
+ },
drawing_bounds,
- rotation.radians(),
- opacity,
);
};
diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs
index b8b69b60..b1aad22c 100644
--- a/widget/src/image/viewer.rs
+++ b/widget/src/image/viewer.rs
@@ -6,8 +6,8 @@ use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
- Clipboard, ContentFit, Element, Layout, Length, Pixels, Point, Radians,
- Rectangle, Shell, Size, Vector, Widget,
+ Clipboard, ContentFit, Element, Image, Layout, Length, Pixels, Point,
+ Radians, Rectangle, Shell, Size, Vector, Widget,
};
/// A frame that displays an image with the ability to zoom in/out and pan.
@@ -349,11 +349,14 @@ where
let render = |renderer: &mut Renderer| {
renderer.with_translation(translation, |renderer| {
renderer.draw_image(
- self.handle.clone(),
- self.filter_method,
+ Image {
+ handle: self.handle.clone(),
+ filter_method: self.filter_method,
+ rotation: Radians(0.0),
+ opacity: 1.0,
+ snap: true,
+ },
drawing_bounds,
- Radians(0.0),
- 1.0,
);
});
};
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,
);
};