Module text

Module text 

Source
Expand description

Contains the Text Struct used for text widgets and the TextRender which is needed for rendering Text widgets

§How Text Rendering Works

Text rendering works diffrently compared to standard rendering. One of the main diffrences is that you do not need to set the text buffer every single frame unlike Material buffers.

Example:

fn main() {
    // assuming you've made a engine handle already
    let mut text_handle = TextRenderer::new(&engine);
    let text_mat = TextMaterial::new("Hello World", Colour::RED, 100.0, 100.0, &mut text_render, &engine);
     
    // construct any struct that implements Game
    let game = UserStruct::new(text, text_buffer);

    egnine.run(game);
}

impl Game for UserStruct {
    fn render<'pass, 'others>(&'others mut self, mut render_handle: Renderer<'pass, 'others>) where 'others: 'pass {
        // notice how you dont need to set the text every frame, and works the same as a Material
        self.text_mat.add_instance(Vec2{x: 0.0, y: 0.0}, Colour::WHITE, &render_handle);

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

    fn update(&mut self, engine_handle: &mut Engine) {
        // nothing, you dont need to update the text buffer every frame
    }
}

Structs§

Font
A struct to ensure Font Families are created properly.
TextMaterial
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.