chiark / gitweb /
Move 0.35 magic value for font y adjustment into a Rust constant
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 22:24:57 +0000 (23:24 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 22:24:57 +0000 (23:24 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dice/overlay-template-extractor
src/dice.rs
src/pieces.rs

index cdc13c18279758432841d0ccdbb2ddf1e2a87290..9cd6b5b1b261422cb5a4f54339eb2c304a3af8a7 100755 (executable)
@@ -58,7 +58,7 @@ sub filter_circle () {
 sub filter_text () {
   filter_element('text', qw(x y font-family text-align text-anchor));
   $node->setAttribute('font-size', "{{ label_font_size }}px");
-  $node->setAttribute('y', "{{ label_font_size * 0.35 }}");
+  $node->setAttribute('y', "{{ label_y_adjust }}");
   $node->removeChildNodes();
   $node->appendText('{{ label_text }}');
 }
index 1e05dea1f286c19c54bcc522eabe0fb569672af1..a43c3e634e0b35863afe75053b3e87a367212980 100644 (file)
@@ -85,6 +85,7 @@ impl PieceXData for State {
 struct OverlayTemplateContext<'c> {
   label_text: &'c str,
   label_font_size: f64,
+  label_y_adjust: f64,
 
   cooldown_active: bool,
   radius: f64,
@@ -437,9 +438,13 @@ impl InertPieceTrait for Die {
       default()
     };
 
+    let label_font_size = DEFAULT_LABEL_FONT_SIZE;
+    
+
     let tc = OverlayTemplateContext {
       label_text: &label,
-      label_font_size: DEFAULT_LABEL_FONT_SIZE,
+      label_font_size,
+      label_y_adjust: label_font_size * SVG_FONT_Y_ADJUST_OF_FONT_SIZE,
 
       cooldown_active,
       radius: self.cooldown_radius,
index 0d1a8df0fdcad49138d9693ef5da26ba88489b77..f41fadc77268847cccea2e44844996fb47dbeb0a 100644 (file)
@@ -31,6 +31,13 @@ pub const SELECT_STROKE_WIDTH: f64 = 2.0;
 pub const DEFAULT_EDGE_WIDTH: f64 = 0.2;
 pub const INVISIBLE_EDGE_SENSITIVE: f64 = 2.;
 
+// When trying to centre text, we use text-align and/or text-anchor
+// to do the horizontal positioning, but vertical positioning is
+// troublesome.  We bodge it.  Multiple the font size (in pixels)
+// by this, and add it to the SVG y coordinate (ie, shufting the text
+// down).
+pub const SVG_FONT_Y_ADJUST_OF_FONT_SIZE: f64 = 0.35;
+
 fn default_edge_width() -> f64 { DEFAULT_EDGE_WIDTH }
 
 #[derive(Copy,Clone,Debug,Error,Serialize,Deserialize)]