glerminal

Struct Font

Source
pub struct Font {
    pub name: String,
    pub line_height: u32,
    pub size: u32,
    /* private fields */
}
Expand description

The Font is used to load fonts that can be used in the TextBuffer

The Font can be loaded from an .sfl or .fnt file and then used in the TextBuffer, in example:

use glerminal::{TerminalBuilder, Font, FontFormat};

let mut terminal = TerminalBuilder::new()
    .with_title("Hello glerminal::font::Font!")
    .with_dimensions((1280, 720))
    .with_font(Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl"))
    .with_headless(true)
    .build();

Alternatively you can use load_raw to load the font straight with include_str! and include_bytes!, example:

use glerminal::{TerminalBuilder, Font, FontFormat};

static SCP_SFL: &'static str = include_str!("../fonts/source_code_pro.sfl");
static SCP_PNG: &'static [u8] = include_bytes!("../fonts/source_code_pro.png");

let mut terminal = TerminalBuilder::new()
    .with_title("Hello glerminal::font::Font!")
    .with_dimensions((1280, 720))
    .with_font(Font::load_raw(&FontFormat::SFL, SCP_SFL, SCP_PNG))
    .with_headless(true)
    .build();

Fields§

§name: String

The name of the font

§line_height: u32

Line height of the font

§size: u32

Size of the font (width)

Implementations§

Source§

impl Font

Source

pub fn load<T: Into<PathBuf>>(format: &FontFormat, fnt_path: T) -> Font

Loads the font fron the given font file, for example:

use glerminal::{Font, FontFormat};
let font = Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl");
Source

pub fn load_raw<T: Into<String>, R: Read>( format: &FontFormat, content: T, image_read: R, ) -> Font

Loads the font from the given string (font file contents) and Read (image read)

use glerminal::{Font, FontFormat};
use std::fs::File;

let font = Font::load_raw(&FontFormat::SFL, include_str!("../fonts/source_code_pro.sfl"), File::open("fonts/source_code_pro.png").unwrap());
Source

pub fn get_character(&self, character: u16) -> Result<CharacterData, String>

Gets the CharacterData from the Font with the given char, if the charcter exists, otherwise returns an error as a String. Example:

use glerminal::{Font, FontFormat};
let a_char_data = Font::load(&FontFormat::SFL, "fonts/source_code_pro.sfl").get_character('a' as u16);

Trait Implementations§

Source§

impl Debug for Font

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Font

Source§

fn eq(&self, other: &Font) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Font

Auto Trait Implementations§

§

impl Freeze for Font

§

impl RefUnwindSafe for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnwindSafe for Font

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T