1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Add UI to modify FontTweak live (#5125)

This will make it easier to get nice sizing and vertical alignments of
fonts
This commit is contained in:
Emil Ernerfeldt
2024-09-18 13:43:33 +02:00
committed by GitHub
parent e31b44f1a5
commit f4ed394a85
7 changed files with 126 additions and 25 deletions

View File

@@ -1,11 +1,13 @@
use std::collections::BTreeMap;
use std::sync::Arc;
use emath::{vec2, Vec2};
use crate::{
mutex::{Mutex, RwLock},
text::FontTweak,
TextureAtlas,
};
use emath::{vec2, Vec2};
use std::collections::BTreeSet;
use std::sync::Arc;
// ----------------------------------------------------------------------------
@@ -330,7 +332,7 @@ pub struct Font {
fonts: Vec<Arc<FontImpl>>,
/// Lazily calculated.
characters: Option<BTreeSet<char>>,
characters: Option<BTreeMap<char, Vec<String>>>,
replacement_glyph: (FontIndex, GlyphInfo),
pixels_per_point: f32,
@@ -398,12 +400,14 @@ impl Font {
self.glyph_info(crate::text::PASSWORD_REPLACEMENT_CHAR);
}
/// All supported characters.
pub fn characters(&mut self) -> &BTreeSet<char> {
/// All supported characters, and in which font they are available in.
pub fn characters(&mut self) -> &BTreeMap<char, Vec<String>> {
self.characters.get_or_insert_with(|| {
let mut characters = BTreeSet::new();
let mut characters: BTreeMap<char, Vec<String>> = Default::default();
for font in &self.fonts {
characters.extend(font.characters());
for chr in font.characters() {
characters.entry(chr).or_default().push(font.name.clone());
}
}
characters
})

View File

@@ -159,6 +159,8 @@ pub struct FontTweak {
/// Shift font's glyphs downwards by this fraction of the font size (in points).
/// this is only a visual effect and does not affect the text layout.
///
/// Affects larger font sizes more.
///
/// A positive value shifts the text downwards.
/// A negative value shifts it upwards.
///
@@ -168,6 +170,8 @@ pub struct FontTweak {
/// Shift font's glyphs downwards by this amount of logical points.
/// this is only a visual effect and does not affect the text layout.
///
/// Affects all font sizes equally.
///
/// Example value: `2.0`.
pub y_offset: f32,

View File

@@ -482,7 +482,7 @@ fn replace_last_glyph_with_overflow_character(
/// Horizontally aligned the text on a row.
///
/// /// Ignores the Y coordinate.
/// Ignores the Y coordinate.
fn halign_and_justify_row(
point_scale: PointScale,
row: &mut Row,