row: Less dense placing of buttons
This commit is contained in:
@ -368,40 +368,40 @@ pub struct Row {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Row {
|
impl Row {
|
||||||
fn place_buttons_with_sizes(&mut self, sizes: Vec<c::Bounds>) {
|
fn place_buttons_with_sizes(&mut self, outlines: Vec<c::Bounds>) {
|
||||||
for (mut button, bounds) in &mut self.buttons.iter_mut().zip(sizes) {
|
let max_height = outlines.iter().map(
|
||||||
button.bounds = Some(bounds);
|
|bounds| FloatOrd(bounds.height)
|
||||||
}
|
|
||||||
|
|
||||||
// Place buttons
|
|
||||||
let max_height = self.buttons.iter().map(
|
|
||||||
|button| FloatOrd(
|
|
||||||
button.bounds.as_ref().unwrap().height
|
|
||||||
)
|
|
||||||
).max()
|
).max()
|
||||||
.unwrap_or(FloatOrd(0f64))
|
.unwrap_or(FloatOrd(0f64))
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
self.buttons.iter_mut().fold(0f64, |acc, button| {
|
let mut acc = 0f64;
|
||||||
let mut bounds = button.bounds.as_mut().unwrap();
|
let x_offsets: Vec<f64> = outlines.iter().map(|outline| {
|
||||||
bounds.x = acc;
|
acc += outline.x; // account for offset outlines
|
||||||
acc + bounds.width + BUTTON_SPACING
|
let out = acc;
|
||||||
});
|
acc += outline.width + BUTTON_SPACING;
|
||||||
|
out
|
||||||
|
}).collect();
|
||||||
|
|
||||||
let total_width = match self.buttons.is_empty() {
|
let total_width = acc;
|
||||||
true => 0f64,
|
|
||||||
false => {
|
for ((mut button, outline), offset)
|
||||||
let last_button = &self.buttons[self.buttons.len() - 1];
|
in &mut self.buttons
|
||||||
let bounds = last_button.bounds.as_ref().unwrap();
|
.iter_mut()
|
||||||
bounds.x + bounds.width
|
.zip(outlines)
|
||||||
},
|
.zip(x_offsets) {
|
||||||
};
|
button.bounds = Some(c::Bounds {
|
||||||
|
x: offset,
|
||||||
|
..outline
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let old_row_bounds = self.bounds.as_ref().unwrap().clone();
|
let old_row_bounds = self.bounds.as_ref().unwrap().clone();
|
||||||
self.bounds = Some(c::Bounds {
|
self.bounds = Some(c::Bounds {
|
||||||
// FIXME: do centering of each row based on keyboard dimensions,
|
// FIXME: do centering of each row based on keyboard dimensions,
|
||||||
// one level up the iterators
|
// one level up the iterators
|
||||||
// now centering by comparing previous width to the new, calculated one
|
// now centering by comparing previous width to the new,
|
||||||
|
// calculated one
|
||||||
x: (old_row_bounds.width - total_width) / 2f64,
|
x: (old_row_bounds.width - total_width) / 2f64,
|
||||||
width: total_width,
|
width: total_width,
|
||||||
height: max_height,
|
height: max_height,
|
||||||
|
|||||||
Reference in New Issue
Block a user