Skip to content

Commit

Permalink
Add a CrossAxisAlignment to Flex to fill the available cross space (#…
Browse files Browse the repository at this point in the history
…1551)

* Add a CrossAxisAlignment to Flex to fill the available cross space

* Complete comment as suggested by Colin

Co-authored-by: Colin Rofls <[email protected]>

Co-authored-by: Colin Rofls <[email protected]>
  • Loading branch information
tirix and cmyr authored Jan 31, 2021
1 parent 393db3e commit 4c865b9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions druid/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ pub enum CrossAxisAlignment {
///
/// The calculated baseline is the maximum baseline offset of the children.
Baseline,
/// Fill the available space.
///
/// The size on this axis is the size of the largest widget;
/// other widgets must fill that space.
Fill,
}

/// Arrangement of children on the main axis.
Expand Down Expand Up @@ -712,6 +717,15 @@ impl<T: Data> Widget<T> for Flex<T> {
let child_above_baseline = child_size.height - child_baseline;
extra_height + (max_above_baseline - child_above_baseline)
}
CrossAxisAlignment::Fill => {
let fill_size: Size = self
.direction
.pack(self.direction.major(child_size), minor_dim)
.into();
let child_bc = BoxConstraints::tight(fill_size);
child.widget.layout(ctx, &child_bc, data, env);
0.0
}
_ => {
let extra_minor = minor_dim - self.direction.minor(child_size);
alignment.align(extra_minor)
Expand Down Expand Up @@ -793,6 +807,7 @@ impl CrossAxisAlignment {
// in vertical layout, baseline is equivalent to center
CrossAxisAlignment::Center | CrossAxisAlignment::Baseline => (val / 2.0).round(),
CrossAxisAlignment::End => val,
CrossAxisAlignment::Fill => 0.0,
}
}
}
Expand Down

0 comments on commit 4c865b9

Please sign in to comment.