diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-26 16:32:06 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-26 16:32:06 +0100 |
| commit | 3a15922d2ffc041c3523edb479f008a9034fd400 (patch) | |
| tree | 988fe103c0752696c1fade2123142a8db5361ab7 /src/library/image.rs | |
| parent | 393d74f9bb0d4c71a69108d5be261103c39f47f3 (diff) | |
X/Y abstractions
Diffstat (limited to 'src/library/image.rs')
| -rw-r--r-- | src/library/image.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/library/image.rs b/src/library/image.rs index 185d033a..92580f6e 100644 --- a/src/library/image.rs +++ b/src/library/image.rs @@ -47,16 +47,16 @@ impl Layout for ImageNode { let pxh = img.height() as f64; let pixel_ratio = pxw / pxh; - let current_ratio = current.w / current.h; + let current_ratio = current.x / current.y; let wide = pixel_ratio > current_ratio; // The space into which the image will be placed according to its fit. let canvas = if expand.x && expand.y { current - } else if expand.x || (wide && current.w.is_finite()) { - Size::new(current.w, current.h.min(current.w.safe_div(pixel_ratio))) - } else if current.h.is_finite() { - Size::new(current.w.min(current.h * pixel_ratio), current.h) + } else if expand.x || (wide && current.x.is_finite()) { + Size::new(current.x, current.y.min(current.x.safe_div(pixel_ratio))) + } else if current.y.is_finite() { + Size::new(current.x.min(current.y * pixel_ratio), current.y) } else { Size::new(Length::pt(pxw), Length::pt(pxh)) }; @@ -65,9 +65,9 @@ impl Layout for ImageNode { let size = match self.fit { ImageFit::Contain | ImageFit::Cover => { if wide == (self.fit == ImageFit::Contain) { - Size::new(canvas.w, canvas.w / pixel_ratio) + Size::new(canvas.x, canvas.x / pixel_ratio) } else { - Size::new(canvas.h * pixel_ratio, canvas.h) + Size::new(canvas.y * pixel_ratio, canvas.y) } } ImageFit::Stretch => canvas, |
