Skip to content

Draw rich_text decorations using font metrics#3358

Draft
airstrike wants to merge 2 commits into
iced-rs:masterfrom
airstrike:feat/improved-decorations
Draft

Draw rich_text decorations using font metrics#3358
airstrike wants to merge 2 commits into
iced-rs:masterfrom
airstrike:feat/improved-decorations

Conversation

@airstrike

Copy link
Copy Markdown
Contributor

rich_text draws 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 Decoration to core::text and Paragraph::decoration_bounds, which returns the decoration rectangles cosmic-text resolves at layout from the font's own metrics. rich_text feeds 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 way fill_paragraph anchors 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.

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.
@airstrike airstrike force-pushed the feat/improved-decorations branch from 4310f68 to 07d47c9 Compare June 12, 2026 01:32
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.
@airstrike airstrike force-pushed the feat/improved-decorations branch from 07d47c9 to 3dc8545 Compare June 12, 2026 12:08

@hecrj hecrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising!

Let's wait until the cosmic-text changes go in.

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