Text

Struct Text 

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

§Text struct

Text is a drawable entity that can be used to display text. The text need a MutResource because the text mut the internal texture of his font.

Implementations§

Source§

impl Text

Source

pub fn dump_texture(&mut self) -> Result<(), Box<dyn Error>>

Dump the font texture to a file

Source

pub fn new(font: &Rc<RefCell<Font>>) -> Text

Create a new text from a font previously created

Examples found in repository?
examples/font.rs (line 21)
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 from_str(font: &Rc<RefCell<Font>>, content: &str) -> Text

Create a text from it’s content and a font

Examples found in repository?
examples/multi_window.rs (line 49)
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 26)
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 set_content(&mut self, content: &str)

Set the content of the text

Examples found in repository?
examples/font.rs (line 22)
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 content(&self) -> &String

Get the content of the text as &String

Source

pub fn content_mut(&mut self) -> &mut String

Get the content of the text as &mut String

Source

pub fn set_size(&mut self, size: u32)

Set the local font size

Source

pub fn size(&self) -> u32

Get the local font size

Trait Implementations§

Source§

impl Debug for Text

Source§

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

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

impl Drawable for Text

Source§

fn update(&mut self)

Update the openGL state of the drawable entity Should be call often so be carefull when implementing.
Source§

fn draw<T: Drawer>(&self, target: &mut T)

Draw the drawable structure, you need a Drawer(Where the struct will be draw)
Source§

fn draw_with_context(&self, context: &mut Context<'_>)

Draw with a particular context
Source§

fn setup_draw(&self, context: &mut Context<'_>)

Setup the draw for the final system you don’t have to implement it in a normal drawable
Source§

impl DrawableMut for Text

Source§

fn draw_mut<T: Drawer>(&mut self, target: &mut T)

Mutable version of draw function.
Source§

fn draw_with_context_mut(&mut self, context: &mut Context<'_>)

Mutable draw context function.
Source§

impl Movable for Text

Source§

fn translate<T>(&mut self, offset: Vector<T>)
where T: Scalar + Into<f32>,

Move the sprite off the offset
Source§

fn set_position<T>(&mut self, pos: Vector<T>)
where T: Scalar + Into<f32>,

Set position of the sprite
Source§

fn get_position(&self) -> Vector<f32>

Get current position
Source§

impl Rotable for Text

Source§

fn rotate<T>(&mut self, _angle: T)
where T: Scalar + Into<f32>,

Rotate from the actual angle with the angle given in argument.
Source§

fn set_rotation<T>(&mut self, _angle: T)
where T: Scalar + Into<f32>,

Set the rotation of the Rotable struct.
Source§

fn get_rotation(&self) -> f32

Return the rotation of the struct.
Source§

impl Scalable for Text

Source§

fn scale<T>(&mut self, _factor: Vector<T>)
where T: Scalar + Into<f32>,

Scale the sprite from a factor
Source§

fn set_scale<T>(&mut self, _vec: Vector<T>)
where T: Scalar + Into<f32>,

Set the scale of the sprite
Source§

fn get_scale(&self) -> Vector<f32>

Get the current scale
Source§

impl Transformable for Text

Source§

fn contain<T>(&self, _point: Point<T>) -> bool
where T: Scalar + Into<f32>,

Move the sprite off the offset.
Source§

fn set_origin<T>(&mut self, _origin: Vector<T>)
where T: Scalar + Into<f32>,

Set the origin of the object.
Source§

fn get_origin(&self) -> Vector<f32>

Get the origin of the transformable.

Auto Trait Implementations§

§

impl Freeze for Text

§

impl !RefUnwindSafe for Text

§

impl !Send for Text

§

impl !Sync for Text

§

impl Unpin for Text

§

impl !UnwindSafe for Text

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, 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.