pub enum Element<'a> {
Div(DivNode<'a>),
Text(Text<'a>),
Img(Img<'a>),
RichText(&'a RichTextSpec<'a>),
DecodedImage(&'a DecodedImageSpec),
Vector(&'a VectorDrawSpec<'a>),
SceneCanvas(&'a SceneCanvasSpec<'a>),
SubView {
id: PodId,
generation: u16,
resolved: Cell<Option<&'a Element<'a>>>,
},
}Expand description
闭合 UI 元素枚举(严格限定 4 种核心节点,彻底消除 Box<dyn Element> 虚表开销与内存碎片)。
Variants§
Div(DivNode<'a>)
弹性盒容器节点(64B 紧凑核心 + 按需分配在 ScratchArena 中的视觉/交互扩展)。
Text(Text<'a>)
文本节点。
Img(Img<'a>)
位图/图标掩码或过程化贴图节点(对应 DrawPayload::Sprite)。
RichText(&'a RichTextSpec<'a>)
行内多字重/多色/BiDi/彩色 Emoji 富文本段落(8B Arena 引用,0 字节膨胀 Element)。
DecodedImage(&'a DecodedImageSpec)
支持 ObjectFit / NineSlice / LRU 缓存的解码图像元素(8B Arena 引用)。
Vector(&'a VectorDrawSpec<'a>)
原生抗锯齿 2D 矢量画布(Polyline / Polygon / Circle / Sector,8B Arena 引用)。
SceneCanvas(&'a SceneCanvasSpec<'a>)
高密度 2D 交互式场景画布(32B 静态几何 + 4B 动态状态分离 + 可选 custom-shader,8B Arena 引用)。
SubView
视图边界:引用另一个常驻 Handle<T>(PodId + generation),作为局部重绘与独立布局的隔离点。
Trait Implementations§
Source§impl<'a> IntoElement<'a> for Element<'a>
impl<'a> IntoElement<'a> for Element<'a>
fn into_element(self, _cx: &'a FrameScope) -> Element<'a>
Source§fn into_any_element(self, cx: &'a FrameScope) -> Element<'a>
fn into_any_element(self, cx: &'a FrameScope) -> Element<'a>
与 GPUI
.into_any_element() 对应的语义别名(零堆分配返回闭合枚举 Element<'a>)。Auto Trait Implementations§
impl<'a> !Freeze for Element<'a>
impl<'a> !RefUnwindSafe for Element<'a>
impl<'a> !Send for Element<'a>
impl<'a> !Sync for Element<'a>
impl<'a> !UnwindSafe for Element<'a>
impl<'a> Forget for Element<'a>
impl<'a> Move for Element<'a>
impl<'a> Unpin for Element<'a>
impl<'a> UnsafeUnpin for Element<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
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
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
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。