From ddcf02f9d0377afe6a35dbbb09a29b4bd52efe2e Mon Sep 17 00:00:00 2001 From: Cory Forsstrom Date: Tue, 23 Jul 2024 13:36:40 -0700 Subject: Add background styling to span / rich text --- widget/src/text/rich.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'widget/src/text/rich.rs') diff --git a/widget/src/text/rich.rs b/widget/src/text/rich.rs index 9c0e2fac..832a3ae7 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, Widget, }; use std::borrow::Cow; @@ -246,6 +246,24 @@ where let style = theme.style(&self.class); + // Draw backgrounds + for (index, span) in self.spans.iter().enumerate() { + if let Some(background) = span.background { + let translation = layout.position() - Point::ORIGIN; + + for bounds in state.paragraph.span_bounds(index) { + renderer.fill_quad( + renderer::Quad { + bounds: bounds + translation, + border: background.border, + ..Default::default() + }, + background.color, + ); + } + } + } + text::draw( renderer, defaults, -- cgit