forge
Explore
Log in

Don't you dare go Hollow

layout: Fix rounding in height distribution

Browse files at this commit

cfa87d508ee496eab20e0dde6cd2478aa92822f3Ivan MolodetskikhParent: f19e171
Rounding before checking min height could artificially increase the
window height that we check, leading to an incorrectly satisfied min
constraint.
src/layout/workspace.rsmodified+20 -19
@@ -3072,23 +3072,25 @@ impl<W: LayoutElement> Column<W> {
3072 return;3072 return;
3073 }3073 }
3074 3074
3075- let min_size: Vec<_> = self.tiles.iter().map(Tile::min_size).collect();3075+ let min_size: Vec<_> = self
3076+ .tiles
3077+ .iter()
3078+ .map(Tile::min_size)
3079+ .map(|mut size| {
3080+ size.w = size.w.max(1.);
3081+ size.h = size.h.max(1.);
3082+ size
3083+ })
3084+ .collect();
3076 let max_size: Vec<_> = self.tiles.iter().map(Tile::max_size).collect();3085 let max_size: Vec<_> = self.tiles.iter().map(Tile::max_size).collect();
3077 3086
3078 // Compute the column width.3087 // Compute the column width.
3079 let min_width = min_size3088 let min_width = min_size
3080 .iter()3089 .iter()
3081- .filter_map(|size| {3090+ .map(|size| NotNan::new(size.w).unwrap())
3082- let w = size.w;
3083- if w == 0. {
3084- None
3085- } else {
3086- Some(NotNan::new(w).unwrap())
3087- }
3088- })
3089 .max()3091 .max()
3090 .map(NotNan::into_inner)3092 .map(NotNan::into_inner)
3091- .unwrap_or(1.);3093+ .unwrap();
3092 let max_width = max_size3094 let max_width = max_size
3093 .iter()3095 .iter()
3094 .filter_map(|size| {3096 .filter_map(|size| {
@@ -3129,7 +3131,7 @@ impl<W: LayoutElement> Column<W> {
3129 // Subtract all fixed-height tiles.3131 // Subtract all fixed-height tiles.
3130 for (h, (min_size, max_size)) in zip(&mut heights, zip(&min_size, &max_size)) {3132 for (h, (min_size, max_size)) in zip(&mut heights, zip(&min_size, &max_size)) {
3131 // Check if the tile has an exact height constraint.3133 // Check if the tile has an exact height constraint.
3132- if min_size.h > 0. && min_size.h == max_size.h {3134+ if min_size.h == max_size.h {
3133 *h = WindowHeight::Fixed(min_size.h);3135 *h = WindowHeight::Fixed(min_size.h);
3134 }3136 }
3135 3137
@@ -3137,9 +3139,7 @@ impl<W: LayoutElement> Column<W> {
3137 if max_size.h > 0. {3139 if max_size.h > 0. {
3138 *h = f64::min(*h, max_size.h);3140 *h = f64::min(*h, max_size.h);
3139 }3141 }
3140- if min_size.h > 0. {3142+ *h = f64::max(*h, min_size.h);
3141- *h = f64::max(*h, min_size.h);
3142- }
3143 3143
3144 height_left -= *h;3144 height_left -= *h;
3145 auto_tiles_left -= 1;3145 auto_tiles_left -= 1;
@@ -3182,19 +3182,20 @@ impl<W: LayoutElement> Column<W> {
3182 let factor = weight / total_weight_2;3182 let factor = weight / total_weight_2;
3183 3183
3184 // Compute the current auto height.3184 // Compute the current auto height.
3185- let auto = height_left_2 * factor;3185+ let mut auto = height_left_2 * factor;
3186- let mut auto = tile.tile_height_for_window_height(
3187- tile.window_height_for_tile_height(auto).round().max(1.),
3188- );
3189 3186
3190 // Check if the auto height satisfies the min height.3187 // Check if the auto height satisfies the min height.
3191- if min_size.h > 0. && min_size.h > auto {3188+ if min_size.h > auto {
3192 auto = min_size.h;3189 auto = min_size.h;
3193 *h = WindowHeight::Fixed(auto);3190 *h = WindowHeight::Fixed(auto);
3194 height_left -= auto;3191 height_left -= auto;
3195 total_weight -= weight;3192 total_weight -= weight;
3196 auto_tiles_left -= 1;3193 auto_tiles_left -= 1;
3197 unsatisfied_min = true;3194 unsatisfied_min = true;
3195+ } else {
3196+ auto = tile.tile_height_for_window_height(
3197+ tile.window_height_for_tile_height(auto).round().max(1.),
3198+ );
3198 }3199 }
3199 3200
3200 height_left_2 -= auto;3201 height_left_2 -= auto;