From 8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 21 Nov 2022 17:33:23 +0100 Subject: [PATCH] Added support for thin space https://en.wikipedia.org/wiki/Thin_space --- CHANGELOG.md | 1 + crates/epaint/CHANGELOG.md | 3 ++- crates/epaint/src/text/font.rs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ba1e13..80ed7f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG * Added possibility to enable text wrap for the selected text of `egui::ComboBox` ([#2272](https://github.com/emilk/egui/pull/2244)) * Added `Area::constrain` and `Window::constrain` which constrains area to the screen bounds. ([#2270](https://github.com/emilk/egui/pull/2270)). * Added `Area::pivot` and `Window::pivot` which controls what part of the window to position. ([#2303](https://github.com/emilk/egui/pull/2303)). +* Added support for [thin space](https://en.wikipedia.org/wiki/Thin_space). ### Changed 🔧 * Panels always have a separator line, but no stroke on other sides. Their spacing has also changed slightly ([#2261](https://github.com/emilk/egui/pull/2261)). diff --git a/crates/epaint/CHANGELOG.md b/crates/epaint/CHANGELOG.md index 1bf8fb01..a5b06d8e 100644 --- a/crates/epaint/CHANGELOG.md +++ b/crates/epaint/CHANGELOG.md @@ -5,7 +5,8 @@ All notable changes to the epaint crate will be documented in this file. ## Unreleased * ⚠️ BREAKING: Fix text being too small ([#2069](https://github.com/emilk/egui/pull/2069)). * ⚠️ BREAKING: epaint now expects integrations to do all color blending in gamma space ([#2071](https://github.com/emilk/egui/pull/2071)). -* Add `Fonts::has_glyph(s)` for querying if a glyph is supported ([#2202](https://github.com/emilk/egui/pull/2202)). +* Added `Fonts::has_glyph(s)` for querying if a glyph is supported ([#2202](https://github.com/emilk/egui/pull/2202)). +* Added support for [thin space](https://en.wikipedia.org/wiki/Thin_space). ## 0.19.0 - 2022-08-20 diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index ee0574ae..e93356ab 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -156,6 +156,23 @@ impl FontImpl { } } + if c == '\u{2009}' { + // Thin space, often used as thousands deliminator: 1 234 567 890 + // 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.height_in_points; // TODO(emilk): is this right? + let advance_width = f32::min(em / 6.0, space.advance_width * 0.5); + let glyph_info = GlyphInfo { + advance_width, + ..GlyphInfo::default() + }; + self.glyph_info_cache.write().insert(c, glyph_info); + return Some(glyph_info); + } + } + // Add new character: use ab_glyph::Font as _; let glyph_id = self.ab_glyph_font.glyph_id(c);