pub struct Span<'a> {
pub text: &'a str,
pub color: Option<Color>,
pub bold: bool,
pub italic: bool,
pub underline: bool,
pub underline_color: Option<Color>,
pub underline_style: UnderlineStyle,
pub strikethrough: bool,
pub bg: Option<Color>,
pub bg_radius: f32,
pub family: Option<FontFamily>,
pub size: Option<f32>,
}Expand description
One styled run inside a rich-text paragraph. Spans are shaped and wrapped together as a single flow; plain data, so every frontend can build them.
Fields§
§text: &'a str§color: Option<Color>§bold: bool§italic: bool§underline: boolA line under the span, where the face puts its underline.
underline_color: Option<Color>The underline’s own colour; None is the span’s.
underline_style: UnderlineStyleThe underline’s shape.
strikethrough: boolA line through the span, where the face puts its strikeout.
bg: Option<Color>A background behind the span’s glyphs, one rect per line it spans, so it follows the span across a wrap the way a box cannot.
bg_radius: f32The background’s corner radius, logical px. Above zero, every background of the same colour and radius that meets another edge to edge on the line above or below — in this text or another — is one shape with it: its corners convex where a line reaches past its neighbour, concave where it falls short, round where nothing meets it. What a selection over lines looks like.
family: Option<FontFamily>The span’s own face, in place of the paragraph’s: inline code in
FontFamily::Mono inside a sans line. None is the paragraph’s.
The span keeps the paragraph’s weights for its family (bold is the
family’s bold), and its glyphs, carets and selection are measured
in the face they are drawn in, so byte positions stay exact across
the change.
size: Option<f32>The span’s own size in logical px, in place of the paragraph’s: a
heading’s larger first word, a smaller footnote mark. Its line
height scales with it at the paragraph’s ratio, and a line is as
tall as its tallest span. None is the paragraph’s. A paragraph
with a sized span is shaped whole, never chunked as a long line.
Implementations§
Source§impl<'a> Span<'a>
impl<'a> Span<'a>
pub fn new(text: &'a str) -> Span<'a>
Sourcepub fn family(self, family: FontFamily) -> Span<'a>
pub fn family(self, family: FontFamily) -> Span<'a>
The span in its own face (see the family field).
Sourcepub fn mono(self) -> Span<'a>
pub fn mono(self) -> Span<'a>
The span in the monospace face: inline code.
let code = Span::new("cargo test").mono();
assert_eq!(code.family, Some(FontFamily::Mono));Sourcepub fn size(self, px: f32) -> Span<'a>
pub fn size(self, px: f32) -> Span<'a>
The span at its own size in logical px (see the size field); a
size that is not a positive number is the paragraph’s.
pub fn color(self, c: Color) -> Span<'a>
pub fn bold(self) -> Span<'a>
pub fn italic(self) -> Span<'a>
pub fn underline(self) -> Span<'a>
Sourcepub fn underline_color(self, c: Color) -> Span<'a>
pub fn underline_color(self, c: Color) -> Span<'a>
An underline in its own colour; turns it on.
Sourcepub fn underline_style(self, s: UnderlineStyle) -> Span<'a>
pub fn underline_style(self, s: UnderlineStyle) -> Span<'a>
An underline of this shape; turns it on.
pub fn strikethrough(self) -> Span<'a>
pub fn bg(self, c: Color) -> Span<'a>
Sourcepub fn bg_radius(self, r: f32) -> Span<'a>
pub fn bg_radius(self, r: f32) -> Span<'a>
Rounds the background, joined with the ones it meets (see
Span::bg_radius).
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Span<'a>
impl<'a> RefUnwindSafe for Span<'a>
impl<'a> Send for Span<'a>
impl<'a> Sync for Span<'a>
impl<'a> Unpin for Span<'a>
impl<'a> UnsafeUnpin for Span<'a>
impl<'a> UnwindSafe for Span<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.