mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
smartass macro
This commit is contained in:
parent
1e54d81e5d
commit
084af3ef01
2 changed files with 11 additions and 13 deletions
|
|
@ -27,19 +27,10 @@ pub enum PhraseCommand {
|
|||
SetTimeZoom(usize),
|
||||
SetTimeLock(bool),
|
||||
Show(Option<Arc<RwLock<Phrase>>>),
|
||||
ToggleDirection,
|
||||
}
|
||||
|
||||
impl InputToCommand<Tui, PhraseEditorModel> for PhraseCommand {
|
||||
fn input_to_command (state: &PhraseEditorModel, from: &TuiInput) -> Option<Self> {
|
||||
return state.to_editor_command(from)
|
||||
}
|
||||
}
|
||||
event_map_input_to_command!(Tui: PhraseEditorModel: PhraseCommand: PhraseEditorModel::KEYS);
|
||||
|
||||
impl PhraseEditorModel {
|
||||
fn phrase_length (&self) -> usize {
|
||||
self.phrase().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
|
||||
}
|
||||
const KEYS: [(TuiEvent, &'static dyn Fn(&Self)->PhraseCommand);31] = [
|
||||
(kexp!(Ctrl-Alt-Up), &|s: &Self|SetNoteScroll(s.note_point() + 3)),
|
||||
(kexp!(Ctrl-Alt-Down), &|s: &Self|SetNoteScroll(s.note_point().saturating_sub(3))),
|
||||
|
|
@ -72,12 +63,11 @@ impl PhraseEditorModel {
|
|||
(kexp!(Char('.')), &|s: &Self|SetNoteLength(Note::next(s.note_len()))),
|
||||
(kexp!(Char('<')), &|s: &Self|SetNoteLength(Note::prev(s.note_len()))), // TODO: 3plet
|
||||
(kexp!(Char('>')), &|s: &Self|SetNoteLength(Note::next(s.note_len()))),
|
||||
//key_pat!(Char('`')) -> ToggleDirection,
|
||||
//// TODO: key_pat!(Char('/')) => // toggle 3plet
|
||||
//// TODO: key_pat!(Char('?')) => // toggle dotted
|
||||
];
|
||||
fn to_editor_command (&self, from: &TuiInput) -> Option<PhraseCommand> {
|
||||
event_map!(Self::KEYS).handle(self, from.event())
|
||||
fn phrase_length (&self) -> usize {
|
||||
self.phrase().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,14 @@ impl<'a, const N: usize, E: PartialEq, T, U> EventMap<'a, N, E, T, U> {
|
|||
};
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! event_map_input_to_command {
|
||||
($Engine:ty: $Model:ty: $Command:ty: $EventMap:expr) => {
|
||||
input_to_command!($Command: <$Engine>|state: $Model, input|{
|
||||
event_map!($EventMap).handle(state, input.event())?
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! kexp {
|
||||
(Ctrl-Alt-$code:ident) => { key_event_expr!($code, KeyModifiers::from_bits(0b0000_0110).unwrap()) };
|
||||
(Ctrl-$code:ident) => { key_event_expr!($code, KeyModifiers::CONTROL) };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue