pub struct Text { /* private fields */ }
Expand description
Drawable text object. Essentially a list of TextFragment
.
and some cached size information.
It implements Drawable
so it can be drawn immediately with Canvas::draw()
.
Implementations§
source§impl Text
impl Text
sourcepub fn new(fragment: impl Into<TextFragment>) -> Self
pub fn new(fragment: impl Into<TextFragment>) -> Self
Creates a Text
from a TextFragment
.
let text = Text::new("foo");
sourcepub fn add(&mut self, fragment: impl Into<TextFragment>) -> &mut Self
pub fn add(&mut self, fragment: impl Into<TextFragment>) -> &mut Self
Appends a TextFragment
to the Text
.
sourcepub fn fragments(&self) -> &[TextFragment]
pub fn fragments(&self) -> &[TextFragment]
Returns an immutable slice of all TextFragment
s.
sourcepub fn fragments_mut(&mut self) -> &mut [TextFragment]
pub fn fragments_mut(&mut self) -> &mut [TextFragment]
Returns a mutable slice of all TextFragment
s.
sourcepub fn set_bounds(&mut self, bounds: impl Into<Vector2<f32>>) -> &mut Self
pub fn set_bounds(&mut self, bounds: impl Into<Vector2<f32>>) -> &mut Self
Specifies rectangular dimensions to fit text inside of, wrapping where necessary. Within these bounds is also where text alignment occurs.
sourcepub fn set_layout(&mut self, layout: TextLayout) -> &mut Self
pub fn set_layout(&mut self, layout: TextLayout) -> &mut Self
Specifies how the text will be layed out.
sourcepub fn set_wrap(&mut self, wrap: bool) -> &mut Self
pub fn set_wrap(&mut self, wrap: bool) -> &mut Self
Specifies whether or not the text will be wrapped within the bounds bounds specified by Text::set_bounds
.
sourcepub fn set_font(&mut self, font: impl Into<String>) -> &mut Self
pub fn set_font(&mut self, font: impl Into<String>) -> &mut Self
Specifies the text’s font for fragments that don’t specify their own font.
sourcepub fn set_scale(&mut self, scale: impl Into<PxScale>) -> &mut Self
pub fn set_scale(&mut self, scale: impl Into<PxScale>) -> &mut Self
Specifies the text’s font scale for fragments that don’t specify their own scale.
sourcepub fn glyph_positions(
&self,
gfx: &impl Has<GraphicsContext>
) -> GameResult<Vec<Point2<f32>>>
pub fn glyph_positions( &self, gfx: &impl Has<GraphicsContext> ) -> GameResult<Vec<Point2<f32>>>
Returns a Vec
containing the coordinates of the formatted and wrapped text.
sourcepub fn measure(
&self,
gfx: &impl Has<GraphicsContext>
) -> GameResult<Vector2<f32>>
pub fn measure( &self, gfx: &impl Has<GraphicsContext> ) -> GameResult<Vector2<f32>>
Measures the glyph boundaries for the text.