chiark / gitweb /
Move text size into TextOptions, so dice now support setting text size
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 11:42:22 +0000 (12:42 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 18:57:56 +0000 (19:57 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dice/overlay-template-extractor
docs/gamespec.rst
src/dice.rs
src/spec.rs
src/ui.rs

index 3684b678ce476e788411be25f64ec8b60a0b2008..9ab896f71e9fe0b3682c015e10338fb2cd4d731b 100755 (executable)
@@ -57,7 +57,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('font-size', "{{ label_options.size }}px");
   $node->setAttribute('y', "{{ label_y_adjust }}");
   $node->setAttribute('fill', "{{ label_options.colour }}");
   $node->setAttribute('pointer-events', 'none');
index 7380282ceb3b6bb41778473a17f863f5530ba510..20587d8318ed64cece43d699d4795c8e13af31bd 100644 (file)
@@ -347,6 +347,9 @@ Parameters:
  * ``label.colour`` [string, defaults to black]:
    Colour to write the ``labels`` text strings.
 
+ * ``label.size`` [number, default 8]:
+   Font size for the ``labels`` text strings (in pixeels, svg ``px``).
+
  * ``cooldown``: Duration of the cooldown time.
    [duration - number(s) with units; default "4s"]
 
index 7a5eaae040b4bbc9a2b030705bdc3bff0db48d94..524d8d13ea460a2d6487f2fb5775141e5c4049fc 100644 (file)
@@ -88,7 +88,6 @@ impl PieceXData for State {
 #[derive(Serialize, Debug)]
 struct OverlayTemplateContext<'c> {
   label_text: &'c str,
-  label_font_size: f64,
   label_y_adjust: f64,
   label_options: &'c TextOptions,
   cooldown_active: bool,
@@ -151,7 +150,7 @@ impl PieceSpec for Spec {
       index_vec!["".into()]
     };
 
-    let text_options = self.label.resolve()?;
+    let text_options = self.label.resolve(DEFAULT_LABEL_FONT_SIZE)?;
 
     if_let!{ Some((nfaces,_)) = nfaces;
              else throw!(SpecError::MultipleFacesRequired) };
@@ -507,14 +506,10 @@ impl InertPieceTrait for Die {
       default()
     };
 
-    let label_font_size = DEFAULT_LABEL_FONT_SIZE;
-    
-
     let tc = OverlayTemplateContext {
       label_text: label,
       label_options: &self.text_options,
-      label_font_size,
-      label_y_adjust: label_font_size * SVG_FONT_Y_ADJUST_OF_FONT_SIZE,
+      label_y_adjust: self.text_options.size * SVG_FONT_Y_ADJUST_OF_FONT_SIZE,
 
       cooldown_active,
       radius: self.cooldown_radius,
index f7c0e4e541a45221fb91e8e18bfd69dae7d6da57..7634c5cdeec06de43af4bd0c17f04c3135002c3b 100644 (file)
@@ -244,6 +244,7 @@ impl PieceAngle {
 #[derive(Debug,Default,Clone,Serialize,Deserialize)]
 pub struct TextOptionsSpec {
   pub colour: Option<ColourSpec>,
+  pub size: Option<f64>,
 }
 
 #[derive(Debug,Copy,Clone,Eq,PartialEq)]
@@ -644,10 +645,11 @@ pub mod imp {
   impl TextOptionsSpec {
     #[throws(SpecError)]
     /// Default colour is always black
-    pub fn resolve(&self) -> TextOptions {
-      let TextOptionsSpec { colour } = self;
+    pub fn resolve(&self, default_size: f64) -> TextOptions {
+      let TextOptionsSpec { colour, size } = self;
       let colour = colour.resolve()?;
-      TextOptions { colour }
+      let size = size.unwrap_or(default_size);
+      TextOptions { colour, size }
     }
   }
 
index 35f41503ee4640ce69530b299e5cba2adefc6c66..fb35c410acc820c8f10041f05812bd7697c9f380 100644 (file)
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -29,6 +29,7 @@ pub const HTML_TEXT_LABEL_ELEM_START: HtmlLit =
 #[derive(Debug,Serialize,Deserialize,Clone)]
 pub struct TextOptions {
   pub colour: Colour,
+  pub size: f64, // px
 }
 
 /// Fudge factor