Skip to main content

Span

Struct Span 

Source
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: bool

A 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: UnderlineStyle

The underline’s shape.

§strikethrough: bool

A 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: f32

The 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>

Source

pub fn new(text: &'a str) -> Self

Source

pub fn family(self, family: FontFamily) -> Self

The span in its own face (see the family field).

Source

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));
Source

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.

Source

pub fn color(self, c: Color) -> Self

Source

pub fn bold(self) -> Self

Source

pub fn italic(self) -> Self

Source

pub fn underline(self) -> Self

Source

pub fn underline_color(self, c: Color) -> Self

An underline in its own colour; turns it on.

Source

pub fn underline_style(self, s: UnderlineStyle) -> Self

An underline of this shape; turns it on.

Source

pub fn strikethrough(self) -> Self

Source

pub fn bg(self, c: Color) -> Self

Source

pub fn bg_radius(self, r: f32) -> Self

Rounds the background, joined with the ones it meets (see Span::bg_radius).

Trait Implementations§

Source§

impl<'a> Clone for Span<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Span<'a>

Source§

impl<'a> Debug for Span<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.