Skip to main content

Text

Struct Text 

Source
pub struct Text<'a> {
    pub content: StrRef<'a>,
    pub font_size: u8,
    pub flags: u8,
    pub color: Color,
}
Expand description

文本原语节点。

Fields§

§content: StrRef<'a>§font_size: u8§flags: u8

位域:align(2b: 0=Left, 1=Center, 2=Right) | ellipsis(1b: 0x04) | nowrap(1b: 0x08) | explicit_size(1b: 0x10) | explicit_color(1b: 0x20)。

§color: Color

Implementations§

Source§

impl<'a> Text<'a>

Source

pub const fn size(self, px: u8) -> Self

设置字号大小(像素)。

Source

pub const fn text_size(self, px: u8) -> Self

设置字号大小(与 Div::text_size 对齐的别名)。

Source

pub const fn text_xs(self) -> Self

Source

pub const fn text_sm(self) -> Self

Source

pub const fn text_base(self) -> Self

Source

pub const fn text_lg(self) -> Self

Source

pub const fn text_xl(self) -> Self

Source

pub const fn text_2xl(self) -> Self

Source

pub const fn text_3xl(self) -> Self

Source

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

设置文本颜色。

Source

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

设置文本颜色(与 GPUI .text_color(...) 对齐的别名)。

Source

pub const fn has_explicit_size(&self) -> bool

是否显式覆盖了字号(否则继承父 Div 的 text_size)。

Source

pub const fn has_explicit_color(&self) -> bool

是否显式覆盖了颜色(否则继承父 Div 的 text_color)。

Source

pub const fn align(self, align: TextAlign) -> Self

设置文本水平对齐方式。

Source

pub const fn text_left(self) -> Self

设置文本左对齐。

Source

pub const fn text_center(self) -> Self

设置文本水平居中对齐。

Source

pub const fn text_right(self) -> Self

设置文本右对齐。

Source

pub fn text_start(self, cx: &FrameScope) -> Self

按当前语言的书写方向自动设置“逻辑起始端对齐”(LTR 为左对齐,RTL 如阿拉伯语/希伯来语自动镜像为右对齐)。

Source

pub fn text_end(self, cx: &FrameScope) -> Self

按当前语言的书写方向自动设置“逻辑末端对齐”(LTR 为右对齐,RTL 自动镜像为左对齐)。

Source

pub const fn ellipsis(self) -> Self

开启单行省略号截断(超出容器宽度时自动截断并追加 ...)。

Source

pub const fn nowrap(self) -> Self

禁用自动多行折行(强制单行排版)。

Source

pub const fn text_align(&self) -> TextAlign

读取水平对齐方式。

Source

pub const fn is_ellipsis(&self) -> bool

是否启用省略号截断。

Source

pub const fn is_nowrap(&self) -> bool

是否禁用自动多行换行。

Trait Implementations§

Source§

impl<'a> Clone for Text<'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 Text<'a>

Source§

impl<'a> Debug for Text<'a>

Source§

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

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

impl<'a> IntoElement<'a> for Text<'a>

Source§

fn into_element(self, _cx: &'a FrameScope) -> Element<'a>

Source§

fn into_any_element(self, cx: &'a FrameScope) -> Element<'a>

与 GPUI .into_any_element() 对应的语义别名(零堆分配返回闭合枚举 Element<'a>)。

Auto Trait Implementations§

§

impl<'a> Forget for Text<'a>

§

impl<'a> Freeze for Text<'a>

§

impl<'a> Move for Text<'a>

§

impl<'a> RefUnwindSafe for Text<'a>

§

impl<'a> Send for Text<'a>

§

impl<'a> Sync for Text<'a>

§

impl<'a> Unpin for Text<'a>

§

impl<'a> UnsafeUnpin for Text<'a>

§

impl<'a> UnwindSafe for Text<'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> FluentBuilder for T

Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self

当 condition 为 true 时执行闭包修饰自身,否则原样返回。
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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