add RoutableWidgetState conception
holds the routes for an arbitrary widget Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
df4e331d33
commit
ee0029268f
26
src/routable_widget_state.rs
Normal file
26
src/routable_widget_state.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
#[derive(Default)]
|
||||
pub struct RoutableWidgetState<R: Clone> {
|
||||
routes: Vec<R>,
|
||||
}
|
||||
|
||||
impl<R: Clone> RoutableWidgetState<R> {
|
||||
pub fn route_to(&mut self, route: R) {
|
||||
self.routes.push(route);
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.routes.clear();
|
||||
}
|
||||
|
||||
pub fn go_back(&mut self) {
|
||||
self.routes.pop();
|
||||
}
|
||||
|
||||
pub fn top(&self) -> Option<R> {
|
||||
self.routes.last().cloned()
|
||||
}
|
||||
|
||||
pub fn get_routes(&self) -> Vec<R> {
|
||||
self.routes.clone()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user