diff options
author | 2024-05-03 13:51:57 +0200 | |
---|---|---|
committer | 2024-05-03 13:51:57 +0200 | |
commit | a94984d681875146d7af9f568bf8713503c1ca96 (patch) | |
tree | c0a4eef3b5ab5fc3450b21b37df99542c178f6e0 /widget | |
parent | 38cf87cb45484c7e52ddf775fb3abd7edbecc652 (diff) | |
parent | afb4cb99b92a196bf4dd15a09a8f9bd191293fdd (diff) | |
download | iced-a94984d681875146d7af9f568bf8713503c1ca96.tar.gz iced-a94984d681875146d7af9f568bf8713503c1ca96.tar.bz2 iced-a94984d681875146d7af9f568bf8713503c1ca96.zip |
Merge pull request #2424 from iced-rs/feature/image-opacity
Introduce dynamic `opacity` support for `Image` and `Svg`
Diffstat (limited to '')
-rw-r--r-- | widget/src/image.rs | 14 | ||||
-rw-r--r-- | widget/src/image/viewer.rs | 1 | ||||
-rw-r--r-- | widget/src/svg.rs | 12 |
3 files changed, 27 insertions, 0 deletions
diff --git a/widget/src/image.rs b/widget/src/image.rs index 45209a91..80e17263 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -38,6 +38,7 @@ pub struct Image<Handle> { content_fit: ContentFit, filter_method: FilterMethod, rotation: Rotation, + opacity: f32, } impl<Handle> Image<Handle> { @@ -50,6 +51,7 @@ impl<Handle> Image<Handle> { content_fit: ContentFit::default(), filter_method: FilterMethod::default(), rotation: Rotation::default(), + opacity: 1.0, } } @@ -84,6 +86,15 @@ impl<Handle> Image<Handle> { self.rotation = rotation.into(); self } + + /// Sets the opacity of the [`Image`]. + /// + /// 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 + } } /// Computes the layout of an [`Image`]. @@ -136,6 +147,7 @@ pub fn draw<Renderer, Handle>( content_fit: ContentFit, filter_method: FilterMethod, rotation: Rotation, + opacity: f32, ) where Renderer: image::Renderer<Handle = Handle>, Handle: Clone, @@ -173,6 +185,7 @@ pub fn draw<Renderer, Handle>( filter_method, drawing_bounds, rotation.radians(), + opacity, ); }; @@ -231,6 +244,7 @@ where self.content_fit, self.filter_method, self.rotation, + self.opacity, ); } } diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 5eb76452..8fe6f021 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -342,6 +342,7 @@ where ..Rectangle::with_size(image_size) }, Radians(0.0), + 1.0, ); }); }); 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, ); }; |