Skip to main content

Element

Trait Element 

Source
pub trait Element: 'static + IntoElement {
    type RequestLayoutState: 'static;
    type PrepaintState: 'static;

    // Required methods
    fn id(&self) -> Option<ElementId>;
    fn source_location(&self) -> Option<&'static Location<'static>>;
    fn request_layout(
        &mut self,
        id: Option<&GlobalElementId>,
        inspector_id: Option<&InspectorElementId>,
        window: &mut Window,
        cx: &mut App,
    ) -> (LayoutId, Self::RequestLayoutState);
    fn prepaint(
        &mut self,
        id: Option<&GlobalElementId>,
        inspector_id: Option<&InspectorElementId>,
        bounds: Bounds<Pixels>,
        request_layout: &mut Self::RequestLayoutState,
        window: &mut Window,
        cx: &mut App,
    ) -> Self::PrepaintState;
    fn paint(
        &mut self,
        id: Option<&GlobalElementId>,
        inspector_id: Option<&InspectorElementId>,
        bounds: Bounds<Pixels>,
        request_layout: &mut Self::RequestLayoutState,
        prepaint: &mut Self::PrepaintState,
        window: &mut Window,
        cx: &mut App,
    );

    // Provided methods
    fn a11y_role(&self) -> Option<Role> { ... }
    fn write_a11y_info(&self, _node: &mut Node) { ... }
    fn a11y_synthetic_children(
        &mut self,
        _prepaint: &mut Self::PrepaintState,
        _builder: &mut A11ySubtreeBuilder<'_>,
    ) { ... }
    fn into_any(self) -> AnyElement { ... }
}
Expand description

重导出元素系统核心类型 参与窗口内容布局和绘制的类型需实现此特征。 元素形成一棵树,按照 Taffy 实现的 Web 布局规则进行布局。 可通过实现此特征创建自定义元素,详见模块文档。

Required Associated Types§

Source

type RequestLayoutState: 'static

Element::request_layout 返回的状态类型。其可变引用随后传递给 Element::prepaint 和 Element::paint。

Source

type PrepaintState: 'static

Element::prepaint 返回的状态类型。其可变引用随后传递给 Element::paint。

Required Methods§

Source

fn id(&self) -> Option<ElementId>

如果此元素有唯一标识符,返回它。用于跨帧追踪元素, 并将 GlobalElementId 传递给 request_layout、prepaint 和 paint 方法。

全局 id 可用于访问跨帧相同 id 元素关联的状态。 该 id 在第一个拥有 id 的父元素的子元素中必须唯一。

Source

fn source_location(&self) -> Option<&'static Location<'static>>

此元素的构造源位置,用于在检查器中区分元素并导航到其源码。

Source

fn request_layout( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)

绘制元素前,需要确定其位置和大小。 使用此方法向 Taffy 请求布局并初始化元素状态。

Source

fn prepaint( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut Self::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> Self::PrepaintState

布局完成后,需将其边界提交到当前帧用于命中检测。 state 参数即 Element::request_layout() 返回的状态。

Source

fn paint( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut Self::RequestLayoutState, prepaint: &mut Self::PrepaintState, window: &mut Window, cx: &mut App, )

布局完成后,调用此方法将元素绘制到屏幕。 state 参数即 Element::request_layout() 返回的状态。

Provided Methods§

Source

fn a11y_role(&self) -> Option<Role>

返回此元素的无障碍角色,若无则返回 None。 返回 None 的元素不会包含在无障碍树中。

注意:加入无障碍树需要 id 返回非 None。

概览见无障碍指南。

Source

fn write_a11y_info(&self, _node: &mut Node)

将无障碍属性写入给定节点。 仅在 a11y_role() 返回 Some 时调用。

概览见无障碍指南。

Source

fn a11y_synthetic_children( &mut self, _prepaint: &mut Self::PrepaintState, _builder: &mut A11ySubtreeBuilder<'_>, )

为拥有 .id() 和 .role() 的 Element 添加合成子节点。

某些元素需要注入不对应任何 RGPUI 元素的无障碍节点。 例如自定义文本框元素可能为文本内容注入合成子节点。

详见无障碍指南中的合成子节点。

Source

fn into_any(self) -> AnyElement

将此元素转换为动态类型的 AnyElement。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Element for &'static str

Source§

type RequestLayoutState = TextLayout

Source§

type PrepaintState = ()

Source§

fn id(&self) -> Option<ElementId>

Source§

fn source_location(&self) -> Option<&'static Location<'static>>

Source§

fn request_layout( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)

Source§

fn prepaint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, text_layout: &mut Self::RequestLayoutState, _window: &mut Window, _cx: &mut App, )

Source§

fn paint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, _bounds: Bounds<Pixels>, text_layout: &mut TextLayout, _: &mut (), window: &mut Window, cx: &mut App, )

Implementors§

Source§

impl Element for Anchored

Source§

impl Element for AnyElement

Source§

impl Element for ContainerQuery

Source§

impl Element for Deferred

Source§

impl Element for Div

Source§

impl Element for Empty

Source§

impl Element for ImageCacheElement

Source§

impl Element for Img

Source§

impl Element for InteractiveText

Source§

impl Element for List

Source§

impl Element for ScrollableMask

Source§

impl Element for Scrollbar

Source§

impl Element for SharedString

Source§

impl Element for StyledText

Source§

impl Element for Surface

Source§

impl Element for Svg

Source§

impl Element for Text

Source§

impl Element for UniformList

Source§

impl Element for VirtualList

Source§

impl<E: InteractiveElement + ParentElement + Styled + Element + 'static> Element for FocusTrapContainer<E>

Source§

impl<E: IntoElement + 'static> Element for AnimationElement<E>

Source§

impl<E: ParentElement + Styled + IntoElement + 'static> Element for ContextMenu<E>

Source§

impl<E> Element for Stateful<E>
where E: Element,

Source§

impl<T: 'static> Element for Canvas<T>