mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
implement sequencer focus; auto update_focus
This commit is contained in:
parent
9f15f8fff9
commit
3bf475d15e
8 changed files with 119 additions and 160 deletions
|
|
@ -4,6 +4,7 @@ pub trait FocusGrid<T: Copy + PartialEq> {
|
|||
fn layout (&self) -> &[&[T]];
|
||||
fn cursor (&self) -> (usize, usize);
|
||||
fn cursor_mut (&mut self) -> &mut (usize, usize);
|
||||
fn update_focus (&mut self) {}
|
||||
fn focused (&self) -> &T {
|
||||
let (x, y) = self.cursor();
|
||||
&self.layout()[y][x]
|
||||
|
|
@ -16,6 +17,7 @@ pub trait FocusGrid<T: Copy + PartialEq> {
|
|||
((x as f32 / layout[y].len() as f32) * layout[next_y].len() as f32) as usize
|
||||
};
|
||||
*self.cursor_mut() = (next_x, next_y);
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_down (&mut self) {
|
||||
let layout = self.layout();
|
||||
|
|
@ -25,18 +27,21 @@ pub trait FocusGrid<T: Copy + PartialEq> {
|
|||
((x as f32 / layout[y].len() as f32) * layout[next_y].len() as f32) as usize
|
||||
};
|
||||
*self.cursor_mut() = (next_x, next_y);
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_left (&mut self) {
|
||||
let layout = self.layout();
|
||||
let (x, y) = self.cursor();
|
||||
let next_x = if x == 0 { layout[y].len().saturating_sub(1) } else { x - 1 };
|
||||
*self.cursor_mut() = (next_x, y);
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_right (&mut self) {
|
||||
let layout = self.layout();
|
||||
let (x, y) = self.cursor();
|
||||
let next_x = if x >= layout[y].len().saturating_sub(1) { 0 } else { x + 1 };
|
||||
*self.cursor_mut() = (next_x, y);
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_next (&mut self) {
|
||||
let current = *self.focused();
|
||||
|
|
@ -50,6 +55,7 @@ pub trait FocusGrid<T: Copy + PartialEq> {
|
|||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_next()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
fn focus_prev (&mut self) {
|
||||
let current = *self.focused();
|
||||
|
|
@ -65,6 +71,7 @@ pub trait FocusGrid<T: Copy + PartialEq> {
|
|||
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||
self.focus_prev()
|
||||
}
|
||||
self.update_focus();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue