wip: borrow checker battles

This commit is contained in:
🪞👃🪞 2024-09-04 16:57:48 +03:00
parent 1d4db3c629
commit 7fbb40fad6
38 changed files with 778 additions and 708 deletions

View file

@ -1,31 +1,42 @@
use crate::*;
handle!(Track |self, event| handle_keymap(self, event, KEYMAP_TRACK));
/// Key bindings for chain section.
pub const KEYMAP_TRACK: &'static [KeyBinding<Track>] = keymap!(Track {
[Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut Track| {
Ok(true)
}],
[Down, NONE, "chain_cursor_down", "move cursor down", |_: &mut Track| {
Ok(true)
}],
[Left, NONE, "chain_cursor_left", "move cursor left", |app: &mut Track| {
//if let Some(track) = app.arranger.track_mut() {
//track.device = track.device.saturating_sub(1);
//return Ok(true)
//}
Ok(false)
}],
[Right, NONE, "chain_cursor_right", "move cursor right", |app: &mut Track| {
//if let Some(track) = app.arranger.track_mut() {
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
//return Ok(true)
//}
Ok(false)
}],
[Char('`'), NONE, "chain_mode_switch", "switch the display mode", |app: &mut Track| {
//app.chain_mode = !app.chain_mode;
Ok(true)
}],
});
impl <T, U> Handle for Track<T, U> {
fn handle (&mut self, event: &AppEvent) -> Usually<bool> {
match event {
AppEvent::Input(crossterm::event::Event::Key(event)) => {
for (code, modifiers, _, _, command) in [
key!(Up, NONE, "chain_cursor_up", "move cursor up", || {
Ok(true)
}),
key!(Down, NONE, "chain_cursor_down", "move cursor down", || {
Ok(true)
}),
key!(Left, NONE, "chain_cursor_left", "move cursor left", || {
//if let Some(track) = app.arranger.track_mut() {
//track.device = track.device.saturating_sub(1);
//return Ok(true)
//}
Ok(false)
}),
key!(Right, NONE, "chain_cursor_right", "move cursor right", || {
//if let Some(track) = app.arranger.track_mut() {
//track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
//return Ok(true)
//}
Ok(false)
}),
key!(Char('`'), NONE, "chain_mode_switch", "switch the display mode", || {
//app.chain_mode = !app.chain_mode;
Ok(true)
}),
].iter() {
if *code == event.code && modifiers.bits() == event.modifiers.bits() {
return command()
}
}
return Ok(false)
},
_ => Ok(false)
}
}
}