Text

Struct Text 

Source
pub struct Text<'a> {
    pub coords: (usize, usize),
    pub font: &'a Font,
    pub text: String,
    pub style: TextStyle,
    pub character_size: (usize, &'a str),
}
Expand description

A text drawable on a Canvas. Multiline (\n) works only when using a character size in px.

Fields§

§coords: (usize, usize)

The coords of the text in px.

§font: &'a Font

The font of the text.

§text: String

The text.

§style: TextStyle

The style of the text (bold/italic…)

§character_size: (usize, &'a str)

The character_size. example: (14, “px”)

Implementations§

Source§

impl<'a> Text<'a>

Source

pub fn new(font: &'a Font) -> Text<'a>

Create a new text with default values.

Source

pub fn new_with_text_and_coords( font: &'a Font, text: String, coords: (usize, usize), ) -> Text<'a>

Create a new text with some default values.

Source

pub fn new_with_options( font: &'a Font, text: String, coords: (usize, usize), style: TextStyle, character_size: (usize, &'a str), ) -> Text<'a>

Create a new text with no default value.

Source

pub fn set_text(&mut self, text: String)

Set the displayed text.

Source

pub fn set_style(&mut self, style: TextStyle)

Set the style of the text.

Source

pub fn get_width(&self, canvas: &mut Canvas) -> f64

Get the width of the text Needs a mutable reference to a canvas

Source

pub fn get_height(&self) -> usize

Get the width of the text. Works only for font size specified using a value in px.

Trait Implementations§

Source§

impl<'a> Drawable for Text<'a>

Source§

fn draw_on_canvas(&self, canvas: &mut Canvas)

This method is called by the draw method.

Auto Trait Implementations§

§

impl<'a> Freeze for Text<'a>

§

impl<'a> RefUnwindSafe for Text<'a>

§

impl<'a> Send for Text<'a>

§

impl<'a> Sync for Text<'a>

§

impl<'a> Unpin for Text<'a>

§

impl<'a> UnwindSafe for Text<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.