mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
tab/backtab focus works pretty ok
This commit is contained in:
parent
cd9244ec88
commit
9f15f8fff9
3 changed files with 33 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub trait FocusGrid<T> {
|
pub trait FocusGrid<T: Copy + PartialEq> {
|
||||||
fn layout (&self) -> &[&[T]];
|
fn layout (&self) -> &[&[T]];
|
||||||
fn cursor (&self) -> (usize, usize);
|
fn cursor (&self) -> (usize, usize);
|
||||||
fn cursor_mut (&mut self) -> &mut (usize, usize);
|
fn cursor_mut (&mut self) -> &mut (usize, usize);
|
||||||
|
|
@ -39,6 +39,7 @@ pub trait FocusGrid<T> {
|
||||||
*self.cursor_mut() = (next_x, y);
|
*self.cursor_mut() = (next_x, y);
|
||||||
}
|
}
|
||||||
fn focus_next (&mut self) {
|
fn focus_next (&mut self) {
|
||||||
|
let current = *self.focused();
|
||||||
let (x, y) = self.cursor();
|
let (x, y) = self.cursor();
|
||||||
if x < self.layout()[y].len().saturating_sub(1) {
|
if x < self.layout()[y].len().saturating_sub(1) {
|
||||||
self.focus_right();
|
self.focus_right();
|
||||||
|
|
@ -46,8 +47,12 @@ pub trait FocusGrid<T> {
|
||||||
self.focus_down();
|
self.focus_down();
|
||||||
self.cursor_mut().0 = 0;
|
self.cursor_mut().0 = 0;
|
||||||
}
|
}
|
||||||
|
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||||
|
self.focus_next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn focus_prev (&mut self) {
|
fn focus_prev (&mut self) {
|
||||||
|
let current = *self.focused();
|
||||||
let (x, _) = self.cursor();
|
let (x, _) = self.cursor();
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
self.focus_left();
|
self.focus_left();
|
||||||
|
|
@ -57,6 +62,9 @@ pub trait FocusGrid<T> {
|
||||||
let next_x = self.layout()[y].len().saturating_sub(1);
|
let next_x = self.layout()[y].len().saturating_sub(1);
|
||||||
self.cursor_mut().0 = next_x;
|
self.cursor_mut().0 = next_x;
|
||||||
}
|
}
|
||||||
|
if *self.focused() == current { // FIXME: prevent infinite loop
|
||||||
|
self.focus_prev()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,15 @@ impl Content for Arranger<Tui> {
|
||||||
/// Handle top-level events in standalone arranger.
|
/// Handle top-level events in standalone arranger.
|
||||||
impl Handle<Tui> for Arranger<Tui> {
|
impl Handle<Tui> for Arranger<Tui> {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
let update_focus = |arranger: &mut Self| {
|
||||||
|
let focused = *arranger.focused();
|
||||||
|
arranger.transport.as_ref().map(|transport|{
|
||||||
|
transport.write().unwrap().focused = focused == ArrangerFocus::Transport
|
||||||
|
});
|
||||||
|
arranger.arrangement.focused = focused == ArrangerFocus::Arrangement;
|
||||||
|
arranger.phrases.write().unwrap().focused = focused == ArrangerFocus::PhrasePool;
|
||||||
|
arranger.editor.focused = focused == ArrangerFocus::PhraseEditor;
|
||||||
|
};
|
||||||
if !match self.focused() {
|
if !match self.focused() {
|
||||||
ArrangerFocus::Transport => self.transport.handle(from)?,
|
ArrangerFocus::Transport => self.transport.handle(from)?,
|
||||||
ArrangerFocus::Arrangement => self.arrangement.handle(from)?,
|
ArrangerFocus::Arrangement => self.arrangement.handle(from)?,
|
||||||
|
|
@ -36,15 +45,15 @@ impl Handle<Tui> for Arranger<Tui> {
|
||||||
}.unwrap_or(false) {
|
}.unwrap_or(false) {
|
||||||
match from.event() {
|
match from.event() {
|
||||||
// Tab navigation
|
// Tab navigation
|
||||||
key!(KeyCode::Tab) => { self.focus_next(); },
|
key!(KeyCode::Tab) => { self.focus_next(); update_focus(self); },
|
||||||
key!(Shift-KeyCode::Tab) => { self.focus_prev(); },
|
key!(Shift-KeyCode::Tab) => { self.focus_prev(); update_focus(self); },
|
||||||
key!(KeyCode::BackTab) => { self.focus_prev(); },
|
key!(KeyCode::BackTab) => { self.focus_prev(); update_focus(self); },
|
||||||
key!(Shift-KeyCode::BackTab) => { self.focus_prev(); },
|
key!(Shift-KeyCode::BackTab) => { self.focus_prev(); update_focus(self); },
|
||||||
// Directional navigation
|
// Directional navigation
|
||||||
key!(KeyCode::Up) => { self.focus_up(); },
|
key!(KeyCode::Up) => { self.focus_up(); update_focus(self); },
|
||||||
key!(KeyCode::Down) => { self.focus_down(); },
|
key!(KeyCode::Down) => { self.focus_down(); update_focus(self); },
|
||||||
key!(KeyCode::Left) => { self.focus_left(); },
|
key!(KeyCode::Left) => { self.focus_left(); update_focus(self); },
|
||||||
key!(KeyCode::Right) => { self.focus_right(); },
|
key!(KeyCode::Right) => { self.focus_right(); update_focus(self); },
|
||||||
// Global play/pause binding
|
// Global play/pause binding
|
||||||
key!(KeyCode::Char(' ')) => match self.transport {
|
key!(KeyCode::Char(' ')) => match self.transport {
|
||||||
Some(ref mut transport) => { transport.write().unwrap().toggle_play()?; },
|
Some(ref mut transport) => { transport.write().unwrap().toggle_play()?; },
|
||||||
|
|
@ -562,19 +571,13 @@ impl Handle<Tui> for ArrangerRenameModal<Tui> {
|
||||||
match from.event() {
|
match from.event() {
|
||||||
TuiEvent::Input(Event::Key(k)) => {
|
TuiEvent::Input(Event::Key(k)) => {
|
||||||
match k.code {
|
match k.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => { self.exit(); },
|
||||||
self.exit();
|
|
||||||
},
|
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
*self.result.write().unwrap() = self.value.clone();
|
*self.result.write().unwrap() = self.value.clone();
|
||||||
self.exit();
|
self.exit();
|
||||||
},
|
},
|
||||||
KeyCode::Left => {
|
KeyCode::Left => { self.cursor = self.cursor.saturating_sub(1); },
|
||||||
self.cursor = self.cursor.saturating_sub(1);
|
KeyCode::Right => { self.cursor = self.value.len().min(self.cursor + 1) },
|
||||||
},
|
|
||||||
KeyCode::Right => {
|
|
||||||
self.cursor = self.value.len().min(self.cursor + 1)
|
|
||||||
},
|
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
let last = self.value.len().saturating_sub(1);
|
let last = self.value.len().saturating_sub(1);
|
||||||
self.value = format!("{}{}",
|
self.value = format!("{}{}",
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ impl Handle<Tui> for TransportToolbar<Tui> {
|
||||||
key!(KeyCode::Left) => { self.focus.prev(); },
|
key!(KeyCode::Left) => { self.focus.prev(); },
|
||||||
key!(KeyCode::Right) => { self.focus.next(); },
|
key!(KeyCode::Right) => { self.focus.next(); },
|
||||||
_ => match self.focus {
|
_ => match self.focus {
|
||||||
TransportToolbarFocus::PlayPause => self.toggle_play().map(|_|())?,
|
TransportToolbarFocus::PlayPause => match from.event() {
|
||||||
|
key!(KeyCode::Enter) => self.toggle_play().map(|_|())?,
|
||||||
|
_ => return Ok(None)
|
||||||
|
},
|
||||||
TransportToolbarFocus::Bpm => self.handle_bpm(from).map(|_|())?,
|
TransportToolbarFocus::Bpm => self.handle_bpm(from).map(|_|())?,
|
||||||
TransportToolbarFocus::Quant => self.handle_quant(from).map(|_|())?,
|
TransportToolbarFocus::Quant => self.handle_quant(from).map(|_|())?,
|
||||||
TransportToolbarFocus::Sync => self.handle_sync(from).map(|_|())?,
|
TransportToolbarFocus::Sync => self.handle_sync(from).map(|_|())?,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue