Font

Struct Font 

Source
pub struct Font { /* private fields */ }
Expand description

Contain a face and everything needed to render a glyph. The font have to be modified by the Text that old it so most of the time you will need to wrap it into MutResource.

Implementations§

Source§

impl Font

Source

pub fn from_path(path: &str) -> Option<Font>

Create a new font from a file path.

Examples found in repository?
examples/multi_window.rs (line 47)
44fn window2() -> Result<(), Box<Error>> {
45    let mut window = Window::new(500, 500, "Hello2");
46    let font = Rc::new(RefCell::new(
47        Font::from_path("examples/font/terminus.ttf").unwrap(),
48    ));
49    let mut text = Text::from_str(&font, "I've been looking forward to this.");
50    text.set_position(Vector::new(5.0, 40.0));
51    let event_handler = EventHandler::new(&window);
52
53    window.set_clear_color(Color::new(1.0, 0.0, 1.0));
54    window.enable_cursor();
55    window.poll(None);
56
57    while window.is_open() {
58        text.update();
59        window.poll_events();
60
61        for event in event_handler.fetch() {
62            event_process(event, &mut window);
63        }
64
65        window.clear();
66        window.draw(&mut text);
67        window.display();
68    }
69    Ok(())
70}
More examples
Hide additional examples
examples/font.rs (line 17)
8fn main() {
9    // Create drawer window
10    let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
11
12    // Create event handler
13    let event_handler = EventHandler::new(&window);
14
15    // Create font
16    let font = Rc::new(RefCell::new(
17        Font::from_path("examples/font/test.ttf").unwrap(),
18    ));
19
20    // Create text with font
21    let mut text = Text::new(&font);
22    text.set_content("Welcome to Gust you can write text and\na lot more !\t(Like tabs)");
23    text.set_position(Vector::new(100.0, 100.0));
24
25    // Create a 2nd text with font
26    let mut text2 = Text::from_str(&font, "Salut !");
27    text2.set_position(Vector::new(200.0, 200.0));
28    text2.update();
29
30    // Loop preparation
31    window.set_clear_color(Color::new(0.0, 0.0, 0.0));
32    window.enable_cursor();
33    window.poll(None);
34    while window.is_open() {
35        // update text
36        text.update();
37
38        // Poll event
39        window.poll_events();
40        event_handler
41            .fetch()
42            .for_each(|event| handle(&event, &mut window, &mut text));
43
44        // Draw process (Clear -> Draw -> Display)
45        window.clear();
46        window.draw(&text);
47        window.draw(&text2);
48        window.display();
49    }
50}
Source

pub fn glyph_exist(&mut self, size: u32, code: u32) -> bool

Check if a glyph exist.

Source

pub fn glyph(&mut self, size: u32, code: u32) -> &CharInfo

Check if the glyph exist: If the glyph exist get GraphicChar from it Else add it to the row and update the texture

Source

pub fn texture(&self, font_size: u32) -> Result<&Texture, TextError>

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 Display for Font

Source§

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

Formats the value using the given formatter. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.