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§
Sourcetype RequestLayoutState: 'static
type RequestLayoutState: 'static
Element::request_layout 返回的状态类型。其可变引用随后传递给
Element::prepaint 和 Element::paint。
Sourcetype PrepaintState: 'static
type PrepaintState: 'static
Element::prepaint 返回的状态类型。其可变引用随后传递给 Element::paint。
Required Methods§
Sourcefn id(&self) -> Option<ElementId>
fn id(&self) -> Option<ElementId>
如果此元素有唯一标识符,返回它。用于跨帧追踪元素, 并将 GlobalElementId 传递给 request_layout、prepaint 和 paint 方法。
全局 id 可用于访问跨帧相同 id 元素关联的状态。 该 id 在第一个拥有 id 的父元素的子元素中必须唯一。
Sourcefn source_location(&self) -> Option<&'static Location<'static>>
fn source_location(&self) -> Option<&'static Location<'static>>
此元素的构造源位置,用于在检查器中区分元素并导航到其源码。
Sourcefn request_layout(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState)
fn request_layout( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)
绘制元素前,需要确定其位置和大小。 使用此方法向 Taffy 请求布局并初始化元素状态。
Sourcefn 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 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() 返回的状态。
Sourcefn 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,
)
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§
Sourcefn write_a11y_info(&self, _node: &mut Node)
fn write_a11y_info(&self, _node: &mut Node)
将无障碍属性写入给定节点。
仅在 a11y_role() 返回 Some 时调用。
概览见无障碍指南。
Sourcefn a11y_synthetic_children(
&mut self,
_prepaint: &mut Self::PrepaintState,
_builder: &mut A11ySubtreeBuilder<'_>,
)
fn a11y_synthetic_children( &mut self, _prepaint: &mut Self::PrepaintState, _builder: &mut A11ySubtreeBuilder<'_>, )
Sourcefn into_any(self) -> AnyElement
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".