Merge branch 'targets' into 'master'

buttons: Buttons are next to each other, padding is visual only

Closes #110

See merge request Librem5/squeekboard!209
This commit is contained in:
Tobias Bernard
2019-10-18 19:14:04 +00:00
15 changed files with 57 additions and 94 deletions

View File

@ -321,8 +321,7 @@ pub mod c {
.map(|button| button.bounds.clone())
.collect()
}).collect();
let spacing = view.spacing.clone();
view.place_buttons_with_sizes(sizes, spacing);
view.place_buttons_with_sizes(sizes);
}
}
@ -433,10 +432,6 @@ pub mod c {
x: 0f64, y: 0f64,
width: 0f64, height: 0f64
},
spacing: Spacing {
button: 0f64,
row: 0f64,
},
rows: vec!(row),
};
@ -456,10 +451,6 @@ pub mod c {
x: 0f64, y: 0f64,
width: 0f64, height: 0f64
},
spacing: Spacing {
button: 0f64,
row: 0f64,
},
rows: Vec::new(),
};
assert_eq!(
@ -595,9 +586,7 @@ impl Row {
}
}
fn calculate_button_positions(outlines: Vec<c::Bounds>, button_spacing: f64)
-> Vec<c::Bounds>
{
fn calculate_button_positions(outlines: Vec<c::Bounds>) -> Vec<c::Bounds> {
let mut x_offset = 0f64;
outlines.iter().map(|outline| {
x_offset += outline.x; // account for offset outlines
@ -605,7 +594,7 @@ impl Row {
x: x_offset,
..outline.clone()
};
x_offset += outline.width + button_spacing;
x_offset += outline.width;
position
}).collect()
}
@ -653,7 +642,6 @@ pub struct Spacing {
pub struct View {
/// Position relative to keyboard origin
pub bounds: c::Bounds,
pub spacing: Spacing,
pub rows: Vec<Box<Row>>,
}
@ -665,9 +653,7 @@ impl View {
/// and derive a scaling factor that lets contents fit into view)
/// (or TODO: blow up view bounds to match contents
/// and then scale the entire thing)
fn calculate_row_positions(&self, sizes: Vec<Size>, row_spacing: f64)
-> Vec<c::Bounds>
{
fn calculate_row_positions(&self, sizes: Vec<Size>) -> Vec<c::Bounds> {
let mut y_offset = self.bounds.y;
sizes.into_iter().map(|size| {
let position = c::Bounds {
@ -676,7 +662,7 @@ impl View {
width: size.width,
height: size.height,
};
y_offset += size.height + row_spacing;
y_offset += size.height;
position
}).collect()
}
@ -686,13 +672,12 @@ impl View {
fn place_buttons_with_sizes(
&mut self,
button_outlines: Vec<Vec<c::Bounds>>,
spacing: Spacing,
) {
// Determine all positions
let button_positions: Vec<_>
= button_outlines.into_iter()
.map(|outlines| {
Row::calculate_button_positions(outlines, spacing.button)
Row::calculate_button_positions(outlines)
})
.collect();
@ -701,7 +686,7 @@ impl View {
.collect();
let row_positions
= self.calculate_row_positions(row_sizes, spacing.row);
= self.calculate_row_positions(row_sizes);
// Apply all positions
for ((mut row, row_position), button_positions)