pub struct TextMaterial { /* private fields */ }
Expand description

This struct represents a piece of text. You only need to create one peice of text per string you would like to draw as you can draw multpiple instances easily.

Implementations§

source§

impl TextMaterial

source

pub fn new( text: &str, colour: Colour, font_size: f32, line_height: f32, engine: &mut Engine ) -> Self

Examples found in repository?
examples/text.rs (line 17)
10
11
12
13
14
15
16
17
18
19
20
21
22
fn main() {
    let mut engine = EngineBuilder::new()
        .set_clear_colour(Colour::BLACK)
        .build()
        .unwrap();

    let comic = Font::new("examples/Comic.ttf", &mut engine);
    let text_mat = TextMaterial::new("AA", Colour::RED, 100.0, 100.0, &mut engine);

    let text_example = TextExample { text_mat, comic };

    engine.run(text_example);
}
source

pub fn set_text(&mut self, text: &str, colour: Colour, engine: &mut Engine)

Sets the text for the widget, using the defualt font. This only needs to be done once, not every frame like Materials.

source

pub fn set_text_with_font( &mut self, text: &str, colour: Colour, font: &ResourceId<Font>, engine: &mut Engine )

Sets the text for the widget, but with a font of your choosing. This only needs to be done once, not every frame like Materials

Examples found in repository?
examples/text.rs (line 51)
48
49
50
51
52
53
54
55
    fn update(&mut self, engine_handle: &mut Engine) {
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            self.text_mat
                .set_text_with_font("hel", Colour::GREEN, &self.comic, engine_handle);
            self.text_mat.set_font_size(40.0, engine_handle);
            self.text_mat.prepare(engine_handle);
        }
    }
source

pub fn set_bounds(&mut self, position: Vec2<i32>, size: Vec2<i32>)

Sets bounds for the text. Any text drawn outside of the bounds will be cropped

source

pub fn set_font_size(&mut self, new_size: f32, engine: &mut Engine)

Sets the font size of the text

Examples found in repository?
examples/text.rs (line 52)
48
49
50
51
52
53
54
55
    fn update(&mut self, engine_handle: &mut Engine) {
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            self.text_mat
                .set_text_with_font("hel", Colour::GREEN, &self.comic, engine_handle);
            self.text_mat.set_font_size(40.0, engine_handle);
            self.text_mat.prepare(engine_handle);
        }
    }
source

pub fn set_line_height(&mut self, new_height: f32, engine: &mut Engine)

Sets the line hieght of the tex

source

pub fn get_measurements(&self) -> Vec2<u32>

Measuers the text contained within the widget

source

pub fn add_instance( &mut self, position: Vec2<f32>, tint: Colour, render: &RenderInformation<'_, '_> )

Queues a peice of text at the specified position. Its size will be the size of the entire text.

Examples found in repository?
examples/text.rs (line 37)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    fn render<'pass, 'others>(
        &'others mut self,
        mut render_handle: RenderInformation<'pass, 'others>,
    ) where
        'others: 'pass,
    {
        self.text_mat
            .add_instance(Vec2 { x: 0.0, y: 0.0 }, Colour::WHITE, &render_handle);
        self.text_mat.add_instance_with_rotation(
            Vec2 { x: 100.0, y: 0.0 },
            Colour::WHITE,
            45.0,
            &render_handle,
        );

        self.text_mat.draw(&mut render_handle);
    }
source

pub fn add_instance_with_rotation( &mut self, position: Vec2<f32>, tint: Colour, degrees: f32, render: &RenderInformation<'_, '_> )

Queues a piece of text at the specified postion, with rotation. Its size will be the size of the text.

Examples found in repository?
examples/text.rs (lines 38-43)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    fn render<'pass, 'others>(
        &'others mut self,
        mut render_handle: RenderInformation<'pass, 'others>,
    ) where
        'others: 'pass,
    {
        self.text_mat
            .add_instance(Vec2 { x: 0.0, y: 0.0 }, Colour::WHITE, &render_handle);
        self.text_mat.add_instance_with_rotation(
            Vec2 { x: 100.0, y: 0.0 },
            Colour::WHITE,
            45.0,
            &render_handle,
        );

        self.text_mat.draw(&mut render_handle);
    }
source

pub fn add_instance_with_uv( &mut self, position: Vec2<f32>, size: Vec2<f32>, uv_pos: Vec2<f32>, uv_size: Vec2<f32>, tint: Colour, render: &RenderInformation<'_, '_> )

Queues a piece of text at the specified postion. This also allows you to control the uv coordinates to the texture that the text has been rendered to.

source

pub fn add_instace_ex( &mut self, position: Vec2<f32>, size: Vec2<f32>, uv_pos: Vec2<f32>, uv_size: Vec2<f32>, degrees: f32, tint: Colour, render: &RenderInformation<'_, '_> )

Queues a piece of text at the position with, uv controll, and rotation.

source

pub fn add_instance_custom( &mut self, points: [Vec2<f32>; 4], uv_points: [Vec2<f32>; 4], degrees: f32, tint: Colour, render: &RenderInformation<'_, '_> )

Queues a peice with complete controll over the points, rotation, and uv coordinates. This can allow for non rectanglular shapes and the points must be in top left, top right, bottom right, bottom left order otherwise it will not draw properly.

source

pub fn prepare(&self, engine: &mut Engine)

Examples found in repository?
examples/text.rs (line 53)
48
49
50
51
52
53
54
55
    fn update(&mut self, engine_handle: &mut Engine) {
        if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
            self.text_mat
                .set_text_with_font("hel", Colour::GREEN, &self.comic, engine_handle);
            self.text_mat.set_font_size(40.0, engine_handle);
            self.text_mat.prepare(engine_handle);
        }
    }
source

pub fn draw<'pass, 'others>( &'others mut self, information: &mut RenderInformation<'pass, 'others> )
where 'others: 'pass,

Draws all queued text instances to the screen

Examples found in repository?
examples/text.rs (line 45)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    fn render<'pass, 'others>(
        &'others mut self,
        mut render_handle: RenderInformation<'pass, 'others>,
    ) where
        'others: 'pass,
    {
        self.text_mat
            .add_instance(Vec2 { x: 0.0, y: 0.0 }, Colour::WHITE, &render_handle);
        self.text_mat.add_instance_with_rotation(
            Vec2 { x: 100.0, y: 0.0 },
            Colour::WHITE,
            45.0,
            &render_handle,
        );

        self.text_mat.draw(&mut render_handle);
    }

Auto Trait Implementations§

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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

§

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

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,