push column picker immediately to new column

instead of pushing to temporary column first

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2024-10-01 12:51:14 -04:00
parent ebe4bf3046
commit 57069ff7c0
6 changed files with 80 additions and 46 deletions

View File

@@ -61,6 +61,7 @@ pub struct Router<R: Clone> {
routes: Vec<R>,
pub returning: bool,
pub navigating: bool,
replacing: bool,
}
impl<R: Clone> Router<R> {
@@ -70,10 +71,12 @@ impl<R: Clone> Router<R> {
}
let returning = false;
let navigating = false;
let replacing = false;
Router {
routes,
returning,
navigating,
replacing,
}
}
@@ -82,6 +85,13 @@ impl<R: Clone> Router<R> {
self.routes.push(route);
}
// Route to R. Then when it is successfully placed, should call `remove_previous_route`
pub fn route_to_replaced(&mut self, route: R) {
self.navigating = true;
self.replacing = true;
self.routes.push(route);
}
/// Go back, start the returning process
pub fn go_back(&mut self) -> Option<R> {
if self.returning || self.routes.len() == 1 {
@@ -100,6 +110,20 @@ impl<R: Clone> Router<R> {
self.routes.pop()
}
pub fn remove_previous_route(&mut self) -> Option<R> {
let num_routes = self.routes.len();
if num_routes <= 1 {
return None;
}
self.returning = false;
self.replacing = false;
Some(self.routes.remove(num_routes - 2))
}
pub fn is_replacing(&self) -> bool {
self.replacing
}
pub fn top(&self) -> &R {
self.routes.last().expect("routes can't be empty")
}