pub struct BitmapFont { /* private fields */ }Expand description
A pixel font: glyphs from a sheet texture, drawn at their native size or whole multiples, on the pixel grid, through the sprite batcher (so text sorts with sprites by layer).
Get one from BitmapFont::from_grid (a glyph sheet), BitmapFont::from_bmfont (an
AngelCode BMFont .fnt text file plus its page image), or use the built-in 5 × 7 font
through Painter::pixel_text /
Graphics::builtin_font. Draw with Painter::bitmap_text.
Implementations§
Source§impl BitmapFont
impl BitmapFont
Sourcepub fn new(
texture: TextureId,
texture_size: [u32; 2],
line_height: u32,
glyphs: HashMap<char, Glyph>,
) -> BitmapFont
pub fn new( texture: TextureId, texture_size: [u32; 2], line_height: u32, glyphs: HashMap<char, Glyph>, ) -> BitmapFont
Build a font from glyph metrics over an already-loaded texture.
Sourcepub fn from_grid(
gfx: &mut Graphics,
png: &[u8],
layout: &GridLayout,
) -> Result<BitmapFont, Error>
pub fn from_grid( gfx: &mut Graphics, png: &[u8], layout: &GridLayout, ) -> Result<BitmapFont, Error>
Load a glyph sheet (PNG bytes) laid out as a grid. Glyph pixels are drawn with their own colour times the tint, so draw the sheet in white to colour text freely.
Sourcepub fn from_grid_rgba(
texture: TextureId,
size: [u32; 2],
rgba: &[u8],
layout: &GridLayout,
) -> BitmapFont
pub fn from_grid_rgba( texture: TextureId, size: [u32; 2], rgba: &[u8], layout: &GridLayout, ) -> BitmapFont
BitmapFont::from_grid over RGBA pixels already uploaded as texture.
§Panics
If rgba holds fewer than size[0] * size[1] * 4 bytes.
Sourcepub fn from_bmfont(
gfx: &mut Graphics,
fnt: &str,
page_png: &[u8],
) -> Result<BitmapFont, Error>
pub fn from_bmfont( gfx: &mut Graphics, fnt: &str, page_png: &[u8], ) -> Result<BitmapFont, Error>
Load an AngelCode BMFont in its text format (.fnt) with a single page, given the
page image’s PNG bytes. Kerning pairs are applied.
Sourcepub fn bmfont_page_file(fnt: &str) -> Option<String>
pub fn bmfont_page_file(fnt: &str) -> Option<String>
The file of page 0 named in a BMFont text file, to find its image next to it.
Sourcepub fn parse_bmfont(
texture: TextureId,
texture_size: [u32; 2],
fnt: &str,
) -> Result<BitmapFont, Error>
pub fn parse_bmfont( texture: TextureId, texture_size: [u32; 2], fnt: &str, ) -> Result<BitmapFont, Error>
Parse BMFont text metrics over an uploaded page texture.
Sourcepub fn builtin(gfx: &mut Graphics) -> BitmapFont
pub fn builtin(gfx: &mut Graphics) -> BitmapFont
The built-in 5 × 7 pixel font (6 × 8 cells, printable ASCII, monospaced), uploaded to
gfx. Graphics::builtin_font keeps one around; use this for a separate copy.
Sourcepub fn set_fallback(&mut self, c: Option<char>)
pub fn set_fallback(&mut self, c: Option<char>)
Replace characters the font lacks with c (default '?' if the font has it); None
skips them.
pub fn texture(&self) -> TextureId
pub fn texture_size(&self) -> [u32; 2]
Sourcepub fn line_height(&self) -> u32
pub fn line_height(&self) -> u32
Height of one line at scale 1, in pixels.
pub fn glyph(&self, c: char) -> Option<&Glyph>
Sourcepub fn measure(&self, s: &str, scale: u32) -> [u32; 2]
pub fn measure(&self, s: &str, scale: u32) -> [u32; 2]
Size [width, height] of s drawn at scale, in whole pixels: the widest line, and
the height of all lines (\n or \r\n starts a new one). The width includes glyphs
that overhang left of the start position (BMFont glyphs with a negative xoffset).
Saturates instead of overflowing for absurd scales.
Trait Implementations§
Source§impl Clone for BitmapFont
impl Clone for BitmapFont
Source§fn clone(&self) -> BitmapFont
fn clone(&self) -> BitmapFont
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Forget for BitmapFont
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.