summaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-05-17 15:23:04 +0200
committerLaurenz <laurmaedje@gmail.com>2021-05-17 15:23:04 +0200
commit24c4a746bc68874f2d1b0d1b726596930acaadcf (patch)
tree8288a78ab53c4d07952f0975ff5166068d4f4526 /src/layout/mod.rs
parent1003d320d40aa46a0a3fba49b09425ead1b4b584 (diff)
Move aspect ratio into stack
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index dad378f5..cb138753 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -155,10 +155,6 @@ pub struct Areas {
///
/// If this is false, the frame will shrink to fit its content.
pub fixed: Spec<bool>,
- /// The aspect ratio the resulting frame should respect.
- ///
- /// This property is only handled by the stack layouter.
- pub aspect: Option<f64>,
}
impl Areas {
@@ -170,7 +166,6 @@ impl Areas {
backlog: vec![],
last: None,
fixed,
- aspect: None,
}
}
@@ -182,16 +177,9 @@ impl Areas {
backlog: vec![],
last: Some(size),
fixed,
- aspect: None,
}
}
- /// Builder-style method for setting the aspect ratio.
- pub fn with_aspect(mut self, aspect: Option<f64>) -> Self {
- self.aspect = aspect;
- self
- }
-
/// Map all areas.
pub fn map<F>(&self, mut f: F) -> Self
where
@@ -203,7 +191,6 @@ impl Areas {
backlog: self.backlog.iter().copied().map(|s| f(s)).collect(),
last: self.last.map(f),
fixed: self.fixed,
- aspect: self.aspect,
}
}
@@ -224,4 +211,10 @@ impl Areas {
self.current.is_nan() || size.is_nan() || self.current == size
})
}
+
+ /// Shrink `current` to ensure that the aspect ratio can be satisfied.
+ pub fn apply_aspect_ratio(&mut self, ratio: f64) {
+ let Size { width, height } = self.current;
+ self.current = Size::new(width.min(ratio * height), height.min(width / ratio));
+ }
}