mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +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
|
|
@ -28,6 +28,15 @@ impl Content for Arranger<Tui> {
|
|||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Arranger<Tui> {
|
||||
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() {
|
||||
ArrangerFocus::Transport => self.transport.handle(from)?,
|
||||
ArrangerFocus::Arrangement => self.arrangement.handle(from)?,
|
||||
|
|
@ -36,15 +45,15 @@ impl Handle<Tui> for Arranger<Tui> {
|
|||
}.unwrap_or(false) {
|
||||
match from.event() {
|
||||
// Tab navigation
|
||||
key!(KeyCode::Tab) => { self.focus_next(); },
|
||||
key!(Shift-KeyCode::Tab) => { self.focus_prev(); },
|
||||
key!(KeyCode::BackTab) => { self.focus_prev(); },
|
||||
key!(Shift-KeyCode::BackTab) => { self.focus_prev(); },
|
||||
key!(KeyCode::Tab) => { self.focus_next(); update_focus(self); },
|
||||
key!(Shift-KeyCode::Tab) => { self.focus_prev(); update_focus(self); },
|
||||
key!(KeyCode::BackTab) => { self.focus_prev(); update_focus(self); },
|
||||
key!(Shift-KeyCode::BackTab) => { self.focus_prev(); update_focus(self); },
|
||||
// Directional navigation
|
||||
key!(KeyCode::Up) => { self.focus_up(); },
|
||||
key!(KeyCode::Down) => { self.focus_down(); },
|
||||
key!(KeyCode::Left) => { self.focus_left(); },
|
||||
key!(KeyCode::Right) => { self.focus_right(); },
|
||||
key!(KeyCode::Up) => { self.focus_up(); update_focus(self); },
|
||||
key!(KeyCode::Down) => { self.focus_down(); update_focus(self); },
|
||||
key!(KeyCode::Left) => { self.focus_left(); update_focus(self); },
|
||||
key!(KeyCode::Right) => { self.focus_right(); update_focus(self); },
|
||||
// Global play/pause binding
|
||||
key!(KeyCode::Char(' ')) => match self.transport {
|
||||
Some(ref mut transport) => { transport.write().unwrap().toggle_play()?; },
|
||||
|
|
@ -562,19 +571,13 @@ impl Handle<Tui> for ArrangerRenameModal<Tui> {
|
|||
match from.event() {
|
||||
TuiEvent::Input(Event::Key(k)) => {
|
||||
match k.code {
|
||||
KeyCode::Esc => {
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Esc => { self.exit(); },
|
||||
KeyCode::Enter => {
|
||||
*self.result.write().unwrap() = self.value.clone();
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Left => {
|
||||
self.cursor = self.cursor.saturating_sub(1);
|
||||
},
|
||||
KeyCode::Right => {
|
||||
self.cursor = self.value.len().min(self.cursor + 1)
|
||||
},
|
||||
KeyCode::Left => { self.cursor = self.cursor.saturating_sub(1); },
|
||||
KeyCode::Right => { self.cursor = self.value.len().min(self.cursor + 1) },
|
||||
KeyCode::Backspace => {
|
||||
let last = self.value.len().saturating_sub(1);
|
||||
self.value = format!("{}{}",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,10 @@ impl Handle<Tui> for TransportToolbar<Tui> {
|
|||
key!(KeyCode::Left) => { self.focus.prev(); },
|
||||
key!(KeyCode::Right) => { self.focus.next(); },
|
||||
_ => 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::Quant => self.handle_quant(from).map(|_|())?,
|
||||
TransportToolbarFocus::Sync => self.handle_sync(from).map(|_|())?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue