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 12:47:44 -05:00 committed by GitHub
parent af6548c745
commit 990bdde5e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 47 deletions

View file

@ -528,12 +528,7 @@ impl MarkdownElement {
let text_style = self.style.base_text_style.clone();
let font_id = window.text_system().resolve_font(&text_style.font());
let font_size = text_style.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();
window.request_autoscroll(Bounds::from_corners(
point(position.x - 3. * em_width, position.y - 3. * line_height),
point(position.x + 3. * em_width, position.y + 3. * line_height),