pub trait Component {
Show 14 methods
// Required method
fn render(&self, cx: &mut RenderCx<'_>);
// Provided methods
fn event(&mut self, _event: &Event, _cx: &mut EventCx<'_>) { ... }
fn style(&self) -> Style { ... }
fn measure(&self, constraint: Constraint, _cx: &mut MeasureCx) -> Size { ... }
fn layout(&mut self, _rect: Rect, _cx: &mut LayoutCx<'_>) { ... }
fn mount(&mut self, _cx: &mut EventCx<'_>) { ... }
fn unmount(&mut self, _cx: &mut EventCx<'_>) { ... }
fn update(&mut self, _cx: &mut EventCx<'_>) { ... }
fn type_name(&self) -> &str { ... }
fn id(&self) -> Option<&str> { ... }
fn class(&self) -> Option<&str> { ... }
fn focusable(&self) -> bool { ... }
fn for_each_child(&self, _f: &mut dyn FnMut(&Node)) { ... }
fn for_each_child_mut(&mut self, _f: &mut dyn FnMut(&mut Node)) { ... }
}Expand description
组件 trait——应用的基本组织单元
Required Methods§
Provided Methods§
Sourcefn measure(&self, constraint: Constraint, _cx: &mut MeasureCx) -> Size
fn measure(&self, constraint: Constraint, _cx: &mut MeasureCx) -> Size
测量组件在给定约束下的自适应尺寸
默认实现:单行高度,宽度填满可用空间。
Sourcefn layout(&mut self, _rect: Rect, _cx: &mut LayoutCx<'_>)
fn layout(&mut self, _rect: Rect, _cx: &mut LayoutCx<'_>)
布局回调——组件在此计算子节点 rect 并调用 child.layout()
默认实现:无子节点,不执行任何操作。
Sourcefn for_each_child(&self, _f: &mut dyn FnMut(&Node))
fn for_each_child(&self, _f: &mut dyn FnMut(&Node))
遍历子节点(为焦点系统等提供统一的树遍历接口)
Sourcefn for_each_child_mut(&mut self, _f: &mut dyn FnMut(&mut Node))
fn for_each_child_mut(&mut self, _f: &mut dyn FnMut(&mut Node))
遍历子节点(可变版本)