models.rs
671 B · rust · 23 lines
1/// One character's pixel bitmap.2#[derive(Clone, Debug, PartialEq, Eq)]3pub struct Glyph {4 /// The character the glyph draws.5 pub char: char,6 /// The bitmap rows of '0' and '1' characters.7 pub rows: Vec<String>,8}910impl Glyph {11 /// Builds a glyph from its character and rows.12 pub fn new(char: char, rows: Vec<String>) -> Glyph {13 Glyph { char, rows }14 }15 /// Returns the cell width of the first row, or 0 for an empty glyph.16 pub fn width(&self) -> usize {17 self.rows.first().map_or(0, |row| row.chars().count())18 }19 /// Returns the number of rows.20 pub fn height(&self) -> usize {21 self.rows.len()22 }23}