Skip to main content

TextElement

Struct TextElement 

Source
pub struct TextElement {
Show 14 fields pub font: FontSpec, pub color: Option<ThemeColor>, pub size_pt: Option<Length>, pub align: Option<HAlign>, pub valign: Option<VAlign>, pub angle: Option<Rotation>, pub lineheight: Option<Length>, pub letter_spacing: Option<Length>, pub underline: Option<bool>, pub strikethrough: Option<bool>, pub margin: Option<Margin>, pub text_stroke: Option<ThemeColor>, pub text_linewidth_pt: Option<Length>, pub markdown: Option<bool>,
}
Expand description

Text styling — font selection, colour, size, alignment, rotation, line height, margin.

Every field is Option<...> so an override can set just the fields it cares about, with the rest cascading through the parent chain. After cascading, callers fall through to text_concrete_defaults for any remaining Nones.

Fields§

§font: FontSpec

Font specification. Each FontSpec field cascades independently — a child can override weight while inheriting family.

§color: Option<ThemeColor>

Ink colour. Resolved against the theme’s palette at draw time.

§size_pt: Option<Length>

Font size. Resolves against the inherited parent’s resolved size — Rel(1.5) = 1.5× the parent.

§align: Option<HAlign>

Horizontal alignment within the slot.

§valign: Option<VAlign>

Vertical alignment within the slot.

§angle: Option<Rotation>

Rotation — absolute degrees, or Along / Across to follow the surface’s baseline direction.

§lineheight: Option<Length>

Line height — typically Rel(1.2) (120% of the resolved size).

§letter_spacing: Option<Length>

Letter spacing (tracking). Length::Abs(pt) is absolute pt between glyph pairs; Length::Rel(m) is m × resolved_size_pt. Abs(0.0) (the default) is the natural font advance.

§underline: Option<bool>

Underline the text. Position and thickness are taken from the font’s reported metrics.

§strikethrough: Option<bool>

Strike through the text. Position and thickness are taken from the font’s reported metrics.

§margin: Option<Margin>

Margin around the text block, each side independent.

§text_stroke: Option<ThemeColor>

Per-glyph outline color. None renders no outline — the one field text_concrete_defaults leaves unset, since a concrete value here would halo every string in the figure. A child layer therefore cannot clear an outline a parent set by writing None; set text_linewidth_pt to Abs(0.0) instead.

Mirrors the "text_stroke" channel on the text geoms.

§text_linewidth_pt: Option<Length>

Outline thickness. Resolves against DEFAULT_LINEWIDTH_PT, the parent every other linewidth in the theme resolves against, so Rel(2.0) is twice the standard hairline rather than a multiple of the font size. Has no effect unless text_stroke resolves to a color.

The stroke centres on the glyph contour and does not grow the text’s measured box, matching the text geoms — a deliberately heavy outline needs clearance from margin, which is measured.

§markdown: Option<bool>

Interpret the slot’s string as marquee-flavoured markdown and shape it through the rich-text pipeline (crate::text::rich::RichTextRun). Off by default so every existing chrome label renders unchanged.

When on, the slot’s crate::plot::theme::Theme::rich_text style sheet drives the markdown styling; the TextElement’s resolved font / colour / size / letter-spacing feed into the rich run’s base style so plain-text fragments still inherit the slot’s ambient look.

Text-outline (text_stroke / text_linewidth_pt) is not applied on markdown slots — the rich pipeline doesn’t expose a glyph-outline surface. Chrome renderers fall back to plain text when an outline is needed on the same slot.

Implementations§

Source§

impl TextElement

Source

pub fn cascade(&self, parent: &Self) -> Self

Merge self over parent: per-field, self’s Some wins; None falls through to parent’s value. font cascades through FontSpec::cascade (each FontSpec field merges independently; feature / variation lists merge by tag).

Trait Implementations§

Source§

impl Clone for TextElement

Source§

fn clone(&self) -> TextElement

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 Debug for TextElement

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TextElement

Source§

fn default() -> TextElement

Returns the “default value” for a type. Read more
Source§

impl PartialEq for TextElement

Source§

fn eq(&self, other: &TextElement) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextElement

Auto Trait Implementations§

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<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more