Skip to content

Fix text background, underline and strikethrough leaving the row when TextFormat::line_height is set - #8941

Open
iamseeley wants to merge 5 commits into
emilk:mainfrom
membrane-io:thomas/text-background-font-height
Open

iamseeley wants to merge 5 commits into
emilk:mainfrom
membrane-io:thomas/text-background-font-height

Conversation

@iamseeley

@iamseeley iamseeley commented Nov 24, 2026 •

Copy link
Copy Markdown
  • I have followed the instructions in the PR template

Since #8030, a custom TextFormat::line_height centers the text in the line. But the background (#8872), the underline and the strikethrough still use Glyph::logical_rect(), which starts at the top of the font and is line_height tall. So with a taller line height they reach past the bottom of the row. With line_height = 40, the background of 14 pt monospace was 11.5..52.5 in a 0..40 row. Now it is 11.5..29.5.

This adds Glyph::font_rect() and uses it for all three. A line height shorter than the font now gets a background that covers the whole font, like an inline <code> with a small line-height in CSS. Without a custom line_height, nothing changes.

The scene of the new snapshot, with line_height = 28, at pixels_per_point = 2:

Before After

Tests: one unit test, which fails without the change, and a new snapshot code_background_tall_line_height.

Open question

Should Glyph::logical_rect() change instead? After this PR, nothing in egui uses its height. Since #8030 its height reaches below the line when line_height is set.

@github-actions

Copy link
Copy Markdown

Preview is being built...

Preview will be available at https://egui-pr-preview.github.io/pr/8941-thomas/text-background-font-height

View snapshot changes at kitdiff

@iamseeley iamseeley changed the title Make text backgrounds as tall as the font, not the line height Fix text background, underline and strikethrough leaving the row when TextFormat::line_height is set Nov 24, 2026
iamseeley added a commit to membrane-io/egui that referenced this pull request Nov 24, 2026
iamseeley added a commit to membrane-io/egui that referenced this pull request Nov 24, 2026
@iamseeley
iamseeley marked this pull request as ready for review November 24, 2026 19:32
@rustbasic

Copy link
Copy Markdown
Contributor

This looks like a useful follow-up to #8030.
Using font_rect() here makes sense; I’d keep logical_rect() unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants