api: compact

This commit is contained in:
🪞👃🪞 2025-04-26 21:20:06 +03:00
parent e4808f8fc1
commit 3ef3d5eb6f
22 changed files with 441 additions and 558 deletions

View file

@ -2,37 +2,6 @@ use crate::*;
pub(crate) use std::fmt::Write;
pub(crate) use ::tengri::tui::ratatui::prelude::Position;
view!(TuiOut: |self: Tek| {
self.size.of(View(self, self.view))
}; {
":nil" =>
Box::new("nil"),
":modal" =>
When::new(self.modal.is_some(), Bsp::b(
Fill::xy(Tui::fg_bg(Color::Rgb(64,64,64), Color::Rgb(32,32,32), "")),
Fixed::xy(30, 15, Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(16,16,16), self.modal))
)).boxed(),
":transport" =>
self.view_transport().boxed(),
":arranger" =>
ArrangerView::new(self).boxed(),
":editor" =>
self.editor.as_ref()
.map(|e|Bsp::n(Bsp::e(e.clip_status(), e.edit_status()), e))
.boxed(),
":samples-keys" =>
self.tracks[0].sampler(0).map(|s|s.view_list(false, self.editor.as_ref().unwrap())).boxed(),
":samples-grid" =>
self.tracks[0].sampler(0).map(|s|s.view_grid()).boxed(),
":sample-viewer" =>
self.tracks[0].sampler(0).map(|s|s.view_sample(self.editor.as_ref().unwrap().note_pos())).boxed(),
":status" =>
self.view_status().boxed(),
":pool" => self.pool.as_ref()
.map(|pool|Fixed::x(self.w_sidebar(), PoolView(self.is_editing(), pool)))
.boxed(),
});
pub(crate) struct ArrangerView<'a> {
app: &'a Tek,
@ -317,7 +286,7 @@ impl<'a> ArrangerView<'a> {
let clip = clip.read().unwrap();
(Some(clip.name.clone()), clip.color)
} else {
(None, ItemPalette::G[32])
(None, ItemTheme::G[32])
};
let height = (1 + y2 - y1) as u16;
let content = Fill::x(Align::w(Tui::bold(true, Bsp::e("", name))));
@ -392,7 +361,7 @@ impl<'a> ArrangerView<'a> {
} else {
Some(self.app.scenes[s-1].clips[track].as_ref()
.map(|c|c.read().unwrap().color)
.unwrap_or(ItemPalette::G[32]))
.unwrap_or(ItemTheme::G[32]))
}))
}
)
@ -402,7 +371,7 @@ impl<'a> ArrangerView<'a> {
trait ScenesColors<'a> = Iterator<Item=SceneWithColor<'a>>;
type SceneWithColor<'a> = (usize, &'a Scene, usize, usize, Option<ItemPalette>);
type SceneWithColor<'a> = (usize, &'a Scene, usize, usize, Option<ItemTheme>);
impl Tek {
/// Spacing between tracks.
@ -537,6 +506,21 @@ impl Tek {
)
}
pub fn view_modal (&self) -> impl Content<TuiOut> + use<'_> {
When::new(self.modal.is_some(), Bsp::b(
Fill::xy(Tui::fg_bg(Color::Rgb(64,64,64), Color::Rgb(32,32,32), "")),
Fixed::xy(30, 15, Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(16,16,16), self.modal))
))
}
pub fn view_arranger (&self) -> impl Content<TuiOut> + use<'_> {
ArrangerView::new(self)
}
pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
self.pool().map(|p|Fixed::x(self.w_sidebar(), PoolView(self.is_editing(), p)))
}
}
/// Define a type alias for iterators of sized items (columns).
@ -563,7 +547,7 @@ fn view_transport (
beat: Arc<RwLock<String>>,
time: Arc<RwLock<String>>,
) -> impl Content<TuiOut> {
let theme = ItemPalette::G[96];
let theme = ItemTheme::G[96];
Tui::bg(Black, row!(Bsp::a(
Fill::xy(Align::w(button_play_pause(play))),
Fill::xy(Align::e(row!(
@ -580,7 +564,7 @@ fn view_status (
buf: Arc<RwLock<String>>,
lat: Arc<RwLock<String>>,
) -> impl Content<TuiOut> {
let theme = ItemPalette::G[96];
let theme = ItemTheme::G[96];
Tui::bg(Black, row!(Bsp::a(
Fill::xy(Align::w(FieldH(theme, "Selected", sel))),
Fill::xy(Align::e(row!(
@ -610,7 +594,7 @@ pub(crate) fn button_play_pause (playing: bool) -> impl Content<TuiOut> {
pub (crate) fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
col!(
FieldH(ItemPalette::G[128], label, format!("{:>+9.3}", value)),
FieldH(ItemTheme::G[128], label, format!("{:>+9.3}", value)),
Fixed::xy(if value >= 0.0 { 13 }
else if value >= -1.0 { 12 }
else if value >= -2.0 { 11 }