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

Fix glyph width of tab and thin space

This commit is contained in:
Emil Ernerfeldt
2025-09-08 16:49:18 +02:00
parent 5b3c80a2ff
commit 197ec85a3e

View File

@@ -343,6 +343,8 @@ impl FontImpl {
chr: char, chr: char,
h_pos: f32, h_pos: f32,
) -> (GlyphAllocation, i32) { ) -> (GlyphAllocation, i32) {
let advance_width_px = glyph_info.advance_width_unscaled.0 * metrics.px_scale_factor;
let Some(glyph_id) = glyph_info.id else { let Some(glyph_id) = glyph_info.id else {
// Invisible. // Invisible.
return (GlyphAllocation::default(), h_pos as i32); return (GlyphAllocation::default(), h_pos as i32);
@@ -361,7 +363,9 @@ impl FontImpl {
.entry(GlyphCacheKey::new(glyph_id, metrics, bin)) .entry(GlyphCacheKey::new(glyph_id, metrics, bin))
{ {
std::collections::hash_map::Entry::Occupied(glyph_alloc) => { std::collections::hash_map::Entry::Occupied(glyph_alloc) => {
return (*glyph_alloc.get(), h_pos_round); let mut glyph_alloc = *glyph_alloc.get();
glyph_alloc.advance_width_px = advance_width_px; // Hack to get `\t` and thin space to work, since they use the same glyph id as ` ` (space).
return (glyph_alloc, h_pos_round);
} }
std::collections::hash_map::Entry::Vacant(entry) => entry, std::collections::hash_map::Entry::Vacant(entry) => entry,
}; };
@@ -425,7 +429,7 @@ impl FontImpl {
let allocation = GlyphAllocation { let allocation = GlyphAllocation {
id: glyph_id, id: glyph_id,
advance_width_px: glyph_info.advance_width_unscaled.0 * metrics.px_scale_factor, advance_width_px,
uv_rect, uv_rect,
}; };
entry.insert(allocation); entry.insert(allocation);