pub trait View: 'static + Sized {
// Required methods
fn entity_id(&self) -> Option<EntityId>;
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement;
}Expand description
重导出视图系统类型
参与 RGPUI 响应式图的可渲染物 — 这是 Render 和 RenderOnce 背后的统一模型。
当 entity_id() 返回 Some 时,该 id 成为视图的标识:它获得一个唯一的
元素 id 空间(因此内部的 use_state / .id(..) 不会在兄弟节点间冲突),
并且在该实体上执行 cx.notify() 只会重新渲染此视图的子树。
None 的行为类似无状态组件。
很少直接实现 View。Entity<T: Render> 和任何 T: RenderOnce
在下面有泛型实现;仅当组件同时需要父级提供的属性和用于标识的支撑实体时
才需要手动实现。
Required Methods§
Sourcefn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
将此视图渲染为元素树,消耗 self。
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".