wip: simplify and document

This commit is contained in:
i do not exist 2026-07-05 18:46:33 +03:00
parent 701a651fbd
commit b9e7b9732e
12 changed files with 116 additions and 72 deletions

View file

@ -1,27 +1,25 @@
use crate::*;
tui_view!(|self: App| {
""
});
/// 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;
impl View<Tui> for App {
fn view (&self) -> impl Draw<Tui> {
thunk(|to: &mut Tui|{
let xywh = to.area().into();
if let Some(e) = self.error.read().unwrap().as_ref() {
to.show(Layout::XYWH(xywh, e.as_ref()))?;
}
}
Ok(xywh)
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)
})
}
}
@ -127,7 +125,7 @@ pub fn draw_dialog (
if *selected == index { Rgb(240,200,180) } else { Rgb(200, 200, 200) },
if *selected == index { Rgb(80, 80, 50) } else { Rgb(30, 30, 30) },
h_exact(2, origin_n(w_full(item)))
)).draw(to);
)).draw(to)?;
}
Ok(to.area().into())
})))
@ -364,7 +362,7 @@ pub fn view_scenes_clips <'a, S: ScenesSizes<'a>> (
tracks: impl TracksSizes<'a>,
select: &Selection,
editor: Option<&MidiEditor>,
size: &Size,
size: &Sizer,
editing: bool,
) -> impl Draw<Tui> {
let status = wh_full(origin_se(fg(Green, format!("{}x{}", size.w(), size.h()))));
@ -465,7 +463,7 @@ pub fn view_track_names (
}, south(w_full(origin_nw(east(
format!("·t{index:02} "),
fg(Rgb(255, 255, 255), bold(true, &track.name))
))), ""))) ).draw(to);
))), ""))) ).draw(to)?;
}
Ok(XYWH(0, 0, 0, 0))
}))))
@ -490,7 +488,7 @@ pub fn view_track_outputs (
h_exact(1, bg(track.color.dark.term, w_full(origin_w(
format!("·o{index:02} {}", port.port_name()))))));
w_exact(track_width(index, track),
origin_nw(h_full(iter_south(iter, draw)))).draw(to);
origin_nw(h_full(iter_south(iter, draw)))).draw(to)?;
}
Ok(XYWH(0, 0, 0, 0))
}))))
@ -513,7 +511,7 @@ pub fn view_track_inputs (
iter_south(||track.sequencer.midi_ins.iter(),
|port, _|fg_bg(Rgb(255, 255, 255), track.color.dark.term,
w_full(origin_w(format!("·i{index:02} {}", port.port_name()))))))))
.draw(to);
.draw(to)?;
}
Ok(XYWH(0, 0, 0, 0))
}))))
@ -527,7 +525,7 @@ pub fn view_scenes_names (
) -> impl Draw<Tui> {
w_exact(20, thunk(move |to: &mut Tui|{
for (index, scene, ..) in scenes {
view_scene_name(select, editor, index, scene, editing).draw(to);
view_scene_name(select, editor, index, scene, editing).draw(to)?;
}
Ok(XYWH(1, 1, 1, 1))
}))
@ -639,10 +637,10 @@ pub fn view_outputs (
origin_w(east("", fg(Rgb(255,255,255), bold(true, port.port_name())))),
w_full(origin_e(format!("{}/{} ",
port.port().get_connections().len(),
port.connections.len())))))).draw(to);
port.connections.len())))))).draw(to)?;
for (index, conn) in port.connections.iter().enumerate() {
h_exact(1, w_full(origin_w(format!(" c{index:02}{}", conn.info()))))
.draw(to);
.draw(to)?;
}
}
todo!();
@ -658,14 +656,14 @@ pub fn view_outputs (
h_exact(1, origin_w(east(
either(true, fg(Green, "play "), "play "),
either(false, fg(Yellow, "solo "), "solo "),
))).draw(to);
))).draw(to)?;
for (_index, port) in midi_outs.iter().enumerate() {
h_exact(1, origin_w(east(
either(true, fg(Green, ""), " · "),
either(false, fg(Yellow, ""), " · "),
))).draw(to);
))).draw(to)?;
for (_index, _conn) in port.connections.iter().enumerate() {
h_exact(1, w_full("")).draw(to);
h_exact(1, w_full("")).draw(to)?;
}
}
todo!()
@ -734,7 +732,7 @@ pub fn view_sessions () -> impl Draw<Tui> {
let b = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) };
let y = (2 * index) as u16;
let h = 2;
y_push(y, &h_exact(h, w_full(bg(b, origin_w(fg(f, name)))))).draw(to);
y_push(y, h_exact(h, w_full(bg(b, origin_w(fg(f, *name)))))).draw(to)?;
}
Ok(to.area().into())
})))

View file

@ -1,6 +1,6 @@
use crate::*;
impl_has!(Size: |self: App|self.size);
impl_has!(Sizer: |self: App|self.size);
/// Define a type alias for iterators of sized items (columns).
macro_rules! def_sizes_iter {