diff options
author | 2024-07-28 17:45:11 +0200 | |
---|---|---|
committer | 2024-07-28 17:45:11 +0200 | |
commit | ca8ebb16a67095260e4e94109f82d3ac1603e927 (patch) | |
tree | 0abbc20c913a1c002dbcb6af4e9291ead567a17c /widget/src/text/rich.rs | |
parent | ebc6c0eba86608dbd9912ab180f48ca603f20c19 (diff) | |
download | iced-ca8ebb16a67095260e4e94109f82d3ac1603e927.tar.gz iced-ca8ebb16a67095260e4e94109f82d3ac1603e927.tar.bz2 iced-ca8ebb16a67095260e4e94109f82d3ac1603e927.zip |
Implement `strikethrough` support for `rich_text` spans
Diffstat (limited to 'widget/src/text/rich.rs')
-rw-r--r-- | widget/src/text/rich.rs | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/widget/src/text/rich.rs b/widget/src/text/rich.rs index 096056d4..c6aa1e14 100644 --- a/widget/src/text/rich.rs +++ b/widget/src/text/rich.rs @@ -254,7 +254,11 @@ where let is_hovered_link = span.link.is_some() && Some(index) == hovered_span; - if span.highlight.is_some() || span.underline || is_hovered_link { + if span.highlight.is_some() + || span.underline + || span.strikethrough + || is_hovered_link + { let translation = layout.position() - Point::ORIGIN; let regions = state.paragraph.span_bounds(index); @@ -284,7 +288,7 @@ where } } - if span.underline || is_hovered_link { + if span.underline || span.strikethrough || is_hovered_link { let size = span .size .or(self.size) @@ -295,27 +299,47 @@ where .unwrap_or(self.line_height) .to_absolute(size); - for bounds in regions { - renderer.fill_quad( - renderer::Quad { - bounds: Rectangle::new( - bounds.position() - + translation - + Vector::new( - 0.0, - size.0 - + (line_height.0 - size.0) - / 2.0 - - size.0 * 0.08, - ), - Size::new(bounds.width, 1.0), - ), - ..Default::default() - }, - span.color - .or(style.color) - .unwrap_or(defaults.text_color), + let color = span + .color + .or(style.color) + .unwrap_or(defaults.text_color); + + let baseline = translation + + Vector::new( + 0.0, + size.0 + (line_height.0 - size.0) / 2.0, ); + + if span.underline || is_hovered_link { + for bounds in ®ions { + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle::new( + bounds.position() + baseline + - Vector::new(0.0, size.0 * 0.08), + Size::new(bounds.width, 1.0), + ), + ..Default::default() + }, + color, + ); + } + } + + if span.strikethrough { + for bounds in ®ions { + renderer.fill_quad( + renderer::Quad { + bounds: Rectangle::new( + bounds.position() + baseline + - Vector::new(0.0, size.0 / 2.0), + Size::new(bounds.width, 1.0), + ), + ..Default::default() + }, + color, + ); + } } } } |