summaryrefslogtreecommitdiff
path: root/src/layout/stack.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-19 15:31:29 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-19 15:52:15 +0200
commita6f260ca39f70f82617eca87855789413715f47d (patch)
tree08141ae619bd21e0544d21433bce759aebc7ba83 /src/layout/stack.rs
parentfdab7158c91c52a4ace211c804fdd8e9110f56de (diff)
Refactor layouting a bit
Notably: - Handle aspect ratio in fixed node - Inline constraint inflation into pad node
Diffstat (limited to 'src/layout/stack.rs')
-rw-r--r--src/layout/stack.rs31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index 504c64aa..51d17807 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -1,5 +1,3 @@
-use decorum::N64;
-
use super::*;
/// A node that stacks its children.
@@ -11,10 +9,6 @@ pub struct StackNode {
/// The children are stacked along the `main` direction. The `cross`
/// direction is required for aligning the children.
pub dirs: Gen<Dir>,
- /// The fixed aspect ratio between width and height, if any.
- ///
- /// The resulting frames will satisfy `width = aspect * height`.
- pub aspect: Option<N64>,
/// The nodes to be stacked.
pub children: Vec<StackChild>,
}
@@ -83,10 +77,6 @@ impl<'a> StackLayouter<'a> {
// Disable expansion on the main axis for children.
regions.expand.set(main, false);
- if let Some(aspect) = stack.aspect {
- regions.current = regions.current.with_aspect(aspect.into_inner());
- }
-
Self {
stack,
main,
@@ -161,6 +151,7 @@ impl<'a> StackLayouter<'a> {
.max
.get_mut(self.main)
.set_min(self.used.main + size.main);
+
self.finish_region();
}
@@ -184,7 +175,7 @@ impl<'a> StackLayouter<'a> {
// Determine the stack's size dependening on whether the region is
// fixed.
- let mut size = Size::new(
+ let size = Size::new(
if expand.horizontal {
self.constraints.exact.horizontal = Some(self.full.width);
self.full.width
@@ -201,20 +192,6 @@ impl<'a> StackLayouter<'a> {
},
);
- // Make sure the stack's size satisfies the aspect ratio.
- if let Some(aspect) = self.stack.aspect {
- self.constraints.exact = self.full.to_spec().map(Some);
- self.constraints.min = Spec::splat(None);
- self.constraints.max = Spec::splat(None);
- let width = size
- .width
- .max(aspect.into_inner() * size.height)
- .min(self.full.width)
- .min(aspect.into_inner() * self.full.height);
-
- size = Size::new(width, width / aspect.into_inner());
- }
-
if self.overflowing {
self.constraints.min.vertical = None;
self.constraints.max.vertical = None;
@@ -259,10 +236,6 @@ impl<'a> StackLayouter<'a> {
}
self.regions.next();
- if let Some(aspect) = self.stack.aspect {
- self.regions.current = self.regions.current.with_aspect(aspect.into_inner());
- }
-
self.full = self.regions.current;
self.used = Gen::zero();
self.ruler = Align::Start;