Struct bottomless_pit::text::TextMaterial
source · 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
impl TextMaterial
sourcepub fn new(
text: &str,
colour: Colour,
font_size: f32,
line_height: f32,
engine: &mut Engine
) -> Self
pub fn new( text: &str, colour: Colour, font_size: f32, line_height: f32, engine: &mut Engine ) -> Self
Examples found in repository?
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);
}sourcepub fn set_text(&mut self, text: &str, colour: Colour, engine: &mut Engine)
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.
sourcepub fn set_text_with_font(
&mut self,
text: &str,
colour: Colour,
font: &ResourceId<Font>,
engine: &mut Engine
)
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
sourcepub fn set_bounds(&mut self, position: Vec2<i32>, size: Vec2<i32>)
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
sourcepub fn set_font_size(&mut self, new_size: f32, engine: &mut Engine)
pub fn set_font_size(&mut self, new_size: f32, engine: &mut Engine)
Sets the font size of the text
sourcepub fn set_line_height(&mut self, new_height: f32, engine: &mut Engine)
pub fn set_line_height(&mut self, new_height: f32, engine: &mut Engine)
Sets the line hieght of the tex
sourcepub fn get_measurements(&self) -> Vec2<u32>
pub fn get_measurements(&self) -> Vec2<u32>
Measuers the text contained within the widget
sourcepub fn add_instance(
&mut self,
position: Vec2<f32>,
tint: Colour,
render: &RenderInformation<'_, '_>
)
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?
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);
}sourcepub fn add_instance_with_rotation(
&mut self,
position: Vec2<f32>,
tint: Colour,
degrees: f32,
render: &RenderInformation<'_, '_>
)
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?
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);
}sourcepub 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<'_, '_>
)
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.
sourcepub 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<'_, '_>
)
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.
sourcepub fn add_instance_custom(
&mut self,
points: [Vec2<f32>; 4],
uv_points: [Vec2<f32>; 4],
degrees: f32,
tint: Colour,
render: &RenderInformation<'_, '_>
)
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.
sourcepub fn draw<'pass, 'others>(
&'others mut self,
information: &mut RenderInformation<'pass, 'others>
)where
'others: 'pass,
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?
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);
}