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
impl Font
Sourcepub fn from_path(path: &str) -> Option<Font>
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
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}Sourcepub fn glyph_exist(&mut self, size: u32, code: u32) -> bool
pub fn glyph_exist(&mut self, size: u32, code: u32) -> bool
Check if a glyph exist.
Sourcepub fn glyph(&mut self, size: u32, code: u32) -> &CharInfo
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
pub fn texture(&self, font_size: u32) -> Result<&Texture, TextError>
Trait Implementations§
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> 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SetParameter for T
impl<T> SetParameter for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.