summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-28 13:56:39 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-28 13:58:14 +0200
commit2796a6bc974d847580ab23c6a5f58db994883ec5 (patch)
treea5e17be147ce1726388735286106db5e43fb165d /widget
parentf7fe1edcbbfde71d801379805b4605ff36075b11 (diff)
downloadiced-2796a6bc974d847580ab23c6a5f58db994883ec5.tar.gz
iced-2796a6bc974d847580ab23c6a5f58db994883ec5.tar.bz2
iced-2796a6bc974d847580ab23c6a5f58db994883ec5.zip
Add `padding` to `text::Span`
Diffstat (limited to 'widget')
-rw-r--r--widget/src/markdown.rs3
-rw-r--r--widget/src/text/rich.rs12
2 files changed, 13 insertions, 2 deletions
diff --git a/widget/src/markdown.rs b/widget/src/markdown.rs
index cb3e9cfc..c5eeaea9 100644
--- a/widget/src/markdown.rs
+++ b/widget/src/markdown.rs
@@ -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())
diff --git a/widget/src/text/rich.rs b/widget/src/text/rich.rs
index f636b219..67db31db 100644
--- a/widget/src/text/rich.rs
+++ b/widget/src/text/rich.rs
@@ -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,