add Arranger::is_first_row/is_last_row for arrow focus

This commit is contained in:
🪞👃🪞 2024-09-01 22:22:49 +03:00
parent a4bd99c117
commit 7bd2a70e85
6 changed files with 81 additions and 27 deletions

View file

@ -44,7 +44,7 @@ impl ArrangerStandalone {
pub fn from_args () -> Usually<Self> {
let args = ArrangerCli::parse();
let mut arranger = Arranger::new("");
let transport = match args.transport {
let mut transport = match args.transport {
Some(true) => Some(TransportToolbar::new(None)),
_ => None
};
@ -65,6 +65,7 @@ impl ArrangerStandalone {
//scene.clips[i] = Some(i);
//}
}
transport.set_focused(true);
Ok(ArrangerStandalone {
transport,
show_sequencer: Some(tek_core::Direction::Down),
@ -81,7 +82,7 @@ impl Render for ArrangerStandalone {
.add_ref(&self.transport)
.add_ref(&self.arranger)
.add_ref(&sequencer)
.focus(Some(self.focus))
//.focus(Some(self.focus))
.render(buf, area)?;
if let Some(ref modal) = self.arranger.modal {
fill_bg(buf, area, Nord::bg_lo(false, false));
@ -95,9 +96,7 @@ impl Render for ArrangerStandalone {
impl Handle for ArrangerStandalone {
fn handle (&mut self, e: &AppEvent) -> Usually<bool> {
match e {
AppEvent::Input(Event::Key(KeyEvent {
code: KeyCode::Char(' '), ..
})) => {
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Char(' '), .. })) => {
if let Some(ref mut transport) = self.transport {
transport.toggle_play()?;
Ok(true)
@ -105,18 +104,32 @@ impl Handle for ArrangerStandalone {
Ok(false)
}
},
AppEvent::Input(Event::Key(KeyEvent {
code: KeyCode::Tab, ..
})) => {
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Tab, .. })) => {
self.focus_next();
Ok(true)
},
AppEvent::Input(Event::Key(KeyEvent {
code: KeyCode::BackTab, ..
})) => {
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::BackTab, .. })) => {
self.focus_prev();
Ok(true)
},
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Down, .. })) => {
if self.focus == 0 || (
self.focus == 1 && self.arranger.is_last_row()
) {
self.focus_next();
Ok(true)
} else {
self.focused_mut().handle(e)
}
},
AppEvent::Input(Event::Key(KeyEvent { code: KeyCode::Up, .. })) => {
if self.focus == 1 && self.arranger.is_first_row() {
self.focus_prev();
Ok(true)
} else {
self.focused_mut().handle(e)
}
},
_ => self.focused_mut().handle(e)
}
}