mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
cmdsys: handle entered areas
This commit is contained in:
parent
31c1db8a5c
commit
1085826849
4 changed files with 65 additions and 24 deletions
|
|
@ -6,12 +6,15 @@ pub trait FocusGrid {
|
|||
fn cursor (&self) -> (usize, usize);
|
||||
fn cursor_mut (&mut self) -> &mut (usize, usize);
|
||||
fn update_focus (&mut self) {}
|
||||
fn focused (&self) -> &Self::Item {
|
||||
fn focus_enter (&mut self) {}
|
||||
fn focus_exit (&mut self) {}
|
||||
fn entered (&self) -> Option<Self::Item>;
|
||||
fn focused (&self) -> Self::Item {
|
||||
let (x, y) = self.cursor();
|
||||
&self.layout()[y][x]
|
||||
self.layout()[y][x]
|
||||
}
|
||||
fn focus (&mut self, target: Self::Item) {
|
||||
while self.focused() != &target {
|
||||
while self.focused() != target {
|
||||
self.focus_next()
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +53,7 @@ pub trait FocusGrid {
|
|||
self.update_focus();
|
||||
}
|
||||
fn focus_next (&mut self) {
|
||||
let current = *self.focused();
|
||||
let current = self.focused();
|
||||
let (x, y) = self.cursor();
|
||||
if x < self.layout()[y].len().saturating_sub(1) {
|
||||
self.focus_right();
|
||||
|
|
@ -58,13 +61,13 @@ pub trait FocusGrid {
|
|||
self.focus_down();
|
||||
self.cursor_mut().0 = 0;
|
||||
}
|
||||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
if self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_next()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_prev (&mut self) {
|
||||
let current = *self.focused();
|
||||
let current = self.focused();
|
||||
let (x, _) = self.cursor();
|
||||
if x > 0 {
|
||||
self.focus_left();
|
||||
|
|
@ -74,13 +77,11 @@ pub trait FocusGrid {
|
|||
let next_x = self.layout()[y].len().saturating_sub(1);
|
||||
self.cursor_mut().0 = next_x;
|
||||
}
|
||||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
if self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_prev()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_enter (&mut self) {}
|
||||
fn focus_exit (&mut self) {}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue