-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, and thanks for the question! First, you may be interested in the Second, the double-borrow happens because you call You borrow it to prepare a string. Since the string itself doesn't borrow the view, you could first build the string while borrowing the view, then only keep the string, and use it to set the content: fn wrap_on_event(&mut self, ch: Event) -> EventResult {
let output = self.with_view_mut(|view| view.on_event(ch));
self.view.with_view_mut(|view| {
let focused_index = view.get_focus_index();
// First build the content string
let content = view
.get_child(focused_index)
.and_then(|view| view.downcast_ref::<NamedView<EditView>>())
.map(|x| {
let name = x.name();
let value = x.with_view(|x| x.get_content()).unwrap();
format!("On {name}: {value}")
});
// Now `view` is no longer borrowed, so we can use it again to find the child to edit.
if let Some(content) = content {
view.call_on_name("inputs_layout", |v: &mut TextView| {
v.set_content(content);
})
.unwrap();
}
});
output.unwrap()
} |
Beta Was this translation helpful? Give feedback.
Hi, and thanks for the question!
First, you may be interested in the
FocusTracker
wrapper, which may help set callbacks for focus events.Second, the double-borrow happens because you call
find_name
onself.view
(theNamedView
) while you're borrowing the layout. But you could directly callfind_name
on the layout instead. For that you do need theview
to be un-borrowed.You borrow it to prepare a string. Since the string itself doesn't borrow the view, you could first build the string while borrowing the view, then only keep the string, and use it to set the content: