Get individual grapheme's width

This commit is contained in:
Joscha 2022-05-28 11:15:18 +02:00
parent 833defd1ce
commit 3b2ea37ba5
3 changed files with 32 additions and 6 deletions

View file

@ -39,7 +39,19 @@ impl Frame {
self.set_cursor(None);
}
pub fn width(&mut self, s: &str) -> u8 {
/// Determine the width of a grapheme.
///
/// If the width has not been measured yet, it is estimated using the
/// Unicode Standard Annex #11.
pub fn grapheme_width(&mut self, grapheme: &str) -> u8 {
self.widthdb.grapheme_width(grapheme)
}
/// Determine the width of a string based on its graphemes.
///
/// If the width of a grapheme has not been measured yet, it is estimated
/// using the Unicode Standard Annex #11.
pub fn width(&mut self, s: &str) -> usize {
self.widthdb.width(s)
}