Skip to main content

FontFamilyBuilder

Struct FontFamilyBuilder 

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

Builder for composing multiple font families

This builder allows you to add multiple font families and their weights, then install them all at once into the egui context. This is more efficient and safer than calling load_font_family multiple times.

§Example

use armas_basic::fonts::FontFamilyBuilder;
use eframe::egui;

fn setup(ctx: &egui::Context) {
    let mut builder = FontFamilyBuilder::new();

    builder.add_family(
        "Inter",
        include_bytes!("../../fonts/Inter-Regular.ttf"),
        Some(include_bytes!("../../fonts/Inter-Medium.ttf")),
        Some(include_bytes!("../../fonts/Inter-SemiBold.ttf")),
        Some(include_bytes!("../../fonts/Inter-Bold.ttf")),
    );

    // Install and set Inter as default
    builder.install(ctx, true);
}

Implementations§

Source§

impl FontFamilyBuilder

Source

pub fn new() -> Self

Create a new font family builder

Source

pub fn add_family( &mut self, family_name: &str, regular: &'static [u8], medium: Option<&'static [u8]>, semibold: Option<&'static [u8]>, bold: Option<&'static [u8]>, ) -> &mut Self

Add a font family with multiple weights

§Naming Convention

Fonts are registered with the following names:

  • Regular: {family_name} (e.g., “Inter”)
  • Medium: {family_name}Medium (e.g., “InterMedium”)
  • SemiBold: {family_name}SemiBold (e.g., “InterSemiBold”)
  • Bold: {family_name}Bold (e.g., “InterBold”)
Source

pub fn set_default(&mut self, family_name: &str) -> &mut Self

Set which family should be the default proportional font

Source

pub fn install(self, ctx: &Context, set_as_default: bool)

Install the fonts into the egui context

This merges with existing font definitions, preserving egui’s default fonts.

§Arguments
  • ctx - The egui context (use from CreationContext or before first frame)
  • set_as_default - If true, sets the first added family as default proportional font
Source

pub fn build(self) -> FontDefinitions

Build FontDefinitions without installing to context

Useful if you want to customize further before applying.

Trait Implementations§

Source§

impl Default for FontFamilyBuilder

Source§

fn default() -> Self

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

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.