summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2020-05-25 20:04:34 +0200
committerrabite <rabite@posteo.de>2020-05-25 20:05:34 +0200
commit355d9a3101f6d8dc375807de79e368602f1cb87d (patch)
treef2b40185b85de2dbe5aaed506a8a7b4a6a7ae251
parenta20fd731687f651ba2842e16be1312090329a750 (diff)
fix size calculation of HBox widgetsHEADmaster
-rw-r--r--src/hbox.rs28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/hbox.rs b/src/hbox.rs
index 391aae0..9e92b55 100644
--- a/src/hbox.rs
+++ b/src/hbox.rs
@@ -89,32 +89,30 @@ impl<T> HBox<T> where T: Widget + PartialEq {
Ok(ratios)
}
- pub fn calculate_coordinates(&self)
- -> HResult<Vec<Coordinates>> {
+ pub fn calculate_coordinates(&self) -> HResult<Vec<Coordinates>> {
let box_coords = self.get_coordinates()?;
let box_xsize = box_coords.xsize();
let box_ysize = box_coords.ysize();
let box_top = box_coords.top().y();
- let mut ratios = match &self.ratios {
- Some(ratios) => ratios.clone(),
+ let ratios = match self.ratios.clone() {
+ Some(ratios) => ratios,
None => self.calculate_equal_ratios()?
};
- let mut ratios_sum: usize = ratios.iter().sum();
-
- ratios = ratios.iter().map(|&r|
- (r as f64 * box_xsize as f64 / ratios_sum as f64).round() as usize).collect();
+ let ratios_sum: usize = ratios.iter().sum();
- for r in &mut ratios {
- if *r < 10 { *r = 10 }
- }
+ let mut ratios = ratios.iter()
+ .map(|&r| (r as f64 * box_xsize as f64 / ratios_sum as f64).round() as usize)
+ .map(|r| if r < 10 { 10 } else { r })
+ .collect::<Vec<_>>();
- ratios_sum = ratios.iter().sum();
+ let mut ratios_sum: usize = ratios.iter().sum();
- while ratios_sum + ratios.len() > box_xsize as usize {
+ while ratios_sum + ratios.len() > box_xsize as usize + 1 {
let ratios_max = ratios.iter()
- .position(|&r| r == *ratios.iter().max().unwrap()).unwrap();
+ .position(|&r| r == *ratios.iter().max().unwrap())
+ .unwrap();
ratios[ratios_max] = ratios[ratios_max] - 1;
ratios_sum -= 1;
}
@@ -138,7 +136,7 @@ impl<T> HBox<T> where T: Widget + PartialEq {
size: Size((widget_xsize,
box_ysize)),
position: Position((widget_xpos,
- box_top))
+ box_top))
});
coords
});