From 4ace85b7800d8929175f583b5068925039a1fd14 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 23 Oct 2021 14:38:26 +0200 Subject: [PATCH] Fix: '\t' always take up the width of four spaces --- epaint/src/text/font.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/epaint/src/text/font.rs b/epaint/src/text/font.rs index 4037a0a3..e97c478d 100644 --- a/epaint/src/text/font.rs +++ b/epaint/src/text/font.rs @@ -137,6 +137,18 @@ impl FontImpl { // Add new character: use ab_glyph::Font as _; let glyph_id = self.ab_glyph_font.glyph_id(c); + + if c == '\t' { + if let Some(space) = self.glyph_info(' ') { + let glyph_info = GlyphInfo { + advance_width: crate::text::TAB_SIZE as f32 * space.advance_width, + ..GlyphInfo::default() + }; + self.glyph_info_cache.write().insert(c, glyph_info); + return Some(glyph_info); + } + } + if glyph_id.0 == 0 { if invisible_char(c) { // hack @@ -147,7 +159,7 @@ impl FontImpl { None } } else { - let mut glyph_info = allocate_glyph( + let glyph_info = allocate_glyph( &mut self.atlas.lock(), &self.ab_glyph_font, glyph_id, @@ -156,12 +168,6 @@ impl FontImpl { self.pixels_per_point, ); - if c == '\t' { - if let Some(space) = self.glyph_info(' ') { - glyph_info.advance_width = crate::text::TAB_SIZE as f32 * space.advance_width; - } - } - self.glyph_info_cache.write().insert(c, glyph_info); Some(glyph_info) }