summaryrefslogtreecommitdiff
path: root/src/library/image.rs
diff options
context:
space:
mode:
authorMartin <mhaug@live.de>2021-06-17 14:18:43 +0200
committerGitHub <noreply@github.com>2021-06-17 14:18:43 +0200
commite14e8047890afad5896c9f38ccdd8551f869be64 (patch)
treee65a448e88c0de84ae0790a92a00fd903ba197da /src/library/image.rs
parente2cdda67dc0e16b9a482aa3a4bfd5991db06d143 (diff)
Constraints (#31)
Diffstat (limited to 'src/library/image.rs')
-rw-r--r--src/library/image.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/library/image.rs b/src/library/image.rs
index e926b955..7e8489e5 100644
--- a/src/library/image.rs
+++ b/src/library/image.rs
@@ -2,7 +2,7 @@ use ::image::GenericImageView;
use super::*;
use crate::image::ImageId;
-use crate::layout::{AnyNode, Element, Frame, Layout, LayoutContext, Regions};
+use crate::layout::{AnyNode, Constrained, Constraints, Element, Frame, Layout, LayoutContext, Regions};
/// `image`: An image.
///
@@ -52,8 +52,11 @@ struct ImageNode {
}
impl Layout for ImageNode {
- fn layout(&self, _: &mut LayoutContext, regions: &Regions) -> Vec<Frame> {
+ fn layout(&self, _: &mut LayoutContext, regions: &Regions) -> Vec<Constrained<Frame>> {
let Regions { current, base, .. } = regions;
+ let mut constraints = Constraints::new(regions.expand);
+ constraints.set_base_using_linears(Spec::new(self.width, self.height), regions);
+
let width = self.width.map(|w| w.resolve(base.width));
let height = self.height.map(|w| w.resolve(base.height));
@@ -66,6 +69,8 @@ impl Layout for ImageNode {
(Some(width), None) => Size::new(width, width / pixel_ratio),
(None, Some(height)) => Size::new(height * pixel_ratio, height),
(None, None) => {
+ constraints.exact = current.to_spec().map(Some);
+
let ratio = current.width / current.height;
if ratio < pixel_ratio && current.width.is_finite() {
Size::new(current.width, current.width / pixel_ratio)
@@ -81,7 +86,7 @@ impl Layout for ImageNode {
let mut frame = Frame::new(size, size.height);
frame.push(Point::zero(), Element::Image(self.id, size));
- vec![frame]
+ vec![frame.constrain(constraints)]
}
}