}
}
+pub trait TextFragmentOneLine {
+ // A more specific trait for fragments always producing exactly one line
+ fn render_oneline(&self, width: usize, _highlight: Option<Highlight>,
+ _style: &dyn DisplayStyleGetter) -> ColouredString;
+}
+
impl<T: TextFragment> TextFragment for Option<T> {
fn can_highlight(htype: HighlightType) -> bool where Self : Sized {
T::can_highlight(htype)
}
}
-impl TextFragment for MenuKeypressLine {
- fn render_highlighted(&self, width: usize, _highlight: Option<Highlight>,
- _style: &dyn DisplayStyleGetter)
- -> Vec<ColouredString>
+impl TextFragmentOneLine for MenuKeypressLine {
+ fn render_oneline(&self, width: usize, _highlight: Option<Highlight>,
+ _style: &dyn DisplayStyleGetter) -> ColouredString
{
let ourwidth = self.lmaxwid + self.rmaxwid + 3; // " = " in the middle
let space = width - min(width, ourwidth + 1);
ColouredString::plain(" = ") +
&self.keypress.description;
+ line.truncate(width).into()
+ }
+}
+
+impl TextFragment for MenuKeypressLine {
+ fn render_highlighted(&self, width: usize, highlight: Option<Highlight>,
+ style: &dyn DisplayStyleGetter)
+ -> Vec<ColouredString>
+ {
vec! {
- line.truncate(width).into()
+ self.render_oneline(width, highlight, style)
}
}
}