summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-07-22 18:37:11 +0700
committerLibravatar GitHub <noreply@github.com>2021-07-22 18:37:11 +0700
commit82488de3ab2be3ad0b556ae5ccb754a989132dca (patch)
tree3af033841017b3f5860350c0a338644c4053bd10 /native
parent9cf5f3e1ef19f67b7939b9a747c2f66ad6b5275c (diff)
parentfe2392e9736477a047f605454c6892ed72378032 (diff)
downloadiced-82488de3ab2be3ad0b556ae5ccb754a989132dca.tar.gz
iced-82488de3ab2be3ad0b556ae5ccb754a989132dca.tar.bz2
iced-82488de3ab2be3ad0b556ae5ccb754a989132dca.zip
Merge pull request #885 from Chiheisen/master
image viewer: Only calculate viewport based width/length for Length::Unit|Shrink
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/image/viewer.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs
index a006c0af..405daf00 100644
--- a/native/src/widget/image/viewer.rs
+++ b/native/src/widget/image/viewer.rs
@@ -132,19 +132,30 @@ where
) -> layout::Node {
let (width, height) = renderer.dimensions(&self.handle);
- let aspect_ratio = width as f32 / height as f32;
-
let mut size = limits
.width(self.width)
.height(self.height)
.resolve(Size::new(width as f32, height as f32));
- let viewport_aspect_ratio = size.width / size.height;
-
- if viewport_aspect_ratio > aspect_ratio {
- size.width = width as f32 * size.height / height as f32;
+ let expansion_size = if height > width {
+ self.width
} else {
- size.height = height as f32 * size.width / width as f32;
+ self.height
+ };
+
+ // Only calculate viewport sizes if the images are constrained to a limited space.
+ // If they are Fill|Portion let them expand within their alotted space.
+ match expansion_size {
+ Length::Shrink | Length::Units(_) => {
+ let aspect_ratio = width as f32 / height as f32;
+ let viewport_aspect_ratio = size.width / size.height;
+ if viewport_aspect_ratio > aspect_ratio {
+ size.width = width as f32 * size.height / height as f32;
+ } else {
+ size.height = height as f32 * size.width / width as f32;
+ }
+ }
+ Length::Fill | Length::FillPortion(_) => {}
}
layout::Node::new(size)