diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-16 10:41:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-16 10:41:30 +0100 |
| commit | 0e0f340502beada1cd9ee23857f48b91a0d11a90 (patch) | |
| tree | e4e4087260720adf4bab57edeac6a3d3cb5f14cf /src/library/image.rs | |
| parent | bc118634aca5de415d211cab38c4eaa3d3cca25f (diff) | |
Revert page and inline levels
Diffstat (limited to 'src/library/image.rs')
| -rw-r--r-- | src/library/image.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/library/image.rs b/src/library/image.rs index b51e4e70..f93d4b54 100644 --- a/src/library/image.rs +++ b/src/library/image.rs @@ -36,23 +36,31 @@ pub struct ImageNode { pub height: Option<Linear>, } -impl InlineLevel for ImageNode { - fn layout(&self, ctx: &mut LayoutContext, space: Length, base: Size) -> Frame { +impl Layout for ImageNode { + fn layout( + &self, + ctx: &mut LayoutContext, + regions: &Regions, + ) -> Vec<Constrained<Rc<Frame>>> { let img = ctx.images.get(self.id); let pixel_size = Spec::new(img.width() as f64, img.height() as f64); let pixel_ratio = pixel_size.x / pixel_size.y; - let width = self.width.map(|w| w.resolve(base.w)); - let height = self.height.map(|w| w.resolve(base.h)); + let width = self.width.map(|w| w.resolve(regions.base.w)); + let height = self.height.map(|w| w.resolve(regions.base.h)); + + let mut cts = Constraints::new(regions.expand); + cts.set_base_if_linear(regions.base, Spec::new(self.width, self.height)); let size = match (width, height) { (Some(width), Some(height)) => Size::new(width, height), (Some(width), None) => Size::new(width, width / pixel_ratio), (None, Some(height)) => Size::new(height * pixel_ratio, height), (None, None) => { - if space.is_finite() { + cts.exact.x = Some(regions.current.w); + if regions.current.w.is_finite() { // Fit to width. - Size::new(space, space / pixel_ratio) + Size::new(regions.current.w, regions.current.w / pixel_ratio) } else { // Unbounded width, we have to make up something, // so it is 1pt per pixel. @@ -63,6 +71,7 @@ impl InlineLevel for ImageNode { let mut frame = Frame::new(size, size.h); frame.push(Point::zero(), Element::Image(self.id, size)); - frame + + vec![frame.constrain(cts)] } } |
