|
|
|
@ -63,6 +63,9 @@ pub struct Layout {
|
|
|
|
|
direction: Direction,
|
|
|
|
|
margin: Margin,
|
|
|
|
|
constraints: Vec<Constraint>,
|
|
|
|
|
/// Whether the last chunk of the computed layout should be expanded to fill the available
|
|
|
|
|
/// space.
|
|
|
|
|
expand_to_fill: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
thread_local! {
|
|
|
|
@ -78,6 +81,7 @@ impl Default for Layout {
|
|
|
|
|
vertical: 0,
|
|
|
|
|
},
|
|
|
|
|
constraints: Vec::new(),
|
|
|
|
|
expand_to_fill: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -114,6 +118,11 @@ impl Layout {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn expand_to_fill(mut self, expand_to_fill: bool) -> Layout {
|
|
|
|
|
self.expand_to_fill = expand_to_fill;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Wrapper function around the cassowary-rs solver to be able to split a given
|
|
|
|
|
/// area into smaller ones based on the preferred widths or heights and the direction.
|
|
|
|
|
///
|
|
|
|
@ -222,12 +231,14 @@ fn split(area: Rect, layout: &Layout) -> Vec<Rect> {
|
|
|
|
|
Direction::Vertical => first.top() | EQ(REQUIRED) | f64::from(dest_area.top()),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if layout.expand_to_fill {
|
|
|
|
|
if let Some(last) = elements.last() {
|
|
|
|
|
ccs.push(match layout.direction {
|
|
|
|
|
Direction::Horizontal => last.right() | EQ(REQUIRED) | f64::from(dest_area.right()),
|
|
|
|
|
Direction::Vertical => last.bottom() | EQ(REQUIRED) | f64::from(dest_area.bottom()),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
match layout.direction {
|
|
|
|
|
Direction::Horizontal => {
|
|
|
|
|
for pair in elements.windows(2) {
|
|
|
|
@ -299,6 +310,7 @@ fn split(area: Rect, layout: &Layout) -> Vec<Rect> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if layout.expand_to_fill {
|
|
|
|
|
// Fix imprecision by extending the last item a bit if necessary
|
|
|
|
|
if let Some(last) = results.last_mut() {
|
|
|
|
|
match layout.direction {
|
|
|
|
@ -310,6 +322,7 @@ fn split(area: Rect, layout: &Layout) -> Vec<Rect> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
results
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|