summaryrefslogtreecommitdiff
path: root/src/layout/image.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-10-16 11:39:26 +0200
committerLaurenz <laurmaedje@gmail.com>2021-10-23 20:22:47 +0200
commit6690bc23545bfe7275ad92de9e6bd11b7345caf4 (patch)
treee116a23f2f04b3053160aae09088830fdb21460f /src/layout/image.rs
parent1e74f7c407e42174b631cb7477f3c88252da7e25 (diff)
Revise block node contract
Frames produced by block nodes are now always treated as exactly one per given region and a frame must not be larger than its respective region. Any overflow must be handled internally. This means that stack and grid don't need to search for fitting regions anymore, since the child has already does that for them. This commit further moves stack spacing into a new `SpacingNode`.
Diffstat (limited to 'src/layout/image.rs')
-rw-r--r--src/layout/image.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/layout/image.rs b/src/layout/image.rs
index 4327375b..eb2fc221 100644
--- a/src/layout/image.rs
+++ b/src/layout/image.rs
@@ -23,18 +23,18 @@ impl Layout for ImageNode {
let pixel_size = Spec::new(img.width() as f64, img.height() as f64);
let pixel_ratio = pixel_size.x / pixel_size.y;
- let mut constraints = Constraints::new(regions.expand);
- constraints.set_base_if_linear(regions.base, Spec::new(self.width, self.height));
-
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) => {
- constraints.exact.x = Some(regions.current.w);
+ cts.exact.x = Some(regions.current.w);
if regions.current.w.is_finite() {
// Fit to width.
Size::new(regions.current.w, regions.current.w / pixel_ratio)
@@ -48,7 +48,7 @@ impl Layout for ImageNode {
let mut frame = Frame::new(size, size.h);
frame.push(Point::zero(), Element::Image(self.id, size));
- vec![frame.constrain(constraints)]
+ vec![frame.constrain(cts)]
}
}