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>None = DEFAULT_FONT_STACK
weight: Option<u16>字重(CSS 数值 100..=900;None = 400 正常)。
由字体匹配决定实际效果:家族里有更重的静态字面就用静态字面,可变字体则走
wght 轴;框架不做合成加粗(parley 0.4 与 0.12 都没有 embolden,升级时查过源码),
所以缺字面时
会退回最近的可用字面(视觉上可能不变粗)。
italic: bool斜体:true = 请求 Italic 字面(同样依赖家族是否提供,无合成倾斜)。
Implementations§
Source§impl RichTextSpan
impl RichTextSpan
pub fn new(text: impl Into<String>) -> RichTextSpan
pub fn with_size(self, size_px: f32) -> RichTextSpan
pub fn with_color(self, color: Color) -> RichTextSpan
pub fn with_font_stack(self, stack: impl Into<String>) -> RichTextSpan
Sourcepub fn with_weight(self, weight: u16) -> RichTextSpan
pub fn with_weight(self, weight: u16) -> RichTextSpan
指定字重(CSS 数值,常用:400 正常 / 500 中等 / 600 半粗 / 700 粗)。
Sourcepub fn bold(self) -> RichTextSpan
pub fn bold(self) -> RichTextSpan
粗体(= with_weight(700))
pub fn with_italic(self, italic: bool) -> RichTextSpan
Sourcepub fn italic(self) -> RichTextSpan
pub fn italic(self) -> RichTextSpan
斜体(= with_italic(true))
Trait Implementations§
Source§impl Clone for RichTextSpan
impl Clone for RichTextSpan
Source§fn clone(&self) -> RichTextSpan
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RichTextSpan
impl Debug for RichTextSpan
Source§impl PartialEq for RichTextSpan
impl PartialEq for RichTextSpan
impl StructuralPartialEq for RichTextSpan
Auto Trait Implementations§
impl Forget for RichTextSpan
impl Freeze for RichTextSpan
impl Move for RichTextSpan
impl RefUnwindSafe for RichTextSpan
impl Send for RichTextSpanwhere
RawVecInner: Send,
impl Sync for RichTextSpanwhere
RawVecInner: Sync,
impl Unpin for RichTextSpan
impl UnsafeUnpin for RichTextSpan
impl UnwindSafe for RichTextSpanwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more