chiark / gitweb /
currency: Offer occulted version
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 19:37:22 +0000 (20:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 19:54:44 +0000 (20:54 +0100)
But we don't do merging within occultations yet.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/currency.rs

index 1318788d609e41db7a7d77b95e14cfeaf3a10bd1..19107c85088b0d91283efdd9c016273b25752a3a 100644 (file)
@@ -66,7 +66,7 @@ impl PieceSpec for Spec {
     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:_ } =
+    let SpecLoadedInert { p: image, occultable: image_occultable } =
       image.load_inert(ig, depth)?;
 
     let itemname = format!("currency-{}", image.itemname());
@@ -80,6 +80,23 @@ impl PieceSpec for Spec {
 
     let _value: &mut Value = gpc.xdata_mut(|| Value { qty })?;
     let image: Arc<dyn InertPieceTrait> = image.into();
+
+    let occultable = Some({
+      let image = image_occultable
+        .map(|(_,o)| o)
+        .unwrap_or_else(|| image.clone());
+
+      (
+        LOI::Distinct,
+        Arc::new(Banknote {
+          image,
+          currency: currency.clone(),
+          itemname: itemname.clone(),
+          label_options: label_options.clone(),
+          unit_size,
+        }) as _
+      )
+    });
         
     let bnote = Banknote {
       image,
@@ -93,7 +110,7 @@ impl PieceSpec for Spec {
       multigrab: true,
       ..default()
     };
-    SpecLoaded { p: Box::new(bnote) as _, occultable: None, special }
+    SpecLoaded { p: Box::new(bnote) as _, occultable, special }
   }
 }
 
@@ -306,3 +323,19 @@ impl Banknote {
             &self.unit_size, &self.currency)?;
   }
 }
+
+const OCCULT_QTY: HtmlLit = Html::lit("?");
+
+#[typetag::serde(name="Currency")]
+impl InertPieceTrait for Banknote {
+  #[throws(IE)]
+  fn svg(&self, f: &mut Html, id: VisiblePieceId, face: FaceId,
+         xdata_for_image_only: &PieceXDataState /* use with care! */) {
+    self.render(f, id, face, xdata_for_image_only, &OCCULT_QTY)?;
+  }
+
+  #[throws(IE)]
+  fn describe_html(&self, face: FaceId) -> Html {
+    self.describe(face, &OCCULT_QTY)?
+  }
+}