thunk -> draw
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
i do not exist 2026-08-03 09:41:07 +03:00
parent 5357e83245
commit 8de62463c0
5 changed files with 37 additions and 29 deletions

View file

@ -137,7 +137,7 @@ impl PianoHorizontal {
let note_lo = self.get_note_lo(); let note_lo = self.get_note_lo();
let note_hi = self.get_note_hi(); let note_hi = self.get_note_hi();
let buffer = self.buffer.clone(); let buffer = self.buffer.clone();
thunk(move|to: &mut Tui|{ draw(move|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
let XYWH(x0, y0, w, _h) = xywh; let XYWH(x0, y0, w, _h) = xywh;
let source = buffer.read().unwrap(); let source = buffer.read().unwrap();
@ -175,7 +175,7 @@ impl PianoHorizontal {
let time_start = self.get_time_start(); let time_start = self.get_time_start();
let time_zoom = self.get_time_zoom(); let time_zoom = self.get_time_zoom();
let style = Some(Style::default().fg(self.color.lightest.term)); let style = Some(Style::default().fg(self.color.lightest.term));
thunk(move|to: &mut Tui|{ draw(move|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
let XYWH(x0, y0, w, _h) = xywh; let XYWH(x0, y0, w, _h) = xywh;
for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) { for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
@ -209,7 +209,7 @@ impl PianoHorizontal {
let key_style = Some(Style::default().fg(Rgb(192, 192, 192)).bg(Rgb(0, 0, 0))); let key_style = Some(Style::default().fg(Rgb(192, 192, 192)).bg(Rgb(0, 0, 0)));
let off_style = Some(Style::default().fg(g(255))); let off_style = Some(Style::default().fg(g(255)));
let on_style = Some(Style::default().fg(Rgb(255,0,0)).bg(color.base.term).bold()); let on_style = Some(Style::default().fg(Rgb(255,0,0)).bg(color.base.term).bold());
thunk(move|to: &mut Tui|{ draw(move|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
let XYWH(x, y0, _w, _h) = xywh; let XYWH(x, y0, _w, _h) = xywh;
for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) { for (_area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
@ -228,7 +228,7 @@ impl PianoHorizontal {
} }
fn timeline (&self) -> impl Draw<Tui> + '_ { fn timeline (&self) -> impl Draw<Tui> + '_ {
thunk(move|to: &mut Tui|{ draw(move|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
let XYWH(x, y, w, _h) = xywh; let XYWH(x, y, w, _h) = xywh;
let style = Some(Style::default().dim()); let style = Some(Style::default().dim());

View file

@ -141,7 +141,7 @@ impl ApplicationHandler for LV2PluginUI {
} }
impl Draw<Tui> for Lv2 { impl Draw<Tui> for Lv2 {
fn draw(self, to: &mut Tui) { fn draw (&self, to: &mut Tui) {
let area = to.area(); let area = to.area();
let XYWH(x, y, _, height) = area; let XYWH(x, y, _, height) = area;
let mut width = 20u16; let mut width = 20u16;

View file

@ -257,7 +257,7 @@ fn draw_list_item (sample: &Option<Arc<RwLock<Sample>>>) -> String {
fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> { fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
let min_db = -64.0; let min_db = -64.0;
thunk(move|to: &mut Tui|{ draw(move|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
let XYWH(x, y, width, height) = xywh; let XYWH(x, y, width, height) = xywh;
let area = Rect { x, y, width, height }; let area = Rect { x, y, width, height };

View file

@ -1452,12 +1452,11 @@ mod draw {
/// Then, every top-level form of the DSL description is rendered. /// Then, every top-level form of the DSL description is rendered.
impl View<Tui> for App { impl View<Tui> for App {
fn view (&self) -> impl Draw<Tui> { fn view (&self) -> impl Draw<Tui> {
thunk(|to: &mut Tui|{ draw(|to: &mut Tui|{
let xywh = to.area().into(); let xywh = to.area().into();
if let Some(e) = self.error.read().unwrap().as_ref() { if let Some(e) = self.error.read().unwrap().as_ref() {
//to.show(area(xywh, format!("KYPbanica {xywh:?}").align_c()))?; e.as_ref().align_c().draw(to)?;
to.show(e.as_ref().align_c())?;
} }
if let Some(ref mode) = self.mode { if let Some(ref mode) = self.mode {
@ -1471,13 +1470,22 @@ mod draw {
} }
} }
to.show(ShowSize.align_se())?; ShowSize.align_se().draw(to)?;
Ok(Some(xywh)) Ok(Some(xywh))
}) })
} }
} }
impl Keywords<Tui, XYWH<u16>> for App {
fn keywords () -> impl Iterator<Item = fn(&Self, &mut Tui, &str) -> Perhaps<XYWH<u16>>> {
[
kw_when, kw_either, kw_split, kw_align,
kw_exact, kw_fixed, kw_min, kw_max, kw_push
].into_iter()
}
}
impl Interpret<Tui, Option<XYWH<u16>>> for App { impl Interpret<Tui, Option<XYWH<u16>>> for App {
fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn<u16> { fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn<u16> {
tek_draw_expr(self, to, lang) tek_draw_expr(self, to, lang)
@ -1582,7 +1590,7 @@ mod draw {
Some("menu") => if let Dialog::Menu(selected, items) = &state.dialog { Some("menu") => if let Dialog::Menu(selected, items) = &state.dialog {
let items = items.clone(); let items = items.clone();
let selected = selected; let selected = selected;
Some(thunk(move|to: &mut Tui|{ Some(draw(move|to: &mut Tui|{
for (index, MenuItem(item, _)) in items.0.iter().enumerate() { for (index, MenuItem(item, _)) in items.0.iter().enumerate() {
let f = if *selected == index { Rgb(240,200,180) } else { Rgb(200, 200, 200) }; let f = if *selected == index { Rgb(240,200,180) } else { Rgb(200, 200, 200) };
let b = if *selected == index { Rgb(80, 80, 50) } else { Rgb(30, 30, 30) }; let b = if *selected == index { Rgb(80, 80, 50) } else { Rgb(30, 30, 30) };
@ -1600,7 +1608,7 @@ mod draw {
pub fn draw_templates (to: &mut Tui, _frags: std::str::Split<&str>, state: &App) -> Drawn<u16> { pub fn draw_templates (to: &mut Tui, _frags: std::str::Split<&str>, state: &App) -> Drawn<u16> {
let height = (state.config.modes.len() * 2) as u16; let height = (state.config.modes.len() * 2) as u16;
thunk(move |to: &mut Tui|{ draw(move |to: &mut Tui|{
let mut index = 0; let mut index = 0;
state.config.modes.for_each(|id, profile| { state.config.modes.for_each(|id, profile| {
let b = if index == 0 { Rgb(70,70,70) } else { Rgb(50,50,50) }; let b = if index == 0 { Rgb(70,70,70) } else { Rgb(50,50,50) };
@ -1654,7 +1662,7 @@ mod draw {
let h = 6; let h = 6;
let w = Some(30); let w = Some(30);
let f = Rgb(224, 192, 128); let f = Rgb(224, 192, 128);
thunk(move |to: &mut Tui|{ draw(move |to: &mut Tui|{
for (index, name) in ["session1", "session2", "session3"].iter().enumerate() { for (index, name) in ["session1", "session2", "session3"].iter().enumerate() {
let b = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) }; let b = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) };
let y = (2 * index) as u16; let y = (2 * index) as u16;
@ -1732,11 +1740,11 @@ mod draw {
pub fn button_play_pause (playing: bool, compact: bool) -> impl Draw<Tui> { pub fn button_play_pause (playing: bool, compact: bool) -> impl Draw<Tui> {
bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) }, bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
either(compact, either(compact,
thunk(move|to: &mut Tui|either(playing, draw(move|to: &mut Tui|either(playing,
fg(Rgb(0, 255, 0), " PLAYING "), fg(Rgb(0, 255, 0), " PLAYING "),
fg(Rgb(255, 128, 0), " STOPPED "), fg(Rgb(255, 128, 0), " STOPPED "),
).exact_w(9).draw(to)), ).exact_w(9).draw(to)),
thunk(move|to: &mut Tui|either(playing, draw(move|to: &mut Tui|either(playing,
fg(Rgb(0, 255, 0), south(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)), fg(Rgb(0, 255, 0), south(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
fg(Rgb(255, 128, 0), south(" ▗▄▖ ", " ▝▀▘ ",)), fg(Rgb(255, 128, 0), south(" ▗▄▖ ", " ▝▀▘ ",)),
).exact_w(5).draw(to)), ).exact_w(5).draw(to)),
@ -1803,7 +1811,7 @@ mod draw {
} }
pub fn view_sample_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> { pub fn view_sample_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
when(sample.is_some(), thunk(move|to: &mut Tui|{ when(sample.is_some(), draw(move|to: &mut Tui|{
let sample = sample.unwrap().read().unwrap(); let sample = sample.unwrap().read().unwrap();
let theme = sample.color; let theme = sample.color;
east!( east!(
@ -1818,7 +1826,7 @@ mod draw {
} }
pub fn view_sample_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> { pub fn view_sample_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Draw<Tui> + use<'_> {
let a = thunk(move|to: &mut Tui|{ let a = draw(move|to: &mut Tui|{
let sample = sample.unwrap().read().unwrap(); let sample = sample.unwrap().read().unwrap();
let theme = sample.color; let theme = sample.color;
south!( south!(
@ -1831,7 +1839,7 @@ mod draw {
).exact_w(20).draw(to) ).exact_w(20).draw(to)
}); });
let b = thunk(|to: &mut Tui|fg(Red, south!( let b = draw(|to: &mut Tui|fg(Red, south!(
bold(true, "× No sample."), bold(true, "× No sample."),
"[r] record", "[r] record",
"[Shift-F9] import", "[Shift-F9] import",
@ -1975,7 +1983,7 @@ mod draw {
button_2("T", "+", false), button_2("T", "+", false),
button_2("S", "+", false)); button_2("S", "+", false));
view_track_row_section(theme, button, button_2, bg(theme.darker.term, view_track_row_section(theme, button, button_2, bg(theme.darker.term,
thunk(|to: &mut Tui|{ draw(|to: &mut Tui|{
for (index, track, x1, _x2) in tracks { for (index, track, x1, _x2) in tracks {
let b = if selected.track() == Some(index) { let b = if selected.track() == Some(index) {
track.color.light.term track.color.light.term
@ -2001,14 +2009,14 @@ mod draw {
) -> impl Draw<Tui> { ) -> impl Draw<Tui> {
view_track_row_section(theme, view_track_row_section(theme,
south(button_2("o", "utput", false).align_w().full_w(), south(button_2("o", "utput", false).align_w().full_w(),
thunk(|to: &mut Tui|{ draw(|to: &mut Tui|{
for port in midi_outs { for port in midi_outs {
let _ = port.port_name().align_w().full_w().draw(to)?; let _ = port.port_name().align_w().full_w().draw(to)?;
} }
Ok(Some(XYWH(0, 0, 0, 0))) Ok(Some(XYWH(0, 0, 0, 0)))
})), })),
button_2("O", "+", false), button_2("O", "+", false),
bg(theme.darker.term, thunk(|to: &mut Tui|{ bg(theme.darker.term, draw(|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks { for (index, track, _x1, _x2) in tracks {
let f = Rgb(255, 255, 255); let f = Rgb(255, 255, 255);
let b = track.color.dark.term; let b = track.color.dark.term;
@ -2027,7 +2035,7 @@ mod draw {
theme: ItemTheme, tracks: impl TracksSizes<'a>, height: u16, theme: ItemTheme, tracks: impl TracksSizes<'a>, height: u16,
) -> impl Draw<Tui> { ) -> impl Draw<Tui> {
view_track_row_section(theme, button_2("i", "nput", false), button_2("I", "+", false), view_track_row_section(theme, button_2("i", "nput", false), button_2("I", "+", false),
bg(theme.darker.term, thunk(move|to: &mut Tui|{ bg(theme.darker.term, draw(move|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks { for (index, track, _x1, _x2) in tracks {
south( south(
bg(track.color.base.term, bg(track.color.base.term,
@ -2051,7 +2059,7 @@ mod draw {
editor: Option<&MidiEditor>, editor: Option<&MidiEditor>,
editing: bool, editing: bool,
) -> impl Draw<Tui> { ) -> impl Draw<Tui> {
thunk(move |to: &mut Tui|{ draw(move |to: &mut Tui|{
for (index, scene, ..) in scenes { 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)?;
} }
@ -2122,7 +2130,7 @@ mod draw {
) -> impl Draw<Tui> { ) -> impl Draw<Tui> {
let title_1 = button_3("i", "nput ", format!("{}", midi_ins.len()), false).align_w().exact_wh(20, 1); let title_1 = button_3("i", "nput ", format!("{}", midi_ins.len()), false).align_w().exact_wh(20, 1);
let title_2 = button_2("I", "+", false).exact_wh(4, 1); let title_2 = button_2("I", "+", false).exact_wh(4, 1);
east(title_1, west(title_2, thunk(move|to: &mut Tui|{ east(title_1, west(title_2, draw(move|to: &mut Tui|{
for (_index, track, x1, _x2) in tracks { for (_index, track, x1, _x2) in tracks {
let _ = south( let _ = south(
bg(track.color.dark.term, east!( bg(track.color.dark.term, east!(
@ -2130,7 +2138,7 @@ mod draw {
either(track.sequencer.recording, fg(Red, "rec "), "rec "), either(track.sequencer.recording, fg(Red, "rec "), "rec "),
either(track.sequencer.overdub, fg(Yellow, "dub "), "dub "), either(track.sequencer.overdub, fg(Yellow, "dub "), "dub "),
).exact_w(track.width as u16)).align_w().push_x(x1 as u16), ).exact_w(track.width as u16)).align_w().push_x(x1 as u16),
thunk(move |to: &mut Tui|{ draw(move |to: &mut Tui|{
for (index, port) in midi_ins.iter().enumerate() { for (index, port) in midi_ins.iter().enumerate() {
let _ = east( let _ = east(
east( east(
@ -2166,7 +2174,7 @@ mod draw {
button_3( button_3(
"o", "utput", format!("{}", midi_outs.len()), false "o", "utput", format!("{}", midi_outs.len()), false
).align_w().full_w().exact_h(1), ).align_w().full_w().exact_h(1),
thunk(|to: &mut Tui|{ draw(|to: &mut Tui|{
for (_index, port) in midi_outs.iter().enumerate() { for (_index, port) in midi_outs.iter().enumerate() {
east( east(
east("", fg(Rgb(255,255,255), bold(true, port.port_name()))).align_w(), east("", fg(Rgb(255,255,255), bold(true, port.port_name()))).align_w(),
@ -2182,9 +2190,9 @@ mod draw {
); );
view_track_row_section(theme, list, button_2("O", "+", false), view_track_row_section(theme, list, button_2("O", "+", false),
bg(theme.darker.term, thunk(|to: &mut Tui|{ bg(theme.darker.term, draw(|to: &mut Tui|{
for (index, track, _x1, _x2) in tracks { for (index, track, _x1, _x2) in tracks {
let _ = thunk(|to: &mut Tui|{ let _ = draw(|to: &mut Tui|{
east( east(
either(true, fg(Green, "play "), "play "), either(true, fg(Green, "play "), "play "),
either(false, fg(Yellow, "solo "), "solo "), either(false, fg(Yellow, "solo "), "solo "),

2
tengri

@ -1 +1 @@
Subproject commit fc01fd6ad3a6ed4ee17d65a65b3e59df522f895a Subproject commit eb028c85fc94a1b86c44d4f079e5fb91667d4db2