diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-13 23:19:44 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-13 23:19:44 +0100 |
| commit | 272a4c228976466e9fa6cc100ad89f93dc5cc371 (patch) | |
| tree | ad02a6e57b07da061432d58ff0ca46d6777bdb97 /src/library/insert.rs | |
| parent | 1b53e27f270e3c040ee095573af9a5243980191a (diff) | |
Unbounded pages 🌌
Diffstat (limited to 'src/library/insert.rs')
| -rw-r--r-- | src/library/insert.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/library/insert.rs b/src/library/insert.rs index 8d60927a..51cbbf52 100644 --- a/src/library/insert.rs +++ b/src/library/insert.rs @@ -55,8 +55,11 @@ struct NodeImage { impl Layout for NodeImage { fn layout(&self, _: &mut LayoutContext, areas: &Areas) -> Layouted { - let Area { rem, full } = areas.current; - let pixel_ratio = (self.dimensions.0 as f64) / (self.dimensions.1 as f64); + let Areas { current, full, .. } = areas; + + let pixel_width = self.dimensions.0 as f64; + let pixel_height = self.dimensions.1 as f64; + let pixel_ratio = pixel_width / pixel_height; let width = self.width.map(|w| w.resolve(full.width)); let height = self.height.map(|w| w.resolve(full.height)); @@ -66,12 +69,15 @@ impl Layout for NodeImage { (Some(width), None) => Size::new(width, width / pixel_ratio), (None, Some(height)) => Size::new(height * pixel_ratio, height), (None, None) => { - let ratio = rem.width / rem.height; - if ratio < pixel_ratio { - Size::new(rem.width, rem.width / pixel_ratio) - } else { + let ratio = current.width / current.height; + if ratio < pixel_ratio && current.width.is_finite() { + Size::new(current.width, current.width / pixel_ratio) + } else if current.height.is_finite() { // TODO: Fix issue with line spacing. - Size::new(rem.height * pixel_ratio, rem.height) + Size::new(current.height * pixel_ratio, current.height) + } else { + // Totally unbounded area, we have to make up something. + Size::new(Length::pt(pixel_width), Length::pt(pixel_height)) } } }; |
