Draw rich_text decorations using font metrics#3358
Draft
airstrike wants to merge 2 commits into
Draft
Conversation
rich_text drew underlines and strikethroughs at a hardcoded fraction of the text size (size * 0.08), ignoring the font's real metrics. Add Decoration to core::text and Paragraph::decoration_bounds, which positions decoration lines from the metrics cosmic-text resolves at layout. rich_text feeds span decoration into cosmic-text, including underline geometry for link spans, and fills the bounds it gets back: always for decorated spans, on hover for links. Highlight and decoration quads are anchored the way fill_paragraph anchors glyphs, so they stay with the text under alignment. Fix: requires cosmic-text's DecorationSpan::x_range; the patch points at that branch until a release carries it.
4310f68 to
07d47c9
Compare
Add a screen demonstrating rich text: underline and strikethrough with per-span colors, and Articles 1 to 3 of the Universal Declaration of Human Rights cycling through eleven languages with a fade transition, exercising wrapping, BiDi, and several scripts.
07d47c9 to
3dc8545
Compare
hecrj
reviewed
Jun 15, 2026
hecrj
left a comment
Member
There was a problem hiding this comment.
Looks promising!
Let's wait until the cosmic-text changes go in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rich_textdraws underlines and strikethroughs at a hardcoded fraction of the text size (size * 0.08), ignoring the font's real metrics. The quads are also translated by the layout position alone, so they drift away from the glyphs whenever the paragraph is aligned.This PR adds
Decorationtocore::textandParagraph::decoration_bounds, which returns the decoration rectangles cosmic-text resolves at layout from the font's own metrics.rich_textfeeds span decorations into cosmic-text, including underline geometry for link spans, and fills the bounds it gets back: always for decorated spans, on hover for links, with no relayout on hover. Highlight and decoration quads are anchored the wayfill_paragraphanchors glyphs, so they stay with the text under alignment.It also adds a "Rich text" screen to the
tour, cycling Articles 1 to 3 of the Universal Declaration of Human Rights through eleven languages with a fade transition, exercising wrapping, BiDi, and several scripts. The screen's heading is a link with no explicit underline, revealing one on hover.Depends on pop-os/cosmic-text#511.
[patch.crates-io]points at that branch until a release carries it.