Calculate width of Styleds directly

This commit is contained in:
Joscha 2022-07-12 10:22:14 +02:00
parent d693712dab
commit e4e1454e80

View file

@ -67,6 +67,15 @@ impl Frame {
self.widthdb.width(s) self.widthdb.width(s)
} }
/// Like [`Self::width`] for [`Styled`].
pub fn width_styled(&mut self, s: &Styled) -> usize {
let mut total: usize = 0;
for grapheme in s.graphemes() {
total += self.widthdb.grapheme_width(grapheme) as usize;
}
total
}
pub fn tab_width_at_column(&self, col: usize) -> u8 { pub fn tab_width_at_column(&self, col: usize) -> u8 {
wrap::tab_width_at_column(self.tab_width, col) wrap::tab_width_at_column(self.tab_width, col)
} }