pub struct BitmapFont { /* private fields */ }Expand description
A fixed-pitch bitmap font.
Implementations§
Source§impl BitmapFont
impl BitmapFont
Sourcepub fn glyph(&self, ch: char) -> &Glyph
pub fn glyph(&self, ch: char) -> &Glyph
The glyph for ch, or the missing-character box.
Examples found in repository?
examples/fontdump.rs (line 7)
3fn main() {
4 for line in std::env::args().skip(1) {
5 let mut rows = vec![String::new(); font::CELL_HEIGHT as usize];
6 for ch in line.chars() {
7 let g = font::BUILT_IN.glyph(ch);
8 for (i, row) in rows.iter_mut().enumerate() {
9 for x in 0..font::CELL_WIDTH {
10 row.push(if g[i] & (0x80 >> x) != 0 { '#' } else { '.' });
11 }
12 row.push('.');
13 }
14 }
15 for r in rows {
16 println!("{r}");
17 }
18 println!();
19 }
20}Sourcepub fn line_width(&self, line: &str, scale: i32) -> i32
pub fn line_width(&self, line: &str, scale: i32) -> i32
Width of one line of text, excluding the trailing inter-glyph gap.
The gap is excluded so that centring text in a button actually centres the ink rather than leaving it a pixel left of true.
Sourcepub const fn caret_offset(&self, index: usize, scale: i32) -> i32
pub const fn caret_offset(&self, index: usize, scale: i32) -> i32
Horizontal offset of the glyph at character index index.
Fixed pitch, so this is multiplication rather than a layout pass — which is exactly why a text field’s caret arithmetic is trivial here and will stop being trivial when M4 brings proportional fonts.
Trait Implementations§
Source§impl Clone for BitmapFont
impl Clone for BitmapFont
Source§fn clone(&self) -> BitmapFont
fn clone(&self) -> BitmapFont
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for BitmapFont
Auto Trait Implementations§
impl Freeze for BitmapFont
impl RefUnwindSafe for BitmapFont
impl Send for BitmapFont
impl Sync for BitmapFont
impl Unpin for BitmapFont
impl UnsafeUnpin for BitmapFont
impl UnwindSafe for BitmapFont
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more