Add padding to text::Span

This commit is contained in:
Héctor Ramón Jiménez 2024-07-28 13:56:39 +02:00
parent f7fe1edcbb
commit 2796a6bc97
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 57 additions and 12 deletions

View file

@ -262,7 +262,8 @@ pub fn parse<'a>(
.font(Font::MONOSPACE)
.color(Color::WHITE)
.background(color!(0x111111))
.border(border::rounded(2));
.border(border::rounded(2))
.padding(padding::left(2).right(2));
let span = if let Some(link) = link.as_ref() {
span.color(palette.primary).link(link.clone())

View file

@ -10,7 +10,7 @@ use crate::core::widget::text::{
use crate::core::widget::tree::{self, Tree};
use crate::core::{
self, Clipboard, Color, Element, Event, Layout, Length, Pixels, Point,
Rectangle, Shell, Size, Widget,
Rectangle, Shell, Size, Vector, Widget,
};
use std::borrow::Cow;
@ -252,6 +252,16 @@ where
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,