Skip to main content

RichTextSpan

Struct RichTextSpan 

Source
pub struct RichTextSpan {
    pub text: String,
    pub size_px: f32,
    pub color: Option<Color>,
    pub font_stack: Option<String>,
    pub weight: Option<u16>,
    pub italic: bool,
}
Expand description

富文本样式 span。颜色只影响绘制,不参与 shape 缓存 key; 字号/字体栈/字重/斜体会改变 shaping,全部计入缓存签名。

Fields§

§text: String§size_px: f32§color: Option<Color>

文字颜色;None = 跟随所在主题(RichTextWidget 使用 theme.text.body.color)

§font_stack: Option<String>§weight: Option<u16>

字重(CSS 数值 100..=900;None = 400 正常)。

由字体匹配决定实际效果:家族里有更重的静态字面就用静态字面,可变字体则走 wght 轴;框架不做合成加粗(parley 0.4 与 0.12 都没有 embolden,升级时查过源码), 所以缺字面时 会退回最近的可用字面(视觉上可能不变粗)。

§italic: bool

斜体:true = 请求 Italic 字面(同样依赖家族是否提供,无合成倾斜)。

Implementations§

Source§

impl RichTextSpan

Source

pub fn new(text: impl Into<String>) -> RichTextSpan

Source

pub fn with_size(self, size_px: f32) -> RichTextSpan

Source

pub fn with_color(self, color: Color) -> RichTextSpan

Source

pub fn with_font_stack(self, stack: impl Into<String>) -> RichTextSpan

Source

pub fn with_weight(self, weight: u16) -> RichTextSpan

指定字重(CSS 数值,常用:400 正常 / 500 中等 / 600 半粗 / 700 粗)。

Source

pub fn bold(self) -> RichTextSpan

粗体(= with_weight(700))

Source

pub fn with_italic(self, italic: bool) -> RichTextSpan

Source

pub fn italic(self) -> RichTextSpan

斜体(= with_italic(true))

Trait Implementations§

Source§

impl Clone for RichTextSpan

Source§

fn clone(&self) -> RichTextSpan

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 RichTextSpan

Source§

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

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

impl PartialEq for RichTextSpan

Source§

fn eq(&self, other: &RichTextSpan) -> 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 RichTextSpan

Auto Trait Implementations§

§

impl Forget for RichTextSpan

§

impl Freeze for RichTextSpan
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for RichTextSpan

§

impl RefUnwindSafe for RichTextSpan

§

impl Send for RichTextSpan
where RawVecInner: Send,

§

impl Sync for RichTextSpan
where RawVecInner: Sync,

§

impl Unpin for RichTextSpan
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for RichTextSpan

§

impl UnwindSafe for RichTextSpan
where RawVecInner: UnwindSafe,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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