wip: build arranger out of freestanding functions

This commit is contained in:
🪞👃🪞 2025-03-12 04:17:33 +02:00
parent 4dbbe0340a
commit 4229364363
12 changed files with 570 additions and 472 deletions

View file

@ -0,0 +1,56 @@
use crate::*;
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
width: u16,
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
Align::x(Tui::bg(Reset, Map::new(tracks, move|(index, track, x1, x2), _|{
let width = (x2 - x1) as u16;
map_east(x1 as u16, width, Fixed::x(width, Tui::fg_bg(
track.color.lightest.rgb,
track.color.base.rgb,
callback(index, track)
)))
})))
}
pub(crate) fn per_track <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
width: u16,
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
per_track_top(width, tracks, move|index, track|Fill::y(Align::y(callback(index, track))))
}
pub(crate) fn view_tracks <'a, T, U> (
w_mid: u16,
w_side: u16,
track_count: &'a Arc<RwLock<String>>,
tracks_sizes: U,
selected: Option<usize>,
editing: bool,
) -> impl Content<TuiOut> + use<'a, T, U> where
T: TracksSizes<'a>, U: Fn()->T + Send + Sync + 'a
{
let callback = |t, track|view_track_header(t, track, selected == Some(t));
Tryptich::center(1)
.left(w_side, button_3("t", "track", track_count, editing))
.middle(w_mid, per_track(w_mid, tracks_sizes, callback))
.right(w_side, button_2("T", "add track", editing))
}
fn view_track_header <'a> (t: usize, track: &'a Track, active: bool) -> impl Content<TuiOut> + use<'a> {
let fg = track.color.lightest.rgb;
let bg = if active { track.color.light.rgb } else { track.color.base.rgb };
let bg2 = Reset;//if t > 0 { self.tracks()[t - 1].color.base.rgb } else { Reset };
wrap(bg, fg, Tui::bold(true, Fill::x(Align::nw(&track.name))))
}
#[cfg(test)] #[test] fn test_view_track () {
let mut output = TuiOut::default();
output.area[2] = 9;
output.area[3] = 9;
Content::render(&view_tracks(), &mut output);
}