From: Ian Jackson Date: Thu, 19 May 2022 18:57:48 +0000 (+0100) Subject: dice: Arrange to use text_options.start_element X-Git-Tag: otter-1.1.0~61 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7d552476f622cdb7c76a7020ba9597e42e4b44aa;p=otter.git dice: Arrange to use text_options.start_element What a palaver! Signed-off-by: Ian Jackson --- diff --git a/dice/overlay-template-extractor b/dice/overlay-template-extractor index 62c5e509..817a881d 100755 --- a/dice/overlay-template-extractor +++ b/dice/overlay-template-extractor @@ -67,17 +67,23 @@ sub filter_text () { 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 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 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 { diff --git a/src/dice.rs b/src/dice.rs index 22682941..e77a7fdd 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -88,8 +88,7 @@ impl PieceXData for State { #[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, @@ -506,13 +505,11 @@ impl InertPieceTrait for Die { 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,