Struct tetra::graphics::text::Text

source ·
pub struct Text { /* private fields */ }
Expand description

A piece of text that can be rendered.

Performance

The layout and geometry of the text is cached after the first time it is calculated, making subsequent renders much faster. If your text stays the same from frame to frame, reusing the Text object will be much faster than recreating it.

Examples

The text example demonstrates how to load a font and then draw some text.

Implementations§

source§

impl Text

source

pub fn new<C>(content: C, font: Font) -> Textwhere C: Into<String>,

Creates a new Text, with the given content and font.

source

pub fn wrapped<C>(content: C, font: Font, max_width: f32) -> Textwhere C: Into<String>,

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.

source

pub fn draw<P>(&mut self, ctx: &mut Context, params: P)where P: Into<DrawParams>,

Draws the text to the screen (or to a canvas, if one is enabled).

source

pub fn content(&self) -> &str

Returns a reference to the content of the text.

source

pub fn set_content<C>(&mut self, content: C)where C: Into<String>,

Sets the content of the text.

Calling this function will cause a re-layout of the text the next time it is rendered.

source

pub fn font(&self) -> &Font

Gets the font of the text.

source

pub fn set_font(&mut self, font: Font)

Sets the font of the text.

Calling this function will cause a re-layout of the text the next time it is rendered.

source

pub fn max_width(&self) -> Option<f32>

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.

source

pub fn set_max_width(&mut self, max_width: Option<f32>)

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.

source

pub fn push(&mut self, ch: char)

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.

source

pub fn push_str(&mut self, string: &str)

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.

source

pub fn pop(&mut self) -> Option<char>

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.

source

pub fn get_bounds(&mut self, ctx: &mut Context) -> Option<Rectangle>

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§

source§

impl Clone for Text

source§

fn clone(&self) -> Text

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Text

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,