Add background styling to span / rich text
This commit is contained in:
parent
23a7e9f981
commit
ddcf02f9d0
7 changed files with 141 additions and 16 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue