refactor: move some things with their appropriate verticals

This commit is contained in:
i do not exist 2026-07-02 07:55:23 +03:00
parent 3b1c31c78d
commit 51faa82d74
9 changed files with 197 additions and 218 deletions

View file

@ -1,5 +1,7 @@
use crate::*;
impl HasJack<'static> for App { fn jack (&self) -> &Jack<'static> { &self.jack } }
impl_audio!(App: tek_jack_process, tek_jack_event);
fn tek_jack_process (state: &mut App, client: &Client, scope: &ProcessScope) -> Control {

View file

@ -1,4 +1,9 @@
use crate::*;
tui_keys!(|self: App, input| {
todo!()
});
/// A control axis.
///
/// ```
@ -128,3 +133,63 @@ impl<E: Clone + Ord, C> Bind<E, C> {
}
impl_debug!(Condition |self, w| { write!(w, "*") });
impl_default!(AppCommand: Self::Nop);
def_command!(AppCommand: |app: App| {
Nop => Ok(None),
Cancel => todo!(), // TODO delegate:
Confirm => app.confirm(),
Inc { axis: ControlAxis } => app.inc(axis),
Dec { axis: ControlAxis } => app.dec(axis),
SetDialog { dialog: Dialog } => {
swap_value(&mut app.dialog, dialog, |dialog|Self::SetDialog { dialog })
},
});
impl<'a> Namespace<'a, AppCommand> for App {
symbols!('a |app| -> AppCommand {
"x/inc" => AppCommand::Inc { axis: ControlAxis::X },
"x/dec" => AppCommand::Dec { axis: ControlAxis::X },
"y/inc" => AppCommand::Inc { axis: ControlAxis::Y },
"y/dec" => AppCommand::Dec { axis: ControlAxis::Y },
"confirm" => AppCommand::Confirm,
"cancel" => AppCommand::Cancel,
});
}
//impl_handle!(TuiIn: |self: App, input|{
//let commands = tek_collect_commands(self, input)?;
//let history = tek_execute_commands(self, commands)?;
//self.history.extend(history.into_iter());
//Ok(None)
//});
//fn tek_collect_commands (app: &App, input: &TuiIn) -> Usually<Vec<AppCommand>> {
//let mut commands = vec![];
//for id in app.mode.keys.iter() {
//if let Some(event_map) = app.config.binds.clone().read().unwrap().get(id.as_ref())
//&& let Some(bindings) = event_map.query(input.event()) {
//for binding in bindings {
//for command in binding.commands.iter() {
//if let Some(command) = app.namespace(command)? as Option<AppCommand> {
//commands.push(command)
//}
//}
//}
//}
//}
//Ok(commands)
//}
//fn tek_execute_commands (
//app: &mut App, commands: Vec<AppCommand>
//) -> Usually<Vec<(AppCommand, Option<AppCommand>)>> {
//let mut history = vec![];
//for command in commands.into_iter() {
//let result = command.act(app);
//match result { Err(err) => { history.push((command, None)); return Err(err) }
//Ok(undo) => { history.push((command, undo)); } };
//}
//Ok(history)
//}

View file

@ -109,7 +109,7 @@ impl Action {
//return Ok(())
//}
// Initialize the app state
let app = App::new_shared(&jack, proj, config, ":menu");
let app = Arc::new(RwLock::new(App::new(&jack, proj, config, ":menu")));
//if matches!(self, Action::Headless) {
//// TODO: Headless mode (daemon + client over IPC, then over network...)
//println!("todo headless");

View file

@ -1,5 +1,26 @@
use crate::*;
/// The [Draw] implementation for [App] handles the loaded view,
/// which is defined in terms of [dizzle] DSL.
///
/// If there is an error, the error is displayed. FIXME: overlay it
/// Then, every top-level form of the DSL description is rendered.
impl Draw<Tui> for App {
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
let xywh = to.area().into();
if let Some(e) = self.error.read().unwrap().as_ref() {
to.show(xywh, e.as_ref())?;
}
for (index, dsl) in self.mode.view.iter().enumerate() {
if let Err(e) = self.interpret(to, dsl) {
*self.error.write().unwrap() = Some(format!("view #{index}: {e}").into());
break;
}
}
Ok(xywh)
}
}
impl Interpret<Tui, XYWH<u16>> for App {
fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression)
-> Usually<XYWH<u16>>

57
src/app/size.rs Normal file
View file

@ -0,0 +1,57 @@
use crate::*;
impl_has!(Size: |self: App|self.size);
/// Define a type alias for iterators of sized items (columns).
macro_rules! def_sizes_iter {
($Type:ident => $($Item:ty),+) => {
pub trait $Type<'a> =
Iterator<Item=(usize, $(&'a $Item,)+ usize, usize)> + Send + Sync + 'a;
}
}
def_sizes_iter!(InputsSizes => MidiInput);
def_sizes_iter!(OutputsSizes => MidiOutput);
def_sizes_iter!(PortsSizes => Arc<str>, [Connect]);
def_sizes_iter!(ScenesSizes => Scene);
def_sizes_iter!(TracksSizes => Track);
pub(crate) fn track_width (_index: usize, track: &Track) -> u16 {
track.width as u16
}
pub trait HasWidth {
const MIN_WIDTH: usize;
/// Increment track width.
fn width_inc (&mut self);
/// Decrement track width, down to a hardcoded minimum of [Self::MIN_WIDTH].
fn width_dec (&mut self);
}
impl HasClipsSize for App {
fn clips_size (&self) -> &Size { &self.project.size_inner }
}
impl HasTrackScroll for App {
fn track_scroll (&self) -> usize {
self.project.track_scroll()
}
}
impl HasSceneScroll for App {
fn scene_scroll (&self) -> usize {
self.project.scene_scroll()
}
}
impl ScenesView for App {
fn w_mid (&self) -> u16 {
(self.size.w() as u16).saturating_sub(self.w_side())
}
fn w_side (&self) -> u16 {
20
}
fn h_scenes (&self) -> u16 {
(self.size.h() as u16).saturating_sub(20)
}
}

View file

@ -1,5 +1,9 @@
use crate::*;
tui_view!(|self: App| {
""
});
/// Collection of custom view definitions.
pub type Views = Arc<RwLock<BTreeMap<Arc<str>, Arc<str>>>>;