Struct tetra::graphics::text::Text [−][src]
pub struct Text { /* fields omitted */ }
Expand description
A piece of text that can be rendered.
Performance
The layout of the text is cached after the first time it is calculated, making subsequent rendering of the text much faster.
Cloning a Text
is a fairly expensive operation, as it creates an entirely new copy of the
object with its own cache.
Examples
The text
example demonstrates how to load a font and then draw some text.
Implementations
impl Text
[src]
impl Text
[src]pub fn new<C>(content: C, font: Font) -> Text where
C: Into<String>,
[src]
pub fn new<C>(content: C, font: Font) -> Text where
C: Into<String>,
[src]Creates a new Text
, with the given content and font.
pub fn wrapped<C>(content: C, font: Font, max_width: f32) -> Text where
C: Into<String>,
[src]
pub fn wrapped<C>(content: C, font: Font, max_width: f32) -> Text where
C: Into<String>,
[src]Creates a new wrapped Text
, with the given content, font
and maximum width.
If a word is too long to fit, it may extend beyond the max width - use
get_bounds
if you need to find the actual bounds
of the text.
pub fn draw<P>(&mut self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]
pub fn draw<P>(&mut self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]Draws the text to the screen (or to a canvas, if one is enabled).
pub fn set_content<C>(&mut self, content: C) where
C: Into<String>,
[src]
pub fn set_content<C>(&mut self, content: C) where
C: Into<String>,
[src]Sets the content of the text.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn set_font(&mut self, font: Font)
[src]
pub fn set_font(&mut self, font: Font)
[src]Sets the font of the text.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn max_width(&self) -> Option<f32>
[src]
pub fn max_width(&self) -> Option<f32>
[src]Gets the maximum width of the text, if one is set.
If a word is too long to fit, it may extend beyond this width - use
get_bounds
if you need to find the actual bounds
of the text.
pub fn set_max_width(&mut self, max_width: Option<f32>)
[src]
pub fn set_max_width(&mut self, max_width: Option<f32>)
[src]Sets the maximum width of the text.
If Some
is passed, word-wrapping will be enabled. If None
is passed,
it will be disabled.
If a word is too long to fit, it may extend beyond this width - use
get_bounds
if you need to find the actual bounds
of the text.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn push(&mut self, ch: char)
[src]
pub fn push(&mut self, ch: char)
[src]Appends the given character to the end of the text.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn push_str(&mut self, string: &str)
[src]
pub fn push_str(&mut self, string: &str)
[src]Appends the given string slice to the end of the text.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn pop(&mut self) -> Option<char>
[src]
pub fn pop(&mut self) -> Option<char>
[src]Removes the last character from the text and returns it.
Returns None
if the text is empty.
Calling this function will cause a re-layout of the text the next time it is rendered.
pub fn get_bounds(&mut self, ctx: &mut Context) -> Option<Rectangle>
[src]
pub fn get_bounds(&mut self, ctx: &mut Context) -> Option<Rectangle>
[src]Get the outer bounds of the text when rendered to the screen.
If the text’s layout needs calculating, this method will do so.
Note that this method will not take into account the positioning applied to the text via DrawParams
.
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
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more