Skip to main content

StyledText

Struct StyledText 

Source
pub struct StyledText {
    pub region: Rect,
    pub scale: f32,
    pub custom_padding: Option<(usize, usize)>,
    pub gradient_region: Option<Rect>,
    /* private fields */
}
Expand description

A styled text. Construct one with StyledTextBuilder

Each text object may have different styling per span, each span is assigned a metadata index which is propagated through cosmic_text attrs onto every DecodedGlyph::metadata produced from this text. Use StyledText::style_at to resolve a metadata value back to its TextStyle.

Note that styles not enabled in crate::Features are ignored at render time.

Fields§

§region: Rect§scale: f32§custom_padding: Option<(usize, usize)>§gradient_region: Option<Rect>

Screen-space rectangle used to normalise gradient positions. Vertex positions are mapped so that vertex at the the rect’s top-left corner is (0, 0) and its bottom-right corner is (1, 1).

When None, StyledText::region is used instead. Set this explicitly when multiple StyledText objects should share a single gradient that spans all of them.

Implementations§

Source§

impl StyledText

Source

pub fn as_text(&self, id: u64) -> Text<'_>

Borrow this styled text as a low-level Text for crate::MeshEncoder::encode.

id is supplied by the caller (e.g. crate::TextRenderer::prepare passes the enumeration index) and surfaces on every produced DecodedGlyph::text_id.

Source

pub fn style_at(&self, metadata: usize) -> &TextStyle

Resolve a metadata value back to its TextStyle.

Source

pub fn styles(&self) -> impl Iterator<Item = &TextStyle>

Iterate over all styles in this text.

Source

pub fn buffer(&self) -> &Buffer

Returns the underlying cosmic_text::Buffer.

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> 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, 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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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