diff --git a/src/widgets/toplevels/toplevel_layout/row_col_toplevel_layout.rs b/src/widgets/toplevels/toplevel_layout/row_col_toplevel_layout.rs index 48490a9..e3e116c 100644 --- a/src/widgets/toplevels/toplevel_layout/row_col_toplevel_layout.rs +++ b/src/widgets/toplevels/toplevel_layout/row_col_toplevel_layout.rs @@ -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::() + + total_spacing as f32 + } +} + impl ToplevelLayout for RowColToplevelLayout { fn size(&self) -> Size { Size { @@ -21,13 +33,7 @@ impl ToplevelLayout for RowColToplevelLayout { max_limit: Size, toplevels: &[LayoutToplevel<'_>], ) -> impl Iterator { - // 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::() - + 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);