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

Make the width of the thin space configurable (#8070)

Adds `FontTweak::thin_space_width` and `FontTweak::tab_size`
This commit is contained in:
Emil Ernerfeldt
2026-04-06 18:09:54 +02:00
committed by GitHub
parent 16cad760a5
commit ab4bca65ea
11 changed files with 73 additions and 37 deletions

View File

@@ -432,8 +432,7 @@ impl FontFace {
&& let Some(space) = self.glyph_info(' ')
{
let glyph_info = GlyphInfo {
advance_width_unscaled: (crate::text::TAB_SIZE as f32
* space.advance_width_unscaled.0)
advance_width_unscaled: (self.tweak.tab_size * space.advance_width_unscaled.0)
.into(),
..space
};
@@ -441,21 +440,18 @@ impl FontFace {
return Some(glyph_info);
}
if c == '\u{2009}' {
// Thin space, often used as thousands deliminator: 1234567890
// https://www.compart.com/en/unicode/U+2009
// https://en.wikipedia.org/wiki/Thin_space
if let Some(space) = self.glyph_info(' ') {
let em = self.font.borrow_dependent().metrics.units_per_em as f32;
let advance_width = f32::min(em / 6.0, space.advance_width_unscaled.0 * 0.5); // TODO(emilk): make configurable
let glyph_info = GlyphInfo {
advance_width_unscaled: advance_width.into(),
..space
};
self.glyph_info_cache.insert(c, glyph_info);
return Some(glyph_info);
}
if (c == '\u{2009}' || c == '\u{202F}')
&& let Some(space) = self.glyph_info(' ')
{
// Thin space (U+2009) and narrow no-break space (U+202F),
// often used as thousands separator: 1234567890
let advance_width = self.tweak.thin_space_width * space.advance_width_unscaled.0;
let glyph_info = GlyphInfo {
advance_width_unscaled: advance_width.into(),
..space
};
self.glyph_info_cache.insert(c, glyph_info);
return Some(glyph_info);
}
if invisible_char(c) {