pub struct ErrorBoundaryWidget {
pub child: WidgetNode,
pub reset_key: u64,
/* private fields */
}Expand description
错误边界 widget:child 构建时 panic → 显示 fallback(并把错误消息传给 fallback 闭包),同子树之外的 UI 不受影响。
§恢复
一旦进入 fallback 状态,不会自动恢复(error 状态持久,防止每帧重试
panic 的 build 死循环)。想恢复:rebuild 时改 reset_key(did_update_widget
检测到 key 变化 → 清 error → 下一轮 build 重试 child)。
调用方需保证重试时 child 已经不会 panic(例如翻转信号驱动的开关)。
Fields§
§child: WidgetNode§reset_key: u64变化时清除 error 状态、重试 child(恢复机制)
Implementations§
Source§impl ErrorBoundaryWidget
impl ErrorBoundaryWidget
Sourcepub fn new_node(child: WidgetNode) -> Self
pub fn new_node(child: WidgetNode) -> Self
同 ErrorBoundaryWidget::new,但 child 已是 WidgetNode
(嵌套组装树时的常用形态)
Sourcepub fn fallback(self, f: impl Fn(&str) -> WidgetNode + 'static) -> Self
pub fn fallback(self, f: impl Fn(&str) -> WidgetNode + 'static) -> Self
设置 fallback 构造器(收到错误消息)
Sourcepub fn with_reset_key(self, key: u64) -> Self
pub fn with_reset_key(self, key: u64) -> Self
设置 reset_key(下次 update 时 key 变化 → 清 error 重试 child)
Trait Implementations§
Source§impl Debug for ErrorBoundaryWidget
impl Debug for ErrorBoundaryWidget
Source§impl Widget for ErrorBoundaryWidget
impl Widget for ErrorBoundaryWidget
Source§fn is_stateful(&self) -> bool
fn is_stateful(&self) -> bool
是否 stateful(true 则 Element 自动创建 State 并持久化)
Source§fn create_render_object(&self) -> Box<dyn RenderObject>
fn create_render_object(&self) -> Box<dyn RenderObject>
创建 RenderObject(桥接到渲染子系统)
Source§fn children(&self) -> Vec<WidgetNode>
fn children(&self) -> Vec<WidgetNode>
子 widget 列表(Element 树递归用)
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
是否可聚焦(Tab 焦点链 + 键盘激活)
Source§fn captures_tab(&self) -> bool
fn captures_tab(&self) -> bool
是否捕获 Tab 键(编辑器等需要 Tab 缩进的输入组件)。
true 时框架焦点遍历跳过该组件,Tab/BackTab 直接投递给焦点 element。
Source§fn children_with_positions(&self) -> Vec<(Point, WidgetNode)>
fn children_with_positions(&self) -> Vec<(Point, WidgetNode)>
子 widget + 各自在父内的 offset(Stack/Positioned 等需要)
Source§fn handle_event(&self, event: &WidgetEvent, local_pos: Point)
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,
)
fn handle_event_ctx( &self, event: &WidgetEvent, local_pos: Point, _ctx: &mut EventContext, )
带消费语义的事件处理;默认转发
Self::handle_event 并继续冒泡。Source§fn accepts_scroll(&self) -> bool
fn accepts_scroll(&self) -> bool
是否接受滚动事件(ScrollView/ListView 返回 true)
Source§fn gesture_state(&self) -> Option<GestureState>
fn gesture_state(&self) -> Option<GestureState>
手势竞技场仲裁(返回 Some 表示参与指针竞争)
Source§fn semantics(&self) -> Option<WidgetSemantics>
fn semantics(&self) -> Option<WidgetSemantics>
返回无障碍语义(阶段 A11y)
Source§fn as_inherited(&self) -> Option<&dyn InheritedWidget>
fn as_inherited(&self) -> Option<&dyn InheritedWidget>
如果是 InheritedWidget,返回引用(主题/布局约束等传播)
Source§fn can_update(&self, old: &dyn Widget) -> bool
fn can_update(&self, old: &dyn Widget) -> bool
Element diff 时判断新旧 widget 是否“兼容“(类型相同 + key 相同)
默认:type_id 比较
Source§fn is_equivalent(&self, _old: &dyn Widget) -> bool
fn is_equivalent(&self, _old: &dyn Widget) -> bool
P0-1:新旧 widget 的全部输入是否等价(不含 State)。 Read more
Source§fn is_repaint_boundary(&self) -> bool
fn is_repaint_boundary(&self) -> bool
是否 RepaintBoundary(dirty 重绘边界)
Source§fn visible_children(&self) -> Option<Vec<bool>>
fn visible_children(&self) -> Option<Vec<bool>>
逐子节点可见性(按
children() 顺序)。None = 全部可见(默认,零行为变化)。
Some(vec) 与 children() 等长;false 表示该子节点的整棵子树
(含其内部 RepaintBoundary layer)不参与合成。 Read moreSource§fn parent_data(&self) -> Option<ParentData>
fn parent_data(&self) -> Option<ParentData>
父容器在布局阶段读取的子节点元数据(如 Flex 的 grow/basis)。
默认
None(无元数据)。Expanded/Flexible 等 override 返回 ParentData::Flex。Auto Trait Implementations§
impl !RefUnwindSafe for ErrorBoundaryWidget
impl !Send for ErrorBoundaryWidget
impl !Sync for ErrorBoundaryWidget
impl !UnwindSafe for ErrorBoundaryWidget
impl Forget for ErrorBoundaryWidget
impl Freeze for ErrorBoundaryWidget
impl Move for ErrorBoundaryWidget
impl Unpin for ErrorBoundaryWidget
impl UnsafeUnpin for ErrorBoundaryWidget
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