Skip to main content

WidgetNode

Struct WidgetNode 

Source
pub struct WidgetNode(pub Rc<dyn Widget>);
Expand description

Widget 树节点:持有 Rc<dyn Widget>,让 widget 树可被多处共享

WidgetNode 同时实现 Widget trait —— 转发到内部 Widget, 这样可以直接用 child.create_render_object() 等方法

字段 pub 只用于读取内层 widget(node.0.create_render_object() 等); 不要用 WidgetNode(rc) 手工构造嵌套节点。统一走 WidgetNode::new, 它会把重复包壳归一掉。

Tuple Fields§

§0: Rc<dyn Widget>

Implementations§

Source§

impl WidgetNode

Source

pub fn new<W: Widget + 'static>(widget: W) -> Self

构造节点。幂等:传入已存在的 WidgetNode 时直接返回它,不再套第二层壳。

WidgetNode 自身实现 Widget,所以 WidgetNode::new(node) 和 container.push(offset, node) 都能通过类型检查;如果这里不拆壳,就会得到 WidgetNode(WidgetNode(...)),多出一层 element,State/RO/事件链路会出现 难查的偏差。把归一化放在唯一构造入口,调用方不需要记住“不要传 node”。

Source

pub fn as_any(&self) -> &dyn Any

Source

pub fn type_id(&self) -> TypeId

内层 widget 的具体 TypeId。

必须有这个 inherent 方法:否则 node.type_id() 会解析到 Any::type_id(&WidgetNode),对所有 widget 返回同一个 id。

Source

pub fn is<T: 'static>(&self) -> bool

Source

pub fn ptr_eq(&self, other: &WidgetNode) -> bool

两个节点是否同一个 Rc(局部 rebuild 的快速路径)。

Source

pub fn is_equivalent(&self, old: &WidgetNode) -> bool

纯 stateless 子树是否可整体跳过:类型/key 相同 + 两侧均无 state

  • 无动态 Signal + 输入等价。boundary 自身不参与跳过(layer 关系需维护)。

Trait Implementations§

Source§

impl Clone for WidgetNode

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 Debug for WidgetNode

Source§

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

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

impl Widget for WidgetNode

Source§

fn as_any(&self) -> &dyn Any

类型擦除入口(用于 downcast 到具体 widget)。
Source§

fn type_name(&self) -> &'static str

类型名称(调试用,Debug impl 用)
Source§

fn is_stateful(&self) -> bool

是否 stateful(true 则 Element 自动创建 State 并持久化)
Source§

fn is_focusable(&self) -> bool

是否可聚焦(Tab 焦点链 + 键盘激活)
Source§

fn wants_ime(&self) -> bool

是否需要 IME(软键盘 —— TextField/TextBox 等输入组件)
Source§

fn captures_tab(&self) -> bool

是否捕获 Tab 键(编辑器等需要 Tab 缩进的输入组件)。 true 时框架焦点遍历跳过该组件,Tab/BackTab 直接投递给焦点 element。
Source§

fn create_state(&self) -> Option<Box<dyn State>>

创建 State 实例(仅 is_stateful=true 时 Element 会调)
Source§

fn create_render_object(&self) -> Box<dyn RenderObject>

创建 RenderObject(桥接到渲染子系统)
Source§

fn children(&self) -> Vec<WidgetNode>

子 widget 列表(Element 树递归用)
Source§

fn children_with_positions(&self) -> Vec<(Point, WidgetNode)>

子 widget + 各自在父内的 offset(Stack/Positioned 等需要)
Source§

fn handle_event(&self, event: &WidgetEvent, local_pos: Point)

处理事件(不可变 — Widget 是 Rc 共享的;stateful widget 通常把逻辑放在 State 里)
Source§

fn handle_event_ctx( &self, event: &WidgetEvent, local_pos: Point, ctx: &mut EventContext, )

带消费语义的事件处理;默认转发 Self::handle_event 并继续冒泡。
Source§

fn accepts_scroll(&self) -> bool

是否接受滚动事件(ScrollView/ListView 返回 true)
Source§

fn key(&self) -> Option<u64>

唯一标识(用于 ListView 复用 Element)
Source§

fn gesture_state(&self) -> Option<GestureState>

手势竞技场仲裁(返回 Some 表示参与指针竞争)
Source§

fn dynamic_signal(&self) -> Option<Signal<Point>>

返回需要订阅的 Signal(PositionedWidget 用)
Source§

fn semantics(&self) -> Option<WidgetSemantics>

返回无障碍语义(阶段 A11y)
Source§

fn as_inherited(&self) -> Option<&dyn InheritedWidget>

如果是 InheritedWidget,返回引用(主题/布局约束等传播)
Source§

fn can_update(&self, old: &dyn Widget) -> bool

Element diff 时判断新旧 widget 是否“兼容“(类型相同 + key 相同) 默认:type_id 比较
Source§

fn is_equivalent(&self, old: &dyn Widget) -> bool

P0-1:新旧 widget 的全部输入是否等价(不含 State)。 Read more
Source§

fn is_repaint_boundary(&self) -> bool

是否 RepaintBoundary(dirty 重绘边界)
Source§

fn visible_children(&self) -> Option<Vec<bool>>

逐子节点可见性(按 children() 顺序)。None = 全部可见(默认,零行为变化)。 Some(vec) 与 children() 等长;false 表示该子节点的整棵子树 (含其内部 RepaintBoundary layer)不参与合成。 Read more
Source§

fn parent_data(&self) -> Option<ParentData>

父容器在布局阶段读取的子节点元数据(如 Flex 的 grow/basis)。 默认 None(无元数据)。Expanded/Flexible 等 override 返回 ParentData::Flex。

Auto Trait Implementations§

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<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> 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> 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.