Skip to main content

FontStack

Struct FontStack 

Source
pub struct FontStack { /* private fields */ }
Expand description

Fonts the application shipped, tried a glyph at a time in the order given.

A family is the faces of one typeface, a file for each weight or style. Text in a stack is set in the first family, and each letter that family has no glyph for comes from the next family that has one, the way CSS reads font-family: Inter, Pretendard. Letters no family has come from the machine’s own fonts. Within a family the face is picked by the weight and style the text asks for, which each face’s file says for itself.

A stack is registered once and named by id, so a theme can make it the font of every role and stay Copy:

ⓘ
static INTER_REGULAR: &[u8] = include_bytes!("../assets/fonts/Inter-Regular.otf");
static INTER_BOLD: &[u8] = include_bytes!("../assets/fonts/Inter-Bold.otf");
static PRETENDARD_REGULAR: &[u8] = include_bytes!("../assets/fonts/Pretendard-Regular.otf");

let latin = [asset(AssetKind::Font, INTER_REGULAR), asset(AssetKind::Font, INTER_BOLD)];
let korean = [asset(AssetKind::Font, PRETENDARD_REGULAR)];
let stack = FontStack::new().family(latin).family(korean).register();
let theme = Theme::adaptive(DesignSystem::Material3).with_default_font(stack);

The faces have to be registered before the stack that names them, which the order above gives for free. A stack naming an id that is not a registered face is reported by the Renderer, and that face is left out.

Implementations§

Source§

impl FontStack

Source

pub fn new() -> Self

Source

pub fn family(self, faces: impl IntoIterator<Item = u32>) -> Self

Adds one family, tried after every family added before it. An empty family is left out, and so is anything past MAX_FONT_STACK_FAMILIES families or MAX_FONT_STACK_FACES faces.

Source

pub fn families(&self) -> &[Vec<u32>]

The families, in the order they are tried.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

The asset bytes: the magic, the version, then the families.

Source

pub fn from_bytes(bytes: &[u8]) -> Option<Self>

Reads bytes FontStack::to_bytes wrote, or None for anything else.

Source

pub fn register(&self) -> u32

Registers the stack and returns the id a theme or a font list names it by.

The same stack registered twice is one registration, as with any asset, so this can run in a component body.

Trait Implementations§

Source§

impl Clone for FontStack

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FontStack

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FontStack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for FontStack

Source§

impl PartialEq for FontStack

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FontStack

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.