pub struct Fonts(/* private fields */);
Expand description
The collection of fonts used by epaint
.
Required in order to paint text. Create one and reuse. Cheap to clone.
Each Fonts
comes with a font atlas textures that needs to be used when painting.
If you are using egui
, use egui::Context::set_fonts
and egui::Context::fonts
.
You need to call Self::begin_pass
and Self::font_image_delta
once every frame.
Implementations§
Source§impl Fonts
impl Fonts
Sourcepub fn new(
pixels_per_point: f32,
max_texture_side: usize,
definitions: FontDefinitions,
) -> Self
pub fn new( pixels_per_point: f32, max_texture_side: usize, definitions: FontDefinitions, ) -> Self
Sourcepub fn begin_pass(&self, pixels_per_point: f32, max_texture_side: usize)
pub fn begin_pass(&self, pixels_per_point: f32, max_texture_side: usize)
Call at the start of each frame with the latest known
pixels_per_point
and max_texture_side
.
Call after painting the previous frame, but before using Fonts
for the new frame.
This function will react to changes in pixels_per_point
and max_texture_side
,
as well as notice when the font atlas is getting full, and handle that.
Sourcepub fn font_image_delta(&self) -> Option<ImageDelta>
pub fn font_image_delta(&self) -> Option<ImageDelta>
Call at the end of each frame (before painting) to get the change to the font texture since last call.
pub fn pixels_per_point(&self) -> f32
pub fn max_texture_side(&self) -> usize
Sourcepub fn texture_atlas(&self) -> Arc<Mutex<TextureAtlas>>
pub fn texture_atlas(&self) -> Arc<Mutex<TextureAtlas>>
The font atlas.
Pass this to crate::Tessellator
.
Sourcepub fn font_image_size(&self) -> [usize; 2]
pub fn font_image_size(&self) -> [usize; 2]
Current size of the font image.
Pass this to crate::Tessellator
.
Sourcepub fn glyph_width(&self, font_id: &FontId, c: char) -> f32
pub fn glyph_width(&self, font_id: &FontId, c: char) -> f32
Width of this character in points.
Sourcepub fn has_glyphs(&self, font_id: &FontId, s: &str) -> bool
pub fn has_glyphs(&self, font_id: &FontId, s: &str) -> bool
Can we display all the glyphs in this text?
Sourcepub fn row_height(&self, font_id: &FontId) -> f32
pub fn row_height(&self, font_id: &FontId) -> f32
Height of one row of text in points
Sourcepub fn families(&self) -> Vec<FontFamily>
pub fn families(&self) -> Vec<FontFamily>
List of all known font families.
Sourcepub fn layout_job(&self, job: LayoutJob) -> Arc<Galley>
pub fn layout_job(&self, job: LayoutJob) -> Arc<Galley>
Layout some text.
This is the most advanced layout function.
See also Self::layout
, Self::layout_no_wrap
and
Self::layout_delayed_color
.
The implementation uses memoization so repeated calls are cheap.
pub fn num_galleys_in_cache(&self) -> usize
Sourcepub fn font_atlas_fill_ratio(&self) -> f32
pub fn font_atlas_fill_ratio(&self) -> f32
How full is the font atlas?
This increases as new fonts and/or glyphs are used,
but can also decrease in a call to Self::begin_pass
.
Sourcepub fn layout(
&self,
text: String,
font_id: FontId,
color: Color32,
wrap_width: f32,
) -> Arc<Galley>
pub fn layout( &self, text: String, font_id: FontId, color: Color32, wrap_width: f32, ) -> Arc<Galley>
Will wrap text at the given width and line break at \n
.
The implementation uses memoization so repeated calls are cheap.
Sourcepub fn layout_no_wrap(
&self,
text: String,
font_id: FontId,
color: Color32,
) -> Arc<Galley>
pub fn layout_no_wrap( &self, text: String, font_id: FontId, color: Color32, ) -> Arc<Galley>
Will line break at \n
.
The implementation uses memoization so repeated calls are cheap.
Sourcepub fn layout_delayed_color(
&self,
text: String,
font_id: FontId,
wrap_width: f32,
) -> Arc<Galley>
pub fn layout_delayed_color( &self, text: String, font_id: FontId, wrap_width: f32, ) -> Arc<Galley>
Like Self::layout
, made for when you want to pick a color for the text later.
The implementation uses memoization so repeated calls are cheap.