my $exp_y = $adj * $font_size;
die "$got_y != $exp_y" unless $got_y == $exp_y;
- filter_element('text', qw(x y font-family text-align text-anchor));
- $node->setAttribute('font-size', "{{ label_options.size }}px");
- $node->setAttribute('y', "{{ label_y_adjust }}");
- $node->setAttribute('fill', "{{ label_options.colour }}");
- $node->setAttribute('pointer-events', 'none');
+ # the attributes will be put back by Rust code,
+ # in TextOptions::start_element
+ filter_element('text', qw(font-family));
$node->removeChildNodes();
$node->appendText('{{ label_text }}');
+ $node->setNodeName('svg:text_tm3vljl79wqouvre');
}
-# This <text> node also acts as the sentinel for when the JS
-# wants to remove the cooldown timer.
-p process_node('textlabel', \&filter_text);
+sub process_text_node() {
+ $_ = process_node('textlabel', \&filter_text);
+ # This <text> node also acts as the sentinel for when the JS
+ # wants to remove the cooldown timer.
+ s/text_tm3vljl79wqouvre/{{ label_start_element }}/;
+ s/text_tm3vljl79wqouvre/text/;
+ die "$_ ?" if m/text_tm3vljl79wqouvre/;
+ $_;
+}
+p process_text_node();
p "{% if cooldown_active %}\n";
p process_node('timeblack', sub {
#[derive(Serialize, Debug)]
struct OverlayTemplateContext<'c> {
label_text: &'c str,
- label_y_adjust: f64,
- label_options: &'c TextOptions,
+ label_start_element: Html,
cooldown_active: bool,
radius: f64,
remprop: f64,
default()
};
- // todo: Ideally we would use text_options.start_element
- // but I don't see how to readily make a template suitable for that
+ let label_start_element = self.text_options.start_element();
let tc = OverlayTemplateContext {
label_text: label,
- label_options: &self.text_options,
- label_y_adjust: self.text_options.y_adjust(),
+ label_start_element,
cooldown_active,
radius: self.cooldown_radius,