row_col_toplevel_layout: fix handling of spacing / scaling
Spacing shouldn't be multiplied by the scale factor. It should be added seperately.
This commit is contained in:
parent
fcd8fa4336
commit
6fd237ac39
1 changed files with 19 additions and 4 deletions
|
|
@ -17,8 +17,18 @@ impl RowColToplevelLayout {
|
|||
|
||||
// Get total requested main axis length if widget could have all the space
|
||||
pub fn requested_main_total(&self, toplevels: &[LayoutToplevel<'_, AxisSize>]) -> f32 {
|
||||
let total_spacing = self.spacing as usize * (toplevels.len().saturating_sub(1)).max(0);
|
||||
toplevels.iter().map(|t| t.preferred_size.main).sum::<f32>() + total_spacing as f32
|
||||
self.requested_main_total_without_spacing(toplevels) + self.total_spacing(toplevels)
|
||||
}
|
||||
|
||||
fn requested_main_total_without_spacing(
|
||||
&self,
|
||||
toplevels: &[LayoutToplevel<'_, AxisSize>],
|
||||
) -> f32 {
|
||||
toplevels.iter().map(|t| t.preferred_size.main).sum::<f32>()
|
||||
}
|
||||
|
||||
fn total_spacing(&self, toplevels: &[LayoutToplevel<'_, AxisSize>]) -> f32 {
|
||||
(self.spacing as usize * toplevels.len().saturating_sub(1)).max(0) as f32
|
||||
}
|
||||
|
||||
pub fn requested_cross_max(&self, toplevels: &[LayoutToplevel<'_, AxisSize>]) -> f32 {
|
||||
|
|
@ -34,7 +44,8 @@ impl RowColToplevelLayout {
|
|||
max_limit: AxisSize,
|
||||
toplevels: &[LayoutToplevel<'_, AxisSize>],
|
||||
) -> f32 {
|
||||
let scale_factor_main = max_limit.main / self.requested_main_total(toplevels);
|
||||
let scale_factor_main = (max_limit.main - self.total_spacing(toplevels))
|
||||
/ self.requested_main_total_without_spacing(toplevels);
|
||||
let scale_factor_cross = max_limit.cross / self.requested_cross_max(toplevels);
|
||||
scale_factor_main.min(scale_factor_cross).min(1.)
|
||||
}
|
||||
|
|
@ -61,7 +72,11 @@ impl AxisToplevelLayout for RowColToplevelLayout {
|
|||
let scale_factor = self.scale_factor(max_limit, toplevels);
|
||||
|
||||
// Add padding to center if total requested size doesn't fill available space
|
||||
let padding = (max_limit.main - scale_factor * requested_main_total).max(0.) / 2.;
|
||||
let padding = (max_limit.main
|
||||
- scale_factor * self.requested_main_total_without_spacing(toplevels)
|
||||
- self.total_spacing(toplevels))
|
||||
.max(0.)
|
||||
/ 2.;
|
||||
|
||||
let mut total_main = padding;
|
||||
let mut first = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue