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 }}');
}
struct OverlayTemplateContext<'c> {
label_text: &'c str,
label_font_size: f64,
+ label_y_adjust: f64,
cooldown_active: bool,
radius: f64,
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,
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)]