diff options
author | 2024-07-28 14:40:58 +0200 | |
---|---|---|
committer | 2024-07-28 14:40:58 +0200 | |
commit | c47a6ed7b639cf76086554fe2b65a8acecb61ea2 (patch) | |
tree | abb30c0620ccab372ed6058f1fd5a2b04e1e4726 /widget/src/text/rich.rs | |
parent | 23a7e9f981728e8a95039db8eb8e9f3d8c6ba3d7 (diff) | |
parent | 41a7318e5df3a49bf6e7fc2110155f2f22ff7e60 (diff) | |
download | iced-c47a6ed7b639cf76086554fe2b65a8acecb61ea2.tar.gz iced-c47a6ed7b639cf76086554fe2b65a8acecb61ea2.tar.bz2 iced-c47a6ed7b639cf76086554fe2b65a8acecb61ea2.zip |
Merge pull request #2516 from tarkah/feat/span-background
Add background styling to span / rich text
Diffstat (limited to 'widget/src/text/rich.rs')
-rw-r--r-- | widget/src/text/rich.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/widget/src/text/rich.rs b/widget/src/text/rich.rs index 9c0e2fac..9935e6c5 100644 --- a/widget/src/text/rich.rs +++ b/widget/src/text/rich.rs @@ -9,8 +9,8 @@ use crate::core::widget::text::{ }; use crate::core::widget::tree::{self, Tree}; use crate::core::{ - self, Clipboard, Color, Element, Event, Layout, Length, Pixels, Rectangle, - Shell, Size, Widget, + self, Clipboard, Color, Element, Event, Layout, Length, Pixels, Point, + Rectangle, Shell, Size, Vector, Widget, }; use std::borrow::Cow; @@ -246,6 +246,33 @@ where let style = theme.style(&self.class); + for (index, span) in self.spans.iter().enumerate() { + if let Some(highlight) = span.highlight { + let translation = layout.position() - Point::ORIGIN; + + for bounds in state.paragraph.span_bounds(index) { + let bounds = Rectangle::new( + bounds.position() + - Vector::new(span.padding.left, span.padding.top), + bounds.size() + + Size::new( + span.padding.horizontal(), + span.padding.vertical(), + ), + ); + + renderer.fill_quad( + renderer::Quad { + bounds: bounds + translation, + border: highlight.border, + ..Default::default() + }, + highlight.background, + ); + } + } + } + text::draw( renderer, defaults, |