toplevel_layout: Move logic into a requested_main_total method
This commit is contained in:
parent
136d02ce28
commit
eb69aba7b2
1 changed files with 13 additions and 7 deletions
|
|
@ -7,6 +7,18 @@ pub(crate) struct RowColToplevelLayout {
|
|||
pub spacing: u32,
|
||||
}
|
||||
|
||||
impl RowColToplevelLayout {
|
||||
// Get total requested main axis length if widget could have all the space
|
||||
fn requested_main_total(&self, toplevels: &[LayoutToplevel<'_>]) -> f32 {
|
||||
let total_spacing = self.spacing as usize * (toplevels.len().saturating_sub(1)).max(0);
|
||||
toplevels
|
||||
.iter()
|
||||
.map(|t| self.axis.main(t.preferred_size))
|
||||
.sum::<f32>()
|
||||
+ total_spacing as f32
|
||||
}
|
||||
}
|
||||
|
||||
impl ToplevelLayout for RowColToplevelLayout {
|
||||
fn size(&self) -> Size<Length> {
|
||||
Size {
|
||||
|
|
@ -21,13 +33,7 @@ impl ToplevelLayout for RowColToplevelLayout {
|
|||
max_limit: Size,
|
||||
toplevels: &[LayoutToplevel<'_>],
|
||||
) -> impl Iterator<Item = Rectangle> {
|
||||
// Get total requested main axis length if widget could have all the space
|
||||
let total_spacing = self.spacing as usize * (toplevels.len().saturating_sub(1)).max(0);
|
||||
let requested_main_total: f32 = toplevels
|
||||
.iter()
|
||||
.map(|t| self.axis.main(t.preferred_size))
|
||||
.sum::<f32>()
|
||||
+ total_spacing as f32;
|
||||
let requested_main_total = self.requested_main_total(toplevels);
|
||||
let scale_factor = (self.axis.main(max_limit) / requested_main_total).min(1.0);
|
||||
let max_cross = self.axis.cross(max_limit);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue