ScreensView: dispatch call_on_any and focus_view to all screens

This commit is contained in:
Alexandre Bury 2020-08-23 10:17:56 -07:00
parent 69feb373e6
commit ad935f5126

View File

@ -1,3 +1,5 @@
use crate::event::AnyCb;
use crate::view::Selector;
use crate::views::BoxedView; use crate::views::BoxedView;
use crate::View; use crate::View;
@ -117,5 +119,24 @@ where
self.screen_mut().map(f) self.screen_mut().map(f)
} }
// TODO: Should `focus_view` work cross-screens? Should `call_on_id`? Answer: yes. fn wrap_call_on_any<'a>(
&mut self,
selector: &Selector<'_>,
callback: AnyCb<'a>,
) {
for screen in &mut self.screens {
screen.call_on_any(selector, callback);
}
}
fn wrap_focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
for (i, child) in self.screens.iter_mut().enumerate() {
if child.focus_view(selector).is_ok() {
self.active_screen = i;
return Ok(());
}
}
Err(())
}
} }