2022-06-19 23:13:21 +02:00
|
|
|
use {
|
|
|
|
crate::list::ListCursorMode,
|
2022-11-13 15:26:25 +01:00
|
|
|
crate::tree::TreeCursor,
|
2022-06-19 23:13:21 +02:00
|
|
|
cgmath::Vector2
|
|
|
|
};
|
2021-08-23 05:00:57 +02:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
2021-08-15 04:27:09 +02:00
|
|
|
pub enum TreeNavResult {
|
|
|
|
Continue,
|
2021-11-19 12:19:52 +01:00
|
|
|
Exit,
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
|
2021-08-26 08:20:51 +02:00
|
|
|
/*
|
|
|
|
impl From<TreeNavResult> for TerminalEditorResult {
|
|
|
|
fn from(v: TreeNavResult) -> TerminalEditorResult {
|
|
|
|
match v {
|
|
|
|
TreeNavResult::Continue => TerminalEditorResult::Continue,
|
|
|
|
TreeNavResult::Exit => TerminalEditorResult::Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
*/
|
|
|
|
|
2021-08-15 04:27:09 +02:00
|
|
|
pub trait TreeNav {
|
2022-06-19 23:13:21 +02:00
|
|
|
/* CORE
|
|
|
|
*/
|
|
|
|
fn get_cursor(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn get_cursor_warp(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 15:26:25 +01:00
|
|
|
fn get_max_depth(&self) -> usize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2022-12-18 01:39:01 +01:00
|
|
|
fn goby(&mut self, _direction: Vector2<isize>) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn goto(&mut self, _new_cursor: TreeCursor) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
/* HULL
|
|
|
|
*/
|
|
|
|
fn set_addr(&mut self, addr: isize) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.tree_addr[0] = addr;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn set_leaf_mode(&mut self, new_leaf_mode: ListCursorMode) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.leaf_mode = new_leaf_mode;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn up(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, -1))
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn dn(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pxev(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(-1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nexd(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
fn qpxev(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
self.goto(TreeCursor::home())
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != 0 {
|
|
|
|
c.tree_addr[depth-1] = 0;
|
|
|
|
} else {
|
|
|
|
for i in (0..depth-1).rev() {
|
|
|
|
if c.tree_addr[i] == 0 {
|
|
|
|
c.tree_addr[i] = -1;
|
|
|
|
} else {
|
|
|
|
c.tree_addr[i] -=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn qnexd(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor_warp();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
TreeNavResult::Exit
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != -1 {
|
|
|
|
c.tree_addr[depth-1] = -1;
|
|
|
|
} else {
|
|
|
|
for i in (0..depth-1).rev() {
|
|
|
|
if c.tree_addr[i] == -1 {
|
|
|
|
c.tree_addr[i] = 0;
|
|
|
|
} else {
|
|
|
|
c.tree_addr[i] += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
}
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|