Struct GlyphLoaderArg

Source
pub struct GlyphLoaderArg<'a> { /* private fields */ }
Expand description

Arguments for GlyphLoader::load_glyph.

Having a struct instead of a collection of parameters makes it easier to write and use.

Implementations§

Source§

impl GlyphLoaderArg<'_>

Source

pub fn codepoint(&self) -> char

The character to be loaded.

Source

pub fn font_size(&self) -> f32

The current size of the font requested.

Source

pub fn dpi_density(&self) -> f32

Gets the rasterizer density (DPI) of the renderer that requests this glyph.

It is usually 1.0, but in hiDPI settings it may be 2.0 (or any other value, actually).

Source

pub fn set_dpi_density(&mut self, scale: f32)

Sets the rasterizer density.

If you can’t (or don’t want to) support hiDPI environments you can disable it by either setting the GlyphBuildFlags::IGNORE_DPI or by calling this function. You can set it to values other than 1.0, but the usefulness is limited.

Source

pub fn oversample(&self) -> Vector2

Gets the X/Y oversample factor.

This is usually (1.0, 1.0), but for small fonts, it may be (2.0, 1.0). If so, you should render your glyph scaled by these factors in X and Y.

Source

pub fn set_oversample(&mut self, oversample: Vector2)

Sets the X/Y oversample factor.

If you can’t (or don’t want to) support oversampling you can disable it by either setting the GlyphBuildFlags::IGNORE_OVERSAMPLE or by calling this function.

Source

pub fn only_advance_x(&self) -> bool

Returns the “only advance X” flag.

If this is true, when you call build, the draw callback will not actually be called: only the advance_x parameter will be used.

This is used by Dear ImGui when using very big fonts to compute the position of the glyphs before rendering them, to save space in the texture atlas.

You can safely ignore this, if you don’t need to micro-optimize the loading of very big custom fonts.

Source

pub fn build( self, origin: Vector2, size: Vector2, advance_x: f32, flags: GlyphBuildFlags, draw: impl FnOnce(&mut SubImage<&'_ mut ImageBuffer<Rgba<u8>, &'_ mut [u8]>>), )

Builds the requested glyph.

origin is the offset of the origin of the glyph, by default it will be just over the baseline. size is the size of the glyph, when drawn to the screen. advance_x is how many pixels this glyph occupies when part of a string. flags: how to interpret the size and scale the bitmap. draw: callback that actually draws the glyph.

Note that draw() may not be actually called every time. You can use only_advance_x() to detect this case, if you need it.

Auto Trait Implementations§

§

impl<'a> Freeze for GlyphLoaderArg<'a>

§

impl<'a> !RefUnwindSafe for GlyphLoaderArg<'a>

§

impl<'a> !Send for GlyphLoaderArg<'a>

§

impl<'a> !Sync for GlyphLoaderArg<'a>

§

impl<'a> Unpin for GlyphLoaderArg<'a>

§

impl<'a> !UnwindSafe for GlyphLoaderArg<'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.