diff options
author | 2023-11-11 07:02:01 +0100 | |
---|---|---|
committer | 2023-11-11 07:22:51 +0100 | |
commit | a5125d6fea824df1191777fe3eb53a2f748208b9 (patch) | |
tree | 4c854e4367af13bf02ae0e052a28a95f79437f3a /widget/src/image.rs | |
parent | 75c9afc608a4a9ff44d60a8fb6f4a5819f05bf79 (diff) | |
download | iced-a5125d6fea824df1191777fe3eb53a2f748208b9.tar.gz iced-a5125d6fea824df1191777fe3eb53a2f748208b9.tar.bz2 iced-a5125d6fea824df1191777fe3eb53a2f748208b9.zip |
Refactor texture image filtering
- Support only `Linear` or `Nearest`
- Simplify `Layer` groups
- Move `FilterMethod` to `Image` and `image::Viewer`
Diffstat (limited to 'widget/src/image.rs')
-rw-r--r-- | widget/src/image.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/widget/src/image.rs b/widget/src/image.rs index 684f200c..67699102 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -13,7 +13,7 @@ use crate::core::{ use std::hash::Hash; -pub use image::{FilterMethod, Handle, TextureFilter}; +pub use image::{FilterMethod, Handle}; /// Creates a new [`Viewer`] with the given image `Handle`. pub fn viewer<Handle>(handle: Handle) -> Viewer<Handle> { @@ -37,6 +37,7 @@ pub struct Image<Handle> { width: Length, height: Length, content_fit: ContentFit, + filter_method: FilterMethod, } impl<Handle> Image<Handle> { @@ -47,6 +48,7 @@ impl<Handle> Image<Handle> { width: Length::Shrink, height: Length::Shrink, content_fit: ContentFit::Contain, + filter_method: FilterMethod::default(), } } @@ -65,11 +67,15 @@ impl<Handle> Image<Handle> { /// Sets the [`ContentFit`] of the [`Image`]. /// /// Defaults to [`ContentFit::Contain`] - pub fn content_fit(self, content_fit: ContentFit) -> Self { - Self { - content_fit, - ..self - } + pub fn content_fit(mut self, content_fit: ContentFit) -> Self { + self.content_fit = content_fit; + self + } + + /// Sets the [`FilterMethod`] of the [`Image`]. + pub fn filter_method(mut self, filter_method: FilterMethod) -> Self { + self.filter_method = filter_method; + self } } @@ -119,6 +125,7 @@ pub fn draw<Renderer, Handle>( layout: Layout<'_>, handle: &Handle, content_fit: ContentFit, + filter_method: FilterMethod, ) where Renderer: image::Renderer<Handle = Handle>, Handle: Clone + Hash, @@ -141,7 +148,7 @@ pub fn draw<Renderer, Handle>( ..bounds }; - renderer.draw(handle.clone(), drawing_bounds + offset); + renderer.draw(handle.clone(), filter_method, drawing_bounds + offset); }; if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height @@ -191,7 +198,13 @@ where _cursor: mouse::Cursor, _viewport: &Rectangle, ) { - draw(renderer, layout, &self.handle, self.content_fit); + draw( + renderer, + layout, + &self.handle, + self.content_fit, + self.filter_method, + ); } } |