@@ -8,7 +8,7 @@ pub use highlighter::Highlighter;
88pub use paragraph:: Paragraph ;
99
1010use crate :: alignment;
11- use crate :: { Color , Pixels , Point , Rectangle , Size } ;
11+ use crate :: { Border , Color , Pixels , Point , Rectangle , Size } ;
1212
1313use std:: borrow:: Cow ;
1414use std:: hash:: { Hash , Hasher } ;
@@ -235,6 +235,8 @@ pub struct Span<'a, Link = (), Font = crate::Font> {
235235 pub font : Option < Font > ,
236236 /// The [`Color`] of the [`Span`].
237237 pub color : Option < Color > ,
238+ /// The [`Background`] of the [`Span`].
239+ pub background : Option < Background > ,
238240 /// The link of the [`Span`].
239241 pub link : Option < Link > ,
240242}
@@ -248,6 +250,7 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
248250 line_height : None ,
249251 font : None ,
250252 color : None ,
253+ background : None ,
251254 link : None ,
252255 }
253256 }
@@ -288,6 +291,21 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
288291 self
289292 }
290293
294+ /// Sets the [`Background`] of the [`Span`].
295+ pub fn background ( mut self , background : impl Into < Background > ) -> Self {
296+ self . background = Some ( background. into ( ) ) ;
297+ self
298+ }
299+
300+ /// Sets the [`Background`] of the [`Span`], if any.
301+ pub fn background_maybe (
302+ mut self ,
303+ background : Option < impl Into < Background > > ,
304+ ) -> Self {
305+ self . background = background. map ( Into :: into) ;
306+ self
307+ }
308+
291309 /// Sets the link of the [`Span`].
292310 pub fn link ( mut self , link : impl Into < Link > ) -> Self {
293311 self . link = Some ( link. into ( ) ) ;
@@ -308,6 +326,7 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
308326 line_height : self . line_height ,
309327 font : self . font ,
310328 color : self . color ,
329+ background : self . background ,
311330 link : self . link ,
312331 }
313332 }
@@ -406,3 +425,21 @@ into_fragment!(isize);
406425
407426into_fragment ! ( f32 ) ;
408427into_fragment ! ( f64 ) ;
428+
429+ /// The background style of text
430+ #[ derive( Debug , Clone , Copy ) ]
431+ pub struct Background {
432+ /// The background [`Color`]
433+ pub color : Color ,
434+ /// The background [`Border`]
435+ pub border : Border ,
436+ }
437+
438+ impl From < Color > for Background {
439+ fn from ( color : Color ) -> Self {
440+ Background {
441+ color,
442+ border : Border :: default ( ) ,
443+ }
444+ }
445+ }
0 commit comments