mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16: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
|
|
@ -10,59 +10,33 @@ impl Content for Sequencer<Tui> {
|
|||
})
|
||||
}
|
||||
}
|
||||
/// Focusable items in standalone arranger.
|
||||
impl Focus<3, Tui> for Sequencer<Tui> {
|
||||
fn focus (&self) -> usize {
|
||||
self.focus
|
||||
}
|
||||
fn focus_mut (&mut self) -> &mut usize {
|
||||
&mut self.focus
|
||||
}
|
||||
fn focusable (&self) -> [&dyn Focusable<Tui>;3] {
|
||||
focusables!(self.transport, self.phrases, self.editor)
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
|
||||
focusables_mut!(self.transport, self.phrases, self.editor)
|
||||
}
|
||||
}
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Sequencer<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let focus = self.focus;
|
||||
let is_first_row = false;
|
||||
let is_last_row = false;
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(' ')) => {
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
transport.write().unwrap().toggle_play()?;
|
||||
} else {
|
||||
return Ok(None)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Tab) => {
|
||||
self.focus_next();
|
||||
},
|
||||
key!(KeyCode::BackTab) => {
|
||||
self.focus_prev();
|
||||
},
|
||||
key!(KeyCode::Down) => {
|
||||
if focus == 0 {
|
||||
self.focus_next();
|
||||
} else if focus == 1 && is_last_row {
|
||||
self.focus_next();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Up) => {
|
||||
if focus == 1 && is_first_row {
|
||||
self.focus_prev();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
_ => return self.focused_mut().handle(from)
|
||||
}
|
||||
if !match self.focused() {
|
||||
SequencerFocus::Transport => self.transport.handle(from)?,
|
||||
SequencerFocus::PhrasePool => self.phrases.handle(from)?,
|
||||
SequencerFocus::PhraseEditor => self.editor.handle(from)?
|
||||
}.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(); },
|
||||
// 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(); },
|
||||
// Global play/pause binding
|
||||
key!(KeyCode::Char(' ')) => match self.transport {
|
||||
Some(ref mut transport) => { transport.write().unwrap().toggle_play()?; },
|
||||
None => { return Ok(None) }
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
|
@ -81,14 +55,6 @@ impl Content for PhrasePool<Tui> {
|
|||
.fg(Color::Rgb(70, 80, 50))))
|
||||
}
|
||||
}
|
||||
impl Focusable<Tui> for PhrasePool<Tui> {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
fn set_focused (&mut self, focused: bool) {
|
||||
self.focused = focused
|
||||
}
|
||||
}
|
||||
impl Handle<Tui> for PhrasePool<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
|
|
@ -225,14 +191,6 @@ impl Handle<Tui> for PhraseEditor<Tui> {
|
|||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl Focusable<Tui> for PhraseEditor<Tui> {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
fn set_focused (&mut self, focused: bool) {
|
||||
self.focused = focused
|
||||
}
|
||||
}
|
||||
impl PhraseEditor<Tui> {
|
||||
const H_KEYS_OFFSET: usize = 5;
|
||||
/// Select which pattern to display. This pre-renders it to the buffer at full resolution.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue