use crate::widget::state; use crate::widget::Id; pub trait Operation { fn container( &mut self, id: Option<&Id>, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ); fn focusable( &mut self, _state: &mut dyn state::Focusable, _id: Option<&Id>, ) { } fn finish(&self) -> Outcome { Outcome::None } } pub enum Outcome { None, Some(T), Chain(Box>), } pub fn focus(target: Id) -> impl Operation { struct Focus { target: Id, } impl Operation for Focus { fn focusable( &mut self, state: &mut dyn state::Focusable, id: Option<&Id>, ) { match id { Some(id) if id == &self.target => { state.focus(); } _ => { state.unfocus(); } } } fn container( &mut self, _id: Option<&Id>, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { operate_on_children(self) } } Focus { target } }