From 029d2c4e029bd8eb796cbb007a8529d819bf173f Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 12 Sep 2021 17:40:03 +0200 Subject: [PATCH] SdfTerm: calculate layer size & offset with configurable font size --- sdf_editor/src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sdf_editor/src/main.rs b/sdf_editor/src/main.rs index 624c219..3181b41 100644 --- a/sdf_editor/src/main.rs +++ b/sdf_editor/src/main.rs @@ -72,10 +72,13 @@ impl Observer> for ColorCollector { } struct SdfTerm { - pub src_view: Option>, + src_view: Option>, bg_layers: HashMap, (bool, LayerId2d)>, fg_layers: HashMap, (bool, LayerId2d)>, - //font: Arc>, + + font_height: usize, + //font: Mutex, + renderer: Arc> } @@ -85,7 +88,8 @@ impl SdfTerm { src_view: None, bg_layers: HashMap::new(), fg_layers: HashMap::new(), - //font: Arc::new(RwLock::new(Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf"),0).unwrap())), + font_height: 60, + //font: Mutex::new(Font::from_path(Path::new("/usr/share/fonts/TTF/FiraCode-Medium.ttf"),0).unwrap()), renderer } } @@ -121,8 +125,8 @@ impl SdfTerm { self.renderer.lock().unwrap().set_layer_info( id.into(), LayerInfo { - extent: (60, 100), - location: (pt.x as usize * 60, pt.y as usize * 100) + extent: (1 + self.font_height / 2, self.font_height), + location: (pt.x as usize * self.font_height / 2, pt.y as usize * self.font_height) }); self.bg_layers.insert(*pt, (false, id)); @@ -140,8 +144,8 @@ impl SdfTerm { self.renderer.lock().unwrap().set_layer_info( id.into(), LayerInfo { - extent: (60, 100), - location: (pt.x as usize * 60, pt.y as usize * 100) + extent: (1 + self.font_height / 2, self.font_height), + location: (pt.x as usize * self.font_height / 2, pt.y as usize * self.font_height) }); self.fg_layers.insert(*pt, (false, id));