From 5e700219f9aa541c888ff1510ba8836aa5127706 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Dec 2019 17:37:30 +0000 Subject: [PATCH] parsing: Remove bounds which weren't used anyway --- data/keyboards/de.yaml | 17 ++++-------- data/keyboards/de_wide.yaml | 17 ++++-------- data/keyboards/el.yaml | 17 ++++-------- data/keyboards/es.yaml | 17 ++++-------- data/keyboards/fi.yaml | 17 ++++-------- data/keyboards/it.yaml | 17 ++++-------- data/keyboards/jp+kana.yaml | 17 ++++-------- data/keyboards/jp+kana_wide.yaml | 17 ++++-------- data/keyboards/no.yaml | 17 ++++-------- data/keyboards/number.yaml | 14 +++------- data/keyboards/se.yaml | 17 ++++-------- data/keyboards/us.yaml | 17 ++++-------- data/keyboards/us_wide.yaml | 17 ++++-------- src/data.rs | 45 ++++++++++++++------------------ tests/layout.yaml | 8 +----- tests/layout2.yaml | 8 +----- tests/layout3.yaml | 8 +----- tests/layout_key1.yaml | 8 +----- tests/layout_key2.yaml | 8 +----- tests/layout_key3.yaml | 8 +----- 20 files changed, 90 insertions(+), 221 deletions(-) diff --git a/data/keyboards/de.yaml b/data/keyboards/de.yaml index 2021f7d2..66566289 100644 --- a/data/keyboards/de.yaml +++ b/data/keyboards/de.yaml @@ -1,18 +1,11 @@ # Maintained by: Mark Müller --- -bounds: { x: 0, y: 1, width: 360, height: 208 } - outlines: - default: - bounds: { x: 0, y: 0, width: 35.33, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 52.67, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 99.67, height: 52 } - special: - bounds: { x: 0, y: 0, width: 35.33, height: 52 } + default: { width: 35.33, height: 52 } + altline: { width: 52.67, height: 52 } + wide: { width: 62, height: 52 } + spaceline: { width: 99.67, height: 52 } + special: { width: 35.33, height: 52 } views: base: diff --git a/data/keyboards/de_wide.yaml b/data/keyboards/de_wide.yaml index a96596f9..1f638557 100644 --- a/data/keyboards/de_wide.yaml +++ b/data/keyboards/de_wide.yaml @@ -1,18 +1,11 @@ # Maintained by: Mark Müller --- -bounds: { x: 0, y: 1, width: 540, height: 168 } - outlines: - default: - bounds: { x: 0, y: 0, width: 48, height: 42 } - altline: - bounds: { x: 0, y: 0, width: 81, height: 42 } - wide: - bounds: { x: 0, y: 0, width: 108, height: 42 } - spaceline: - bounds: { x: 0, y: 0, width: 216, height: 42 } - special: - bounds: { x: 0, y: 0, width: 48, height: 42 } + default: { width: 48, height: 42 } + altline: { width: 81, height: 42 } + wide: { width: 108, height: 42 } + spaceline: { width: 216, height: 42 } + special: { width: 48, height: 42 } views: base: diff --git a/data/keyboards/el.yaml b/data/keyboards/el.yaml index 70ec7be5..f24b207a 100644 --- a/data/keyboards/el.yaml +++ b/data/keyboards/el.yaml @@ -2,19 +2,12 @@ # University of the Aegean, Department of Mathematics, atsol@aegean.gr # Sep 2019 --- -bounds: { x: 0, y: 0.33, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 32, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 48.39024, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - outline7: - bounds: { x: 0, y: 0, width: 88.97561, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 150.5853, height: 52 } + default: { width: 32, height: 52 } + altline: { width: 48.39024, height: 52 } + wide: { width: 62, height: 52 } + outline7: { width: 88.97561, height: 52 } + spaceline: { width: 150.5853, height: 52 } views: base: diff --git a/data/keyboards/es.yaml b/data/keyboards/es.yaml index 2d021202..bc7ba73f 100644 --- a/data/keyboards/es.yaml +++ b/data/keyboards/es.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 1, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 35.33, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 52.67, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 99.67, height: 52 } - special: - bounds: { x: 0, y: 0, width: 44, height: 52 } + default: { width: 35.33, height: 52 } + altline: { width: 52.67, height: 52 } + wide: { width: 62, height: 52 } + spaceline: { width: 99.67, height: 52 } + special: { width: 44, height: 52 } views: base: diff --git a/data/keyboards/fi.yaml b/data/keyboards/fi.yaml index ce38007d..ec972f47 100644 --- a/data/keyboards/fi.yaml +++ b/data/keyboards/fi.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 0.33, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 32, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 48.39024, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - outline7: - bounds: { x: 0, y: 0, width: 88.97561, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 150.5853, height: 52 } + default: { width: 32, height: 52 } + altline: { width: 48.39024, height: 52 } + wide: { width: 62, height: 52 } + outline7: { width: 88.97561, height: 52 } + spaceline: { width: 150.5853, height: 52 } views: base: diff --git a/data/keyboards/it.yaml b/data/keyboards/it.yaml index 54b6f19f..7a05ed46 100644 --- a/data/keyboards/it.yaml +++ b/data/keyboards/it.yaml @@ -1,19 +1,12 @@ # Italian layout created by Antonio Pandolfo # 03 october 2019 --- -bounds: { x: 0, y: 1, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 35.33, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 52.67, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 99.67, height: 52 } - special: - bounds: { x: 0, y: 0, width: 44, height: 52 } + default: { width: 35.33, height: 52 } + altline: { width: 52.67, height: 52 } + wide: { width: 62, height: 52 } + spaceline: { width: 99.67, height: 52 } + special: { width: 44, height: 52 } views: base: diff --git a/data/keyboards/jp+kana.yaml b/data/keyboards/jp+kana.yaml index b20d2bf9..076a7db1 100644 --- a/data/keyboards/jp+kana.yaml +++ b/data/keyboards/jp+kana.yaml @@ -1,18 +1,11 @@ # Maintained by: Mark Müller --- -bounds: { x: 0, y: 1, width: 360, height: 208 } - outlines: - default: - bounds: { x: 0, y: 0, width: 62, height: 52 } - default-wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 62, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - special: - bounds: { x: 0, y: 0, width: 62, height: 52 } + default: { width: 62, height: 52 } + default-wide: { width: 62, height: 52 } + altline: { width: 62, height: 52 } + wide: { width: 62, height: 52 } + special: { width: 62, height: 52 } views: base: # hiragana diff --git a/data/keyboards/jp+kana_wide.yaml b/data/keyboards/jp+kana_wide.yaml index de1635d6..684cedfc 100644 --- a/data/keyboards/jp+kana_wide.yaml +++ b/data/keyboards/jp+kana_wide.yaml @@ -1,18 +1,11 @@ # Maintained by: Mark Müller --- -bounds: { x: 0, y: 1, width: 540, height: 168 } - outlines: - default: - bounds: { x: 0, y: 0, width: 62, height: 42 } - default-wide: - bounds: { x: 0, y: 0, width: 62, height: 42 } - altline: - bounds: { x: 0, y: 0, width: 62, height: 42 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 42 } - special: - bounds: { x: 0, y: 0, width: 62, height: 42 } + default: { width: 62, height: 42 } + default-wide: { width: 62, height: 42 } + altline: { width: 62, height: 42 } + wide: { width: 62, height: 42 } + special: { width: 62, height: 42 } views: base: # hiragana diff --git a/data/keyboards/no.yaml b/data/keyboards/no.yaml index 7a502501..27ff21ff 100644 --- a/data/keyboards/no.yaml +++ b/data/keyboards/no.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 0.33, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 32, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 48.39024, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - outline7: - bounds: { x: 0, y: 0, width: 88.97561, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 150.5853, height: 52 } + default: { width: 32, height: 52 } + altline: { width: 48.39024, height: 52 } + wide: { width: 62, height: 52 } + outline7: { width: 88.97561, height: 52 } + spaceline: { width: 150.5853, height: 52 } views: base: diff --git a/data/keyboards/number.yaml b/data/keyboards/number.yaml index 2f145aeb..3f672cd4 100644 --- a/data/keyboards/number.yaml +++ b/data/keyboards/number.yaml @@ -1,15 +1,9 @@ --- -bounds: { x: 0, y: 0.33, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 37.46341, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 48.39024, height: 52 } - outline7: - bounds: { x: 0, y: 0, width: 88.97561, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 120.5853, height: 52 } + default: { width: 37.46341, height: 52 } + altline: { width: 48.39024, height: 52 } + outline7: { width: 88.97561, height: 52 } + spaceline: { width: 120.5853, height: 52 } views: base: diff --git a/data/keyboards/se.yaml b/data/keyboards/se.yaml index dae7663f..0a0a127f 100644 --- a/data/keyboards/se.yaml +++ b/data/keyboards/se.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 0.33, width: 360, height: 210 } - outlines: - default: - bounds: { x: 0, y: 0, width: 32, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 48.39024, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - outline7: - bounds: { x: 0, y: 0, width: 88.97561, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 150.5853, height: 52 } + default: { width: 32, height: 52 } + altline: { width: 48.39024, height: 52 } + wide: { width: 62, height: 52 } + outline7: { width: 88.97561, height: 52 } + spaceline: { width: 150.5853, height: 52 } views: base: diff --git a/data/keyboards/us.yaml b/data/keyboards/us.yaml index 4d195ba1..d150c480 100644 --- a/data/keyboards/us.yaml +++ b/data/keyboards/us.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 1, width: 360, height: 208 } - outlines: - default: - bounds: { x: 0, y: 0, width: 35.33, height: 52 } - altline: - bounds: { x: 0, y: 0, width: 52.67, height: 52 } - wide: - bounds: { x: 0, y: 0, width: 62, height: 52 } - spaceline: - bounds: { x: 0, y: 0, width: 142, height: 52 } - special: - bounds: { x: 0, y: 0, width: 44, height: 52 } + default: { width: 35.33, height: 52 } + altline: { width: 52.67, height: 52 } + wide: { width: 62, height: 52 } + spaceline: { width: 142, height: 52 } + special: { width: 44, height: 52 } views: base: diff --git a/data/keyboards/us_wide.yaml b/data/keyboards/us_wide.yaml index 1c1cc54e..654db8f8 100644 --- a/data/keyboards/us_wide.yaml +++ b/data/keyboards/us_wide.yaml @@ -1,17 +1,10 @@ --- -bounds: { x: 0, y: 1, width: 540, height: 168 } - outlines: - default: - bounds: { x: 0, y: 0, width: 54, height: 42 } - altline: - bounds: { x: 0, y: 0, width: 81, height: 42 } - wide: - bounds: { x: 0, y: 0, width: 108, height: 42 } - spaceline: - bounds: { x: 0, y: 0, width: 216, height: 42 } - special: - bounds: { x: 0, y: 0, width: 54, height: 42 } + default: { width: 54, height: 42 } + altline: { width: 81, height: 42 } + wide: { width: 108, height: 42 } + spaceline: { width: 216, height: 42 } + special: { width: 54, height: 42 } views: base: diff --git a/src/data.rs b/src/data.rs index 54636f57..baa62e26 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,5 +1,7 @@ /**! The parsing of the data files for layouts */ +// TODO: find a nice way to make sure non-positive sizes don't break layouts + use std::cell::RefCell; use std::collections::{ HashMap, HashSet }; use std::env; @@ -216,21 +218,20 @@ fn load_layout_data_with_fallback( #[derive(Debug, Deserialize, PartialEq)] #[serde(deny_unknown_fields)] pub struct Layout { - /// FIXME: deprecate in favor of margins - bounds: Bounds, + #[serde(default)] + margins: Margins, views: HashMap>, #[serde(default)] buttons: HashMap, outlines: HashMap } -#[derive(Debug, Clone, Deserialize, PartialEq)] +#[derive(Debug, Clone, Deserialize, PartialEq, Default)] #[serde(deny_unknown_fields)] -struct Bounds { - x: f64, - y: f64, - width: f64, - height: f64, +struct Margins { + top: f64, + bottom: f64, + side: f64, } /// Buttons are embedded in a single string @@ -271,8 +272,8 @@ enum Action { #[derive(Debug, Clone, Deserialize, PartialEq)] #[serde(deny_unknown_fields)] struct Outline { - /// FIXME: replace with Size - bounds: Bounds, + width: f64, + height: f64, } /// Errors encountered loading the layout into yaml @@ -460,10 +461,10 @@ impl Layout { }, // FIXME: use a dedicated field margins: layout::Margins { - top: self.bounds.x, - left: self.bounds.y, - bottom: 0.0, - right: self.bounds.y, + top: self.margins.top, + left: self.margins.side, + bottom: self.margins.bottom, + right: self.margins.side, }, }), warning_handler, @@ -649,9 +650,7 @@ fn create_button( warning_handler.handle( &format!("No default outline defined! Using 1x1!") ); - Outline { - bounds: Bounds { x: 0f64, y: 0f64, width: 1f64, height: 1f64 }, - } + Outline { width: 1f64, height: 1f64 } }); layout::Button { @@ -659,8 +658,8 @@ fn create_button( outline_name: CString::new(outline_name).expect("Bad outline"), // TODO: do layout before creating buttons size: layout::Size { - width: outline.bounds.width, - height: outline.bounds.height, + width: outline.width, + height: outline.height, }, label: label, state: state, @@ -686,7 +685,7 @@ mod tests { assert_eq!( Layout::from_file(PathBuf::from("tests/layout.yaml")).unwrap(), Layout { - bounds: Bounds { x: 0f64, y: 0f64, width: 0f64, height: 0f64 }, + margins: Margins { top: 0f64, bottom: 0f64, side: 0f64 }, views: hashmap!( "base".into() => vec!("test".into()), ), @@ -701,11 +700,7 @@ mod tests { } }, outlines: hashmap!{ - "default".into() => Outline { - bounds: Bounds { - x: 0f64, y: 0f64, width: 0f64, height: 0f64 - }, - } + "default".into() => Outline { width: 0f64, height: 0f64 }, }, } ); diff --git a/tests/layout.yaml b/tests/layout.yaml index d7ccc7b9..c750510a 100644 --- a/tests/layout.yaml +++ b/tests/layout.yaml @@ -1,15 +1,9 @@ --- -bounds: - x: 0 - y: 0 - width: 0 - height: 0 views: base: - "test" outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 } buttons: test: diff --git a/tests/layout2.yaml b/tests/layout2.yaml index f8610ddb..de72bb84 100644 --- a/tests/layout2.yaml +++ b/tests/layout2.yaml @@ -1,11 +1,5 @@ --- # missing views -bounds: - x: 0 - y: 0 - width: 0 - height: 0 outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 } diff --git a/tests/layout3.yaml b/tests/layout3.yaml index 8065d4d0..75c67bf6 100644 --- a/tests/layout3.yaml +++ b/tests/layout3.yaml @@ -1,15 +1,9 @@ --- # extra field -bounds: - x: 0 - y: 0 - width: 0 - height: 0 views: base: - "test" outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 } bad_field: false diff --git a/tests/layout_key1.yaml b/tests/layout_key1.yaml index 89de08c6..2c67ff90 100644 --- a/tests/layout_key1.yaml +++ b/tests/layout_key1.yaml @@ -1,16 +1,10 @@ --- # punctuation -bounds: - x: 0 - y: 0 - width: 0 - height: 0 views: base: - "." outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 } buttons: ".": diff --git a/tests/layout_key2.yaml b/tests/layout_key2.yaml index a8372fc8..8a50415a 100644 --- a/tests/layout_key2.yaml +++ b/tests/layout_key2.yaml @@ -1,16 +1,10 @@ --- # punctuation -bounds: - x: 0 - y: 0 - width: 0 - height: 0 views: base: - "å" outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 } buttons: å: diff --git a/tests/layout_key3.yaml b/tests/layout_key3.yaml index 34383848..6a4586e5 100644 --- a/tests/layout_key3.yaml +++ b/tests/layout_key3.yaml @@ -1,14 +1,8 @@ --- # punctuation -bounds: - x: 0 - y: 0 - width: 0 - height: 0 views: base: - "か゚" # 2 codepoints outlines: - default: - bounds: { x: 0, y: 0, width: 0, height: 0 } + default: { width: 0, height: 0 }