Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CrossAxisAlignment to Flex to fill the available cross space #1551

Merged
merged 2 commits into from
Jan 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions druid/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ pub enum CrossAxisAlignment {
///
/// The calculated baseline is the maximum baseline offset of the children.
Baseline,
/// Fill the available space.
///
Fill,
}

/// Arrangement of children on the main axis.
Expand Down Expand Up @@ -712,6 +715,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 +805,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