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
sourceimpl 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>>,
layout: TextLayout
) -> &mut Text
pub fn set_bounds(
&mut self,
bounds: impl Into<Vector2<f32>>,
layout: TextLayout
) -> &mut Text
Specifies rectangular dimensions to fit text inside of, wrapping where necessary. Within these bounds is also where text alignment occurs.
Wrapping can be disabled by setting layout
to TextLayout::SingleLine
.
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 scael for fragments that don’t specify their own scale.
sourcepub fn glyph_positions(
&self,
gfx: &mut impl HasMut<GraphicsContext>
) -> GameResult<Vec<Point2<f32>>>
pub fn glyph_positions(
&self,
gfx: &mut impl HasMut<GraphicsContext>
) -> GameResult<Vec<Point2<f32>>>
Returns a Vec
containing the coordinates of the formatted and wrapped text.
sourcepub fn measure(
&self,
gfx: &mut impl HasMut<GraphicsContext>
) -> GameResult<Vector2<f32>>
pub fn measure(
&self,
gfx: &mut impl HasMut<GraphicsContext>
) -> GameResult<Vector2<f32>>
Measures the glyph boundaries for the text.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnwindSafe for Text
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> HasMut<T> for T
impl<T> HasMut<T> for T
sourcefn retrieve_mut(&mut self) -> &mut T
fn retrieve_mut(&mut self) -> &mut T
Method to retrieve the context type as mutable.