add SingletonRouter

used for popup

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-05-22 18:51:10 -04:00
parent 99aa50c120
commit 08a720b860

View File

@@ -361,3 +361,40 @@ impl fmt::Display for Route {
}
}
}
#[derive(Clone, Debug)]
pub struct SingletonRouter<R: Clone> {
route: Option<R>,
pub returning: bool,
pub navigating: bool,
}
impl<R: Clone> SingletonRouter<R> {
pub fn route_to(&mut self, route: R) {
self.navigating = true;
self.route = Some(route);
}
pub fn go_back(&mut self) {
self.returning = true;
}
pub fn clear(&mut self) {
self.route = None;
self.returning = false;
}
pub fn route(&self) -> &Option<R> {
&self.route
}
}
impl<R: Clone> Default for SingletonRouter<R> {
fn default() -> Self {
Self {
route: None,
returning: false,
navigating: false,
}
}
}