add RoutableWidgetState conception

holds the routes for an arbitrary widget

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-09-06 18:31:50 -04:00
committed by William Casarin
parent df4e331d33
commit ee0029268f
4 changed files with 49 additions and 18 deletions

View 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()
}
}