Add margin controls, increase to 0.25in

main
Elnu 1 year ago
parent 52ed2c87d3
commit 31572568da

@ -31,21 +31,22 @@ enum Error {
fn positions<'a>( fn positions<'a>(
keys: &'a Vec<Key>, keys: &'a Vec<Key>,
size: SVGMeasure, size: SVGMeasure,
margin: SVGMeasure,
padding: SVGMeasure, padding: SVGMeasure,
dimensions: &DocumentDimensions, dimensions: &DocumentDimensions,
) -> Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))> { ) -> Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))> {
let grid = size + padding; let grid = size + padding;
let mut x = padding; let mut x = margin;
let mut y = padding; let mut y = margin;
let mut positions = Vec::with_capacity(keys.len()); let mut positions = Vec::with_capacity(keys.len());
for key in keys { for key in keys {
if let Key::Break = key { if let Key::Break = key {
x = padding; x = margin;
y = y + grid; y = y + grid;
continue; continue;
} }
if x + grid > dimensions.width { if x + grid > dimensions.width - margin {
x = padding; x = margin;
y = y + grid; y = y + grid;
} }
positions.push((key, (x, y))); positions.push((key, (x, y)));
@ -66,8 +67,9 @@ fn main() -> Result<(), Error> {
}; };
let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter);
let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter); let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter);
let margin = SVGMeasure::new(0.25, SVGUnit::Inch);
let document = DocumentTemplate { let document = DocumentTemplate {
positions: positions(&KEYS, box_size, padding, &dimensions), positions: positions(&KEYS, box_size, margin, padding, &dimensions),
dimensions: &dimensions, dimensions: &dimensions,
box_size, box_size,
}; };

Loading…
Cancel
Save