add SingletonRouter
used for popup Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user