gpui: Add helper methods for em width and em advance (#24036)

This PR adds two helpers methods to the `TextSystem`:

- `em_width`
- `em_advance`

These methods return the width and advance width for an `em`,
respectively.

We were using these definitions in a number of different spots, and by
unifying them we better canonicalize that an `em` is based on the `m`
character.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2025-01-31 17:47:44 +00:00
committed by GitHub
parent af6548c745
commit 990bdde5e8
4 changed files with 23 additions and 47 deletions
+1 -7
View File
@@ -14124,13 +14124,7 @@ impl Editor {
let font_id = window.text_system().resolve_font(&style.text.font());
let font_size = style.text.font_size.to_pixels(window.rem_size());
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.unwrap()
.size
.width;
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
gpui::Point::new(em_width, line_height)
}
+7 -34
View File
@@ -836,12 +836,7 @@ impl EditorElement {
let style = editor.style.clone().unwrap_or_default();
let font_id = window.text_system().resolve_font(&style.text.font());
let font_size = style.text.font_size.to_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.unwrap()
.size
.width;
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
let scroll_margin_x = EditorSettings::get_global(cx).horizontal_scroll_margin;
@@ -6398,12 +6393,8 @@ impl Element for EditorElement {
window.text_system().resolve_font(&style.text.font());
let font_size =
style.text.font_size.to_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.unwrap()
.size
.width;
let em_width =
window.text_system().em_width(font_id, font_size).unwrap();
size(line.width + em_width, height)
},
@@ -6480,17 +6471,8 @@ impl Element for EditorElement {
let font_id = window.text_system().resolve_font(&style.text.font());
let font_size = style.text.font_size.to_pixels(window.rem_size());
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.unwrap()
.size
.width;
let em_advance = window
.text_system()
.advance(font_id, font_size, 'm')
.unwrap()
.width;
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
let em_advance = window.text_system().em_advance(font_id, font_size).unwrap();
let letter_size = size(em_width, line_height);
@@ -8060,17 +8042,8 @@ fn compute_auto_height_layout(
let font_id = window.text_system().resolve_font(&style.text.font());
let font_size = style.text.font_size.to_pixels(window.rem_size());
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window
.text_system()
.typographic_bounds(font_id, font_size, 'm')
.unwrap()
.size
.width;
let em_advance = window
.text_system()
.advance(font_id, font_size, 'm')
.unwrap()
.width;
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
let em_advance = window.text_system().em_advance(font_id, font_size).unwrap();
let mut snapshot = editor.snapshot(window, cx);
let gutter_dimensions = snapshot.gutter_dimensions(