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) -> Self
Sourcepub fn family(self, family: FontFamily) -> Self
pub fn family(self, family: FontFamily) -> Self
The span in its own face (see the family field).
Sourcepub fn mono(self) -> Self
pub fn mono(self) -> Self
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) -> Self
pub fn size(self, px: f32) -> Self
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) -> Self
pub fn bold(self) -> Self
pub fn italic(self) -> Self
pub fn underline(self) -> Self
Sourcepub fn underline_color(self, c: Color) -> Self
pub fn underline_color(self, c: Color) -> Self
An underline in its own colour; turns it on.
Sourcepub fn underline_style(self, s: UnderlineStyle) -> Self
pub fn underline_style(self, s: UnderlineStyle) -> Self
An underline of this shape; turns it on.
pub fn strikethrough(self) -> Self
pub fn bg(self, c: Color) -> Self
Sourcepub fn bg_radius(self, r: f32) -> Self
pub fn bg_radius(self, r: f32) -> Self
Rounds the background, joined with the ones it meets (see
Span::bg_radius).