From 31b9a88edb6a5f86bdb1c13ac693ecd90f6b9999 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Mon, 14 Aug 2023 16:09:09 -0700 Subject: [PATCH 1/6] Add text --- dyesub-tool/src/svg/measure.rs | 4 ++-- dyesub-tool/templates/document.xml | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/dyesub-tool/src/svg/measure.rs b/dyesub-tool/src/svg/measure.rs index fd59c9f..092c2a6 100644 --- a/dyesub-tool/src/svg/measure.rs +++ b/dyesub-tool/src/svg/measure.rs @@ -23,11 +23,11 @@ impl SVGMeasure { Self { measure, unit } } - fn to_user_units(self) -> f64 { + pub fn to_user_units(self) -> f64 { self.measure * self.unit.to_user_units() } - fn to_unit(self, unit: SVGUnit) -> Self { + pub fn to_unit(self, unit: SVGUnit) -> Self { SVGMeasure { measure: self.to_user_units() / unit.to_user_units(), unit, diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index 7804fe5..de05c53 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -1,7 +1,13 @@ + + + {% for (x, y) in positions %} - + + + + {% endfor %} From 20e0b8dd084d1e00ed606320a346c73eda70fc03 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 10:11:22 -0700 Subject: [PATCH 2/6] Show all letter keys, create Key struct --- dyesub-tool/src/key/mod.rs | 28 ++++++++++++++++++++++++ dyesub-tool/src/key/oyayubi.rs | 34 ++++++++++++++++++++++++++++++ dyesub-tool/src/main.rs | 30 ++++++++++++++------------ dyesub-tool/templates/document.xml | 13 ++++++++++-- 4 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 dyesub-tool/src/key/mod.rs create mode 100644 dyesub-tool/src/key/oyayubi.rs diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs new file mode 100644 index 0000000..52f710f --- /dev/null +++ b/dyesub-tool/src/key/mod.rs @@ -0,0 +1,28 @@ +mod oyayubi; +pub use oyayubi::OYAYUBI; + +use std::fmt::{Display, self}; + +pub struct Key { + pub latin: char, + pub normal: char, + pub shift: char, + pub alt_shift: Option, +} + +impl Display for Key { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.latin) + } +} + +impl Key { + const fn new(latin: char, normal: char, shift: char, alt_shift: Option) -> Self { + Self { + latin, + normal, + shift, + alt_shift, + } + } +} \ No newline at end of file diff --git a/dyesub-tool/src/key/oyayubi.rs b/dyesub-tool/src/key/oyayubi.rs new file mode 100644 index 0000000..d94a77c --- /dev/null +++ b/dyesub-tool/src/key/oyayubi.rs @@ -0,0 +1,34 @@ +use super::Key; + +pub const OYAYUBI: [Key; 30] = [ + Key::new('Q', '。', 'ぁ', None), + Key::new('W', 'か', 'え', None), + Key::new('E', 'た', 'り', None), + Key::new('R', 'こ', 'ゃ', None), + Key::new('T', 'さ', 'れ', None), + Key::new('Y', 'ら', 'よ', Some('ぱ')), + Key::new('U', 'ち', 'に', None), + Key::new('I', 'く', 'る', None), + Key::new('O', 'つ', 'ま', None), + Key::new('P', ',', 'ぇ', Some('ぴ')), + Key::new('A', 'う', 'を', None), + Key::new('S', 'し', 'あ', None), + Key::new('D', 'て', 'な', None), + Key::new('F', 'け', 'ゅ', None), + Key::new('G', 'せ', 'も', None), + Key::new('H', 'は', 'み', None), + Key::new('J', 'と', 'お', None), + Key::new('K', 'き', 'の', None), + Key::new('L', 'い', 'ょ', Some('ぽ')), + Key::new(';', 'ん', 'っ', None), // Missing + + Key::new('Z', '.', 'ぅ', None), + Key::new('X', 'ひ', 'ー', None), + Key::new('C', 'す', 'ろ', None), + Key::new('V', 'ふ', 'や', None), + Key::new('B', 'へ', 'ぃ', None), + Key::new('N', 'め', 'ぬ', Some('ぷ')), + Key::new('M', 'そ', 'ゆ', None), + Key::new(',', 'ね', 'む', Some('ぺ')), // Missing < + Key::new('.', 'ほ', 'わ', None), // Missing > + Key::new('?', '・', 'ぉ', Some('ゎ')) // Missing / +]; \ No newline at end of file diff --git a/dyesub-tool/src/main.rs b/dyesub-tool/src/main.rs index ba9def8..854d8f5 100644 --- a/dyesub-tool/src/main.rs +++ b/dyesub-tool/src/main.rs @@ -1,16 +1,19 @@ pub mod svg; use svg::*; +pub mod key; +use key::*; + use askama::Template; use derive_more::From; use std::{fs::OpenOptions, io::Write}; #[derive(Template)] #[template(path = "document.xml")] -struct DocumentTemplate { - dimensions: DocumentDimensions, +struct DocumentTemplate<'a> { + dimensions: &'a DocumentDimensions, box_size: SVGMeasure, - positions: Vec<(SVGMeasure, SVGMeasure)>, + positions: Vec<(&'a Key, (SVGMeasure, SVGMeasure))>, } struct DocumentDimensions { @@ -28,17 +31,19 @@ fn positions( size: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, - count: u32, -) -> Vec<(SVGMeasure, SVGMeasure)> { +) -> Vec<(&Key, (SVGMeasure, SVGMeasure))> { let grid = size + padding; let row_count = ((dimensions.width - padding * 2.0) / grid) as u32; - (0..count) - .map(|i| { + OYAYUBI + .iter() + .enumerate() + .map(|(i, key)| ( + key, ( - grid * (i % row_count).into() + padding, - grid * (i / row_count).into() + padding, + grid * (i as u32 % row_count).into() + padding, + grid * (i as u32 / row_count).into() + padding, ) - }) + )) .collect() } @@ -53,11 +58,10 @@ fn main() -> Result<(), Error> { height: SVGMeasure::new(11.0, SVGUnit::Inch), }; let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); - let boxes = 54; let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter); let document = DocumentTemplate { - positions: positions(box_size, padding, &dimensions, boxes), - dimensions, + positions: positions(box_size, padding, &dimensions), + dimensions: &dimensions, box_size, }; write!(file, "{}", document.render()?)?; diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index de05c53..7f7d4cb 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -4,10 +4,19 @@ - {% for (x, y) in positions %} + {% for (key, (x, y)) in positions %} - + {% let dy = "0.125em" %} + {% let font_size = "0.45cm" %} + {% let latin_font_size = "0.4cm" %} + {% let alt_shift_font_size = "0.325cm" %} + {{ key.latin }} + {{ key.shift }} + {{ key.normal }} + {% if let Some(alt_shift) = key.alt_shift %} + {{ alt_shift }} + {% endif %} {% endfor %} From f5e043c981b123c0057d690ad705c55c5498b3c4 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 10:21:49 -0700 Subject: [PATCH 3/6] Make Key an enum --- dyesub-tool/src/key/mod.rs | 28 +++++------- dyesub-tool/src/key/oyayubi.rs | 69 +++++++++++++++++------------- dyesub-tool/templates/document.xml | 25 ++++++----- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs index 52f710f..6a10d6b 100644 --- a/dyesub-tool/src/key/mod.rs +++ b/dyesub-tool/src/key/mod.rs @@ -3,26 +3,20 @@ pub use oyayubi::OYAYUBI; use std::fmt::{Display, self}; -pub struct Key { - pub latin: char, - pub normal: char, - pub shift: char, - pub alt_shift: Option, +pub enum Key { + Oyayubi { + latin: char, + normal: char, + shift: char, + alt_shift: Option, + } } impl Display for Key { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.latin) - } -} - -impl Key { - const fn new(latin: char, normal: char, shift: char, alt_shift: Option) -> Self { - Self { - latin, - normal, - shift, - alt_shift, - } + use Key::*; + write!(f, "{}", match self { + Oyayubi { latin, .. } => latin, + }) } } \ No newline at end of file diff --git a/dyesub-tool/src/key/oyayubi.rs b/dyesub-tool/src/key/oyayubi.rs index d94a77c..5bbac60 100644 --- a/dyesub-tool/src/key/oyayubi.rs +++ b/dyesub-tool/src/key/oyayubi.rs @@ -1,34 +1,43 @@ use super::Key; +const fn k(latin: char, normal: char, shift: char, alt_shift: Option) -> Key { + Key::Oyayubi { + latin, + normal, + shift, + alt_shift, + } +} + pub const OYAYUBI: [Key; 30] = [ - Key::new('Q', '。', 'ぁ', None), - Key::new('W', 'か', 'え', None), - Key::new('E', 'た', 'り', None), - Key::new('R', 'こ', 'ゃ', None), - Key::new('T', 'さ', 'れ', None), - Key::new('Y', 'ら', 'よ', Some('ぱ')), - Key::new('U', 'ち', 'に', None), - Key::new('I', 'く', 'る', None), - Key::new('O', 'つ', 'ま', None), - Key::new('P', ',', 'ぇ', Some('ぴ')), - Key::new('A', 'う', 'を', None), - Key::new('S', 'し', 'あ', None), - Key::new('D', 'て', 'な', None), - Key::new('F', 'け', 'ゅ', None), - Key::new('G', 'せ', 'も', None), - Key::new('H', 'は', 'み', None), - Key::new('J', 'と', 'お', None), - Key::new('K', 'き', 'の', None), - Key::new('L', 'い', 'ょ', Some('ぽ')), - Key::new(';', 'ん', 'っ', None), // Missing + - Key::new('Z', '.', 'ぅ', None), - Key::new('X', 'ひ', 'ー', None), - Key::new('C', 'す', 'ろ', None), - Key::new('V', 'ふ', 'や', None), - Key::new('B', 'へ', 'ぃ', None), - Key::new('N', 'め', 'ぬ', Some('ぷ')), - Key::new('M', 'そ', 'ゆ', None), - Key::new(',', 'ね', 'む', Some('ぺ')), // Missing < - Key::new('.', 'ほ', 'わ', None), // Missing > - Key::new('?', '・', 'ぉ', Some('ゎ')) // Missing / + k('Q', '。', 'ぁ', None), + k('W', 'か', 'え', None), + k('E', 'た', 'り', None), + k('R', 'こ', 'ゃ', None), + k('T', 'さ', 'れ', None), + k('Y', 'ら', 'よ', Some('ぱ')), + k('U', 'ち', 'に', None), + k('I', 'く', 'る', None), + k('O', 'つ', 'ま', None), + k('P', ',', 'ぇ', Some('ぴ')), + k('A', 'う', 'を', None), + k('S', 'し', 'あ', None), + k('D', 'て', 'な', None), + k('F', 'け', 'ゅ', None), + k('G', 'せ', 'も', None), + k('H', 'は', 'み', None), + k('J', 'と', 'お', None), + k('K', 'き', 'の', None), + k('L', 'い', 'ょ', Some('ぽ')), + k(';', 'ん', 'っ', None), // Missing + + k('Z', '.', 'ぅ', None), + k('X', 'ひ', 'ー', None), + k('C', 'す', 'ろ', None), + k('V', 'ふ', 'や', None), + k('B', 'へ', 'ぃ', None), + k('N', 'め', 'ぬ', Some('ぷ')), + k('M', 'そ', 'ゆ', None), + k(',', 'ね', 'む', Some('ぺ')), // Missing < + k('.', 'ほ', 'わ', None), // Missing > + k('?', '・', 'ぉ', Some('ゎ')) // Missing / ]; \ No newline at end of file diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index 7f7d4cb..a905954 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -6,17 +6,20 @@ {% for (key, (x, y)) in positions %} - - {% let dy = "0.125em" %} - {% let font_size = "0.45cm" %} - {% let latin_font_size = "0.4cm" %} - {% let alt_shift_font_size = "0.325cm" %} - {{ key.latin }} - {{ key.shift }} - {{ key.normal }} - {% if let Some(alt_shift) = key.alt_shift %} - {{ alt_shift }} - {% endif %} + {% match key %} + {% when crate::key::Key::Oyayubi with { latin, normal, shift, alt_shift } %} + + {% let dy = "0.125em" %} + {% let font_size = "0.45cm" %} + {% let latin_font_size = "0.4cm" %} + {% let alt_shift_font_size = "0.325cm" %} + {{ latin }} + {{ shift }} + {{ normal }} + {% if let Some(alt_shift) = alt_shift %} + {{ alt_shift }} + {% endif %} + {% endmatch %} {% endfor %} From da997bd5b619ca206c99765ae6aa0e1d2b58d0d8 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 11:06:55 -0700 Subject: [PATCH 4/6] Add single keys with variable units --- dyesub-tool/src/key/mod.rs | 38 +++++++++++++++++++++++--- dyesub-tool/src/key/oyayubi.rs | 10 +------ dyesub-tool/src/main.rs | 43 +++++++++++++++++++----------- dyesub-tool/templates/document.xml | 18 ++++++++----- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs index 6a10d6b..d90bf4a 100644 --- a/dyesub-tool/src/key/mod.rs +++ b/dyesub-tool/src/key/mod.rs @@ -3,20 +3,52 @@ pub use oyayubi::OYAYUBI; use std::fmt::{Display, self}; -pub enum Key { +#[derive(Clone, Copy)] +pub enum Key<'a> { Oyayubi { latin: char, normal: char, shift: char, alt_shift: Option, + }, + Single { + text: &'a str, + u: f64, + }, +} + +pub const fn oyayubi<'a>(latin: char, normal: char, shift: char, alt_shift: Option) -> Key<'a> { + Key::Oyayubi { + latin, + normal, + shift, + alt_shift, } } -impl Display for Key { +pub const fn single<'a>(text: &'a str, u: f64) -> Key<'a> { + Key::Single { + text, + u, + } +} + +impl<'a> Key<'a> { + pub fn width_mod(&self) -> f64 { + use Key::*; + match self { + Oyayubi { .. } => 1.0, + Single { u, .. } => *u, + } + } +} + +impl<'a> Display for Key<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use Key::*; write!(f, "{}", match self { - Oyayubi { latin, .. } => latin, + Oyayubi { latin, .. } => latin.to_string(), + Single { text, .. } => text.to_string(), }) } } \ No newline at end of file diff --git a/dyesub-tool/src/key/oyayubi.rs b/dyesub-tool/src/key/oyayubi.rs index 5bbac60..ffffea5 100644 --- a/dyesub-tool/src/key/oyayubi.rs +++ b/dyesub-tool/src/key/oyayubi.rs @@ -1,13 +1,5 @@ use super::Key; - -const fn k(latin: char, normal: char, shift: char, alt_shift: Option) -> Key { - Key::Oyayubi { - latin, - normal, - shift, - alt_shift, - } -} +use super::oyayubi as k; pub const OYAYUBI: [Key; 30] = [ k('Q', '。', 'ぁ', None), diff --git a/dyesub-tool/src/main.rs b/dyesub-tool/src/main.rs index 854d8f5..f054c96 100644 --- a/dyesub-tool/src/main.rs +++ b/dyesub-tool/src/main.rs @@ -7,13 +7,14 @@ use key::*; use askama::Template; use derive_more::From; use std::{fs::OpenOptions, io::Write}; +use lazy_static::lazy_static; #[derive(Template)] #[template(path = "document.xml")] struct DocumentTemplate<'a> { dimensions: &'a DocumentDimensions, box_size: SVGMeasure, - positions: Vec<(&'a Key, (SVGMeasure, SVGMeasure))>, + positions: Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))>, } struct DocumentDimensions { @@ -27,24 +28,25 @@ enum Error { Template(askama::Error), } -fn positions( +fn positions<'a>( + keys: &'a Vec, size: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, -) -> Vec<(&Key, (SVGMeasure, SVGMeasure))> { +) -> Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))> { let grid = size + padding; - let row_count = ((dimensions.width - padding * 2.0) / grid) as u32; - OYAYUBI - .iter() - .enumerate() - .map(|(i, key)| ( - key, - ( - grid * (i as u32 % row_count).into() + padding, - grid * (i as u32 / row_count).into() + padding, - ) - )) - .collect() + let mut x = padding; + let mut y = padding; + let mut positions = Vec::with_capacity(keys.len()); + for key in keys { + if x + grid > dimensions.width { + x = padding; + y = y + grid; + } + positions.push((key, (x, y))); + x = x + size * key.width_mod() + padding; + } + positions } fn main() -> Result<(), Error> { @@ -60,10 +62,19 @@ fn main() -> Result<(), Error> { let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter); let document = DocumentTemplate { - positions: positions(box_size, padding, &dimensions), + positions: positions(&KEYS, box_size, padding, &dimensions), dimensions: &dimensions, box_size, }; write!(file, "{}", document.render()?)?; Ok(()) } + +lazy_static! { + static ref KEYS: Vec> = { + let mut keys = OYAYUBI.to_vec(); + keys.push(single("親指左", 3.0)); + keys.push(single("親指右", 3.0)); + keys + }; +} \ No newline at end of file diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index a905954..07e94ae 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -5,20 +5,24 @@ {% for (key, (x, y)) in positions %} - + {% let width = box_size * key.width_mod() %} + + + {% let dy = "0.125em" %} {% match key %} {% when crate::key::Key::Oyayubi with { latin, normal, shift, alt_shift } %} - - {% let dy = "0.125em" %} {% let font_size = "0.45cm" %} {% let latin_font_size = "0.4cm" %} {% let alt_shift_font_size = "0.325cm" %} - {{ latin }} - {{ shift }} - {{ normal }} + {{ latin }} + {{ shift }} + {{ normal }} {% if let Some(alt_shift) = alt_shift %} - {{ alt_shift }} + {{ alt_shift }} {% endif %} + {% when crate::key::Key::Single with { text, u } %} + {% let font_size = "0.5cm" %} + {{ text }} {% endmatch %} {% endfor %} From 52ed2c87d3f57a1bd57cb37c6d8e75d99e156962 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 11:34:46 -0700 Subject: [PATCH 5/6] Add icon keys and row breaks --- dyesub-tool/assets/next.svg | 3 + dyesub-tool/assets/nixos.svg | 124 +++++++++++++++++++++++++++++ dyesub-tool/assets/playpause.svg | 3 + dyesub-tool/assets/previous.svg | 3 + dyesub-tool/src/key/mod.rs | 16 ++++ dyesub-tool/src/main.rs | 11 +++ dyesub-tool/templates/document.xml | 4 + 7 files changed, 164 insertions(+) create mode 100644 dyesub-tool/assets/next.svg create mode 100644 dyesub-tool/assets/nixos.svg create mode 100644 dyesub-tool/assets/playpause.svg create mode 100644 dyesub-tool/assets/previous.svg diff --git a/dyesub-tool/assets/next.svg b/dyesub-tool/assets/next.svg new file mode 100644 index 0000000..b805ced --- /dev/null +++ b/dyesub-tool/assets/next.svg @@ -0,0 +1,3 @@ + + + diff --git a/dyesub-tool/assets/nixos.svg b/dyesub-tool/assets/nixos.svg new file mode 100644 index 0000000..8041d98 --- /dev/null +++ b/dyesub-tool/assets/nixos.svg @@ -0,0 +1,124 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/dyesub-tool/assets/playpause.svg b/dyesub-tool/assets/playpause.svg new file mode 100644 index 0000000..3a02310 --- /dev/null +++ b/dyesub-tool/assets/playpause.svg @@ -0,0 +1,3 @@ + + + diff --git a/dyesub-tool/assets/previous.svg b/dyesub-tool/assets/previous.svg new file mode 100644 index 0000000..b55a8f9 --- /dev/null +++ b/dyesub-tool/assets/previous.svg @@ -0,0 +1,3 @@ + + + diff --git a/dyesub-tool/src/key/mod.rs b/dyesub-tool/src/key/mod.rs index d90bf4a..28e3553 100644 --- a/dyesub-tool/src/key/mod.rs +++ b/dyesub-tool/src/key/mod.rs @@ -15,6 +15,11 @@ pub enum Key<'a> { text: &'a str, u: f64, }, + Icon { + icon_path: &'a str, + u: f64, + }, + Break, } pub const fn oyayubi<'a>(latin: char, normal: char, shift: char, alt_shift: Option) -> Key<'a> { @@ -33,12 +38,21 @@ pub const fn single<'a>(text: &'a str, u: f64) -> Key<'a> { } } +pub const fn icon<'a>(icon_path: &'a str, u: f64) -> Key<'a> { + Key::Icon { + icon_path, + u, + } +} + impl<'a> Key<'a> { pub fn width_mod(&self) -> f64 { use Key::*; match self { Oyayubi { .. } => 1.0, Single { u, .. } => *u, + Icon { u, .. } => *u, + Break => 0.0, } } } @@ -49,6 +63,8 @@ impl<'a> Display for Key<'a> { write!(f, "{}", match self { Oyayubi { latin, .. } => latin.to_string(), Single { text, .. } => text.to_string(), + Icon { icon_path, .. } => icon_path.to_string(), + Break => "".to_string(), }) } } \ No newline at end of file diff --git a/dyesub-tool/src/main.rs b/dyesub-tool/src/main.rs index f054c96..33139d2 100644 --- a/dyesub-tool/src/main.rs +++ b/dyesub-tool/src/main.rs @@ -39,6 +39,11 @@ fn positions<'a>( let mut y = padding; let mut positions = Vec::with_capacity(keys.len()); for key in keys { + if let Key::Break = key { + x = padding; + y = y + grid; + continue; + } if x + grid > dimensions.width { x = padding; y = y + grid; @@ -73,8 +78,14 @@ fn main() -> Result<(), Error> { lazy_static! { static ref KEYS: Vec> = { let mut keys = OYAYUBI.to_vec(); + keys.push(Key::Break); keys.push(single("親指左", 3.0)); keys.push(single("親指右", 3.0)); + keys.push(Key::Break); + keys.push(icon("assets/nixos.svg", 1.0)); + keys.push(icon("assets/playpause.svg", 1.0)); + keys.push(icon("assets/previous.svg", 1.0)); + keys.push(icon("assets/next.svg", 1.0)); keys }; } \ No newline at end of file diff --git a/dyesub-tool/templates/document.xml b/dyesub-tool/templates/document.xml index 07e94ae..49a9758 100644 --- a/dyesub-tool/templates/document.xml +++ b/dyesub-tool/templates/document.xml @@ -23,6 +23,10 @@ {% when crate::key::Key::Single with { text, u } %} {% let font_size = "0.5cm" %} {{ text }} + {% when crate::key::Key::Icon with { icon_path, u } %} + {% let icon_width_mm = 7.5 %} + + {% when crate::key::Key::Break %} {% endmatch %} {% endfor %} From 31572568daf0104bcb93ed7b2e42731b02f80d26 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 15 Aug 2023 11:37:39 -0700 Subject: [PATCH 6/6] Add margin controls, increase to 0.25in --- dyesub-tool/src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dyesub-tool/src/main.rs b/dyesub-tool/src/main.rs index 33139d2..0c0d63f 100644 --- a/dyesub-tool/src/main.rs +++ b/dyesub-tool/src/main.rs @@ -31,21 +31,22 @@ enum Error { fn positions<'a>( keys: &'a Vec, size: SVGMeasure, + margin: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, ) -> Vec<(&'a Key<'a>, (SVGMeasure, SVGMeasure))> { let grid = size + padding; - let mut x = padding; - let mut y = padding; + let mut x = margin; + let mut y = margin; let mut positions = Vec::with_capacity(keys.len()); for key in keys { if let Key::Break = key { - x = padding; + x = margin; y = y + grid; continue; } - if x + grid > dimensions.width { - x = padding; + if x + grid > dimensions.width - margin { + x = margin; y = y + grid; } positions.push((key, (x, y))); @@ -66,8 +67,9 @@ fn main() -> Result<(), Error> { }; let box_size = SVGMeasure::new(14.0, SVGUnit::Millimeter); let padding = SVGMeasure::new(2.5, SVGUnit::Millimeter); + let margin = SVGMeasure::new(0.25, SVGUnit::Inch); let document = DocumentTemplate { - positions: positions(&KEYS, box_size, padding, &dimensions), + positions: positions(&KEYS, box_size, margin, padding, &dimensions), dimensions: &dimensions, box_size, };