1pub struct WidgetRefInner {
2 pub widget: Box<dyn Widget>,
3}
4
5pub struct WidgetRef(Rc<RefCell<Option<WidgetRefInner>>>);
6
7// 关键方法
8impl WidgetRef {
9 // 其他方法
10 // 事件处理
11 pub fn handle_event(&self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
12 // ...
13
14 }
15
16 // 绘制
17 pub fn draw(&mut self, cx: &mut Cx2d, scope: &mut Scope) -> DrawStep {
18 // ...
19 }
20
21 // 获取底层Widget的可变引用
22 pub fn borrow_mut<T: 'static + Widget>(&self) -> Option<RefMut<'_, T>> {
23 // ...
24 }
25
26 // 基础查找方法
27 pub fn find_widgets(&self, path: &[LiveId], cached: WidgetCache, results: &mut WidgetSet) {
28 if let Some(inner) = self.0.borrow().as_ref() {
29 inner.widget.find_widgets(path, cached, results)
30 }
31 }
32}