summaryrefslogtreecommitdiffstats
path: root/widget/src/svg.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 13:25:58 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 13:25:58 +0200
commitfa9e1d96ea1924b51749b775ea0e67e69bc8a305 (patch)
tree20cb13d6e3074569a15a16c8b0d261b1875a2045 /widget/src/svg.rs
parent38cf87cb45484c7e52ddf775fb3abd7edbecc652 (diff)
downloadiced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.tar.gz
iced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.tar.bz2
iced-fa9e1d96ea1924b51749b775ea0e67e69bc8a305.zip
Introduce dynamic `opacity` support for `Image` and `Svg`
Diffstat (limited to '')
-rw-r--r--widget/src/svg.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/widget/src/svg.rs b/widget/src/svg.rs
index c1fccba1..4551bcad 100644
--- a/widget/src/svg.rs
+++ b/widget/src/svg.rs
@@ -30,6 +30,7 @@ where
content_fit: ContentFit,
class: Theme::Class<'a>,
rotation: Rotation,
+ opacity: f32,
}
impl<'a, Theme> Svg<'a, Theme>
@@ -45,6 +46,7 @@ where
content_fit: ContentFit::Contain,
class: Theme::default(),
rotation: Rotation::default(),
+ opacity: 1.0,
}
}
@@ -103,6 +105,15 @@ where
self.rotation = rotation.into();
self
}
+
+ /// Sets the opacity of the [`Svg`].
+ ///
+ /// It should be in the [0.0, 1.0] range—`0.0` meaning completely transparent,
+ /// and `1.0` meaning completely opaque.
+ pub fn opacity(mut self, opacity: impl Into<f32>) -> Self {
+ self.opacity = opacity.into();
+ self
+ }
}
impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
@@ -204,6 +215,7 @@ where
style.color,
drawing_bounds,
self.rotation.radians(),
+ self.opacity,
);
};