From 9830785f619ada26daf08c20ed1414604f92032e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 19 May 2022 18:55:19 +0100 Subject: [PATCH] currency: Support adjusting size of the unit text, separately Signed-off-by: Ian Jackson --- docs/gamespec.rst | 4 ++++ src/currency.rs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/gamespec.rst b/docs/gamespec.rst index aed2f8b7..1eddf0e0 100644 --- a/docs/gamespec.rst +++ b/docs/gamespec.rst @@ -447,6 +447,10 @@ Parameters: * ``label.size`` [number, default 6]: Font size for the value (in pixeels, svg ``px``). + * ``label.unit_rel_size`` [number, default 1]: + Relative font size for the unit part of the value. + (Proportion of the quantity.) + Exammple:: [[pieces]] diff --git a/src/currency.rs b/src/currency.rs index 61af1ff1..32050115 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -30,6 +30,8 @@ pub struct Spec { #[derive(Debug,Default,Clone,Serialize,Deserialize)] pub struct LabelSpec { + pub unit_rel_size: Option, + #[serde(flatten,default)] pub options: TextOptionsSpec, } @@ -39,6 +41,7 @@ pub struct Banknote { itemname: String, image: Arc, currency: String, + unit_size: f64, label_options: TextOptions, } @@ -56,10 +59,12 @@ impl PieceSpec for Spec { fn load(&self, PLA { gpc,ig,depth,.. }: PLA) -> SpecLoaded { gpc.rotateable = false; - let Spec { ref image, ref currency, qty, - label: LabelSpec { options: ref label_options } } = *self; + let Spec { ref image, ref currency, qty, label: LabelSpec { + options: ref label_options, unit_rel_size, + } } = *self; let label_options = label_options.resolve(DEFAULT_QTY_FONT_SIZE)?; + let unit_size = label_options.size * unit_rel_size.unwrap_or(1.); let SpecLoadedInert { p: image, occultable:_ } = image.load_inert(ig, depth)?; @@ -78,7 +83,7 @@ impl PieceSpec for Spec { let bnote = Banknote { image: image.into(), currency: currency.clone(), - itemname, label_options, + itemname, label_options, unit_size, }; gpc.fastsplit = FastSplitId::new_placeholder(); @@ -120,8 +125,9 @@ impl PieceTrait for Banknote { let value: &Value = gpc.xdata.get_exp()?; hwrite!(f, - r##"<{}>{}{}"##, - &self.label_options.start_element(), value.qty, &self.currency)?; + r##"<{}>{}{}"##, + &self.label_options.start_element(), value.qty, + &self.unit_size, &self.currency)?; } #[throws(ApiPieceOpError)] -- 2.30.2