Underline rich_text links when hovered

This commit is contained in:
Héctor Ramón Jiménez 2024-07-28 15:10:33 +02:00
parent bf16d1ddcd
commit ca31dcadd5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 11 additions and 6 deletions

View file

@ -237,7 +237,7 @@ where
theme: &Theme,
defaults: &renderer::Style,
layout: Layout<'_>,
_cursor: mouse::Cursor,
cursor: mouse::Cursor,
viewport: &Rectangle,
) {
let state = tree
@ -246,8 +246,15 @@ where
let style = theme.style(&self.class);
let hovered_span = cursor
.position_in(layout.bounds())
.and_then(|position| state.paragraph.hit_span(position));
for (index, span) in self.spans.iter().enumerate() {
if span.highlight.is_some() || span.underline {
let is_hovered_link =
span.link.is_some() && Some(index) == hovered_span;
if span.highlight.is_some() || span.underline || is_hovered_link {
let translation = layout.position() - Point::ORIGIN;
let regions = state.paragraph.span_bounds(index);
@ -277,7 +284,7 @@ where
}
}
if span.underline {
if span.underline || is_hovered_link {
let line_height = span
.line_height
.unwrap_or(self.line_height)