mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
parent
cfd19062fd
commit
559d2fc4a1
7 changed files with 125 additions and 72 deletions
|
|
@ -30,34 +30,55 @@ handle!(TuiIn:|self: App, input|{
|
|||
Ok(None)
|
||||
});
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum Axis { X, Y, Z, I }
|
||||
|
||||
impl<'t> DslNs<'t, AppCommand> for App {
|
||||
dsl_exprs!(|app| -> AppCommand { /* TODO */ });
|
||||
dsl_words!(|app| -> AppCommand {
|
||||
"y/inc" => match app.dialog {
|
||||
Dialog::Menu(index, count) => AppCommand::SetDialog {
|
||||
dialog: Dialog::Menu(if count > 0 {
|
||||
(index + 1) % count
|
||||
} else { 0 }, count)
|
||||
},
|
||||
_ => todo!(),
|
||||
},
|
||||
"y/dec" => match app.dialog {
|
||||
Dialog::Menu(index, count) => AppCommand::SetDialog {
|
||||
dialog: Dialog::Menu(if count > 0 {
|
||||
index.overflowing_sub(1).0.min(count.saturating_sub(1))
|
||||
} else { 0 }, count)
|
||||
},
|
||||
_ => todo!(),
|
||||
},
|
||||
"confirm" => todo!(),
|
||||
"x/inc" => AppCommand::Inc { axis: Axis::X },
|
||||
"x/dec" => AppCommand::Dec { axis: Axis::X },
|
||||
"y/inc" => AppCommand::Inc { axis: Axis::Y },
|
||||
"y/dec" => AppCommand::Dec { axis: Axis::Y },
|
||||
"confirm" => AppCommand::Confirm,
|
||||
"cancel" => AppCommand::Cancel,
|
||||
});
|
||||
}
|
||||
|
||||
impl Default for AppCommand { fn default () -> Self { Self::Nop } }
|
||||
|
||||
def_command!(AppCommand: |app: App| {
|
||||
SetDialog { dialog: Dialog } =>
|
||||
swap_value(&mut app.dialog, dialog, |dialog|Self::SetDialog { dialog }),
|
||||
Nop => Ok(None),
|
||||
Confirm => todo!(),
|
||||
Cancel => todo!(), // TODO delegate:
|
||||
Inc { axis: Axis } => Ok(match (&app.dialog, axis) {
|
||||
(Dialog::None, _) => todo!(),
|
||||
(Dialog::Menu(_, _), Axis::Y) => AppCommand::SetDialog { dialog: app.dialog.menu_next() }
|
||||
.execute(app)?,
|
||||
_ => todo!()
|
||||
}),
|
||||
Dec { axis: Axis } => Ok(match (&app.dialog, axis) {
|
||||
(Dialog::None, _) => None,
|
||||
(Dialog::Menu(_, _), Axis::Y) => AppCommand::SetDialog { dialog: app.dialog.menu_prev() }
|
||||
.execute(app)?,
|
||||
_ => todo!()
|
||||
}),
|
||||
SetDialog { dialog: Dialog } => {
|
||||
swap_value(&mut app.dialog, dialog, |dialog|Self::SetDialog { dialog })
|
||||
},
|
||||
});
|
||||
|
||||
pub fn wrap_inc (index: usize, count: usize) -> usize {
|
||||
if count > 0 { (index + 1) % count } else { 0 }
|
||||
}
|
||||
|
||||
pub fn wrap_dec (index: usize, count: usize) -> usize {
|
||||
if count > 0 { index.overflowing_sub(1).0.min(count.saturating_sub(1)) } else { 0 }
|
||||
}
|
||||
|
||||
impl Dialog {
|
||||
}
|
||||
|
||||
//AppCommand => {
|
||||
//("x/inc" /
|
||||
//("stop-all") => todo!(),//app.project.stop_all(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue