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:
@@ -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
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user