SurfaceRenderer

Struct SurfaceRenderer 

Source
pub struct SurfaceRenderer {
    pub fg_color: Color,
    pub bg_color: Color,
    pub scale: u32,
    pub bold: bool,
    pub italic: bool,
    /* private fields */
}
Expand description

Storage class for rendering settings.

Fields§

§fg_color: Color

The colour to use to draw text.

§bg_color: Color

The colour to use to fill the surface before drawing text.

§scale: u32

Integer scale multiplier, since Unifont is a raster font.

§bold: bool

Whether or not to make text bold. Uses XTerm-style bolding, where the text is just drawn twice on the x-axis, one pixel apart.

§italic: bool

Whether or not to make text italicised. Simply shifts pixels to the right by one additional pixel, every two vertical pixels.

Implementations§

Source§

impl SurfaceRenderer

Source

pub fn new(fg_color: Color, bg_color: Color) -> SurfaceRenderer

Creates a new Unifont renderer which renders text to new SDL surfaces.

Source

pub fn reset(&mut self)

Returns the renderer to the state it was in when it was first created (i.e. the foreground and background colours are reset to the values given to the constructor, and all other fields are reset).

Source

pub fn draw(&self, text: &str) -> Result<Surface<'_>, String>

Draws the supplied text to a new surface, which has been sized to fit the text exactly, using the renderer’s style settings. Returns an Err result if a character was found which is not in the font, or the font could not be initialised.

Source

pub fn measure_width(&self, text: &str) -> Result<u32, String>

Sums the width of each character in the supplied text, and multiples the sum by the renderer’s integer scale factor. Takes into consideration formatting options’ effects on text width.

Source

pub fn measure_height(&self, _text: &str) -> Result<u32, String>

May in the future take into consideration newlines and other formatting. For now, it just returns 16 * scale, thus, the result of this method can always be safely unwrap()ped.

Auto Trait Implementations§

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.