chiark / gitweb /
impl TextFragmentOneLine for CentredInfoLine.
authorSimon Tatham <anakin@pobox.com>
Sun, 4 Feb 2024 14:51:08 +0000 (14:51 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 4 Feb 2024 14:51:57 +0000 (14:51 +0000)
This always draws exactly one line, and I'm about to want to use it in
a context that expects that and doesn't want to worry about unpacking
a returned vector.

src/text.rs

index 05eb8aef1f1d80e61d55d6db5a25d5f7816851b2..3781312ed41028b09789e68537ba5bac7876bde1 100644 (file)
@@ -2271,19 +2271,29 @@ impl CentredInfoLine {
     }
 }
 
-impl TextFragment for CentredInfoLine {
-    fn render_highlighted(
+impl TextFragmentOneLine for CentredInfoLine {
+    fn render_oneline(
         &self,
         width: usize,
         _highlight: Option<Highlight>,
         _style: &dyn DisplayStyleGetter,
-    ) -> Vec<ColouredString> {
+    ) -> ColouredString {
         let twidth = width.saturating_sub(1);
         let title = self.text.truncate(twidth);
         let tspace = twidth - title.width();
         let tleft = tspace / 2;
-        let textpad = ColouredString::plain(" ").repeat(tleft) + &self.text;
-        vec![textpad]
+        ColouredString::plain(" ").repeat(tleft) + &self.text
+    }
+}
+
+impl TextFragment for CentredInfoLine {
+    fn render_highlighted(
+        &self,
+        width: usize,
+        highlight: Option<Highlight>,
+        style: &dyn DisplayStyleGetter,
+    ) -> Vec<ColouredString> {
+        vec![self.render_oneline(width, highlight, style)]
     }
 }