wip: tui cleanup

This commit is contained in:
🪞👃🪞 2024-09-05 13:28:05 +03:00
parent df3dac183e
commit 14d619a10a
17 changed files with 345 additions and 306 deletions

View file

@ -2,7 +2,7 @@
use crate::*;
/// Represents the tracks and scenes of the composition.
pub struct Arranger<T, U> {
pub struct Arranger<E: Engine> {
/// Name of arranger
pub name: Arc<RwLock<String>>,
/// Collection of tracks.
@ -14,11 +14,11 @@ pub struct Arranger<T, U> {
/// Display mode of arranger
pub mode: ArrangerViewMode,
/// Slot for modal dialog displayed on top of app.
pub modal: Option<Box<dyn ExitableComponent<T, U>>>,
pub modal: Option<Box<dyn ExitableComponent<E>>>,
/// Whether the arranger is currently focused
pub focused: bool
}
impl<T, U> Arranger<T, U> {
impl<E: Engine> Arranger<E> {
pub fn new (name: &str) -> Self {
Self {
name: Arc::new(RwLock::new(name.into())),
@ -100,7 +100,7 @@ impl ArrangerViewMode {
}
}
/// Render arranger to terminal
impl<'a> Render<TuiOutput<'a>, Rect> for Arranger<TuiOutput<'a>, Rect> {
impl Render<Tui> for Arranger<Tui> {
fn render (&'a self, to: &'a mut TuiOutput<'a>) -> Perhaps<Rect> {
let area = (|to|match self.mode {
ArrangerViewMode::Horizontal =>
@ -125,7 +125,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for Arranger<TuiOutput<'a>, Rect> {
}))
}
}
impl<'a> Focusable<TuiOutput<'a>, Rect> for Arranger<TuiOutput<'a>, Rect> {
impl Focusable<Tui> for Arranger<Tui> {
fn is_focused (&self) -> bool {
self.focused
}

View file

@ -2,7 +2,7 @@ use crate::*;
/// Draw arranger with 1 row per scene.
pub fn draw_compact_1 <'a> (
state: &Arranger<TuiOutput<'a>, Rect>, to: &mut TuiOutput<'a>
state: &Arranger<Tui>, to: &mut Tui
) -> Perhaps<Rect> {
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
let scene_rows = (0..=state.scenes.len()).map(|i|(96, 96*i)).collect::<Vec<_>>();
@ -11,7 +11,7 @@ pub fn draw_compact_1 <'a> (
/// Draw arranger with 2 rows per scene.
pub fn draw_compact_2 <'a> (
state: &Arranger<TuiOutput<'a>, Rect>, to: &mut TuiOutput<'a>
state: &Arranger<Tui>, to: &mut Tui
) -> Perhaps<Rect> {
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
let scene_rows = (0..=state.scenes.len()).map(|i|(192, 192*i)).collect::<Vec<_>>();
@ -20,7 +20,7 @@ pub fn draw_compact_2 <'a> (
/// Draw arranger with number of rows per scene proportional to duration of scene.
pub fn draw_expanded <'a> (
state: &Arranger<TuiOutput<'a>, Rect>, to: &mut TuiOutput<'a>
state: &Arranger<Tui>, to: &mut Tui
) -> Perhaps<Rect> {
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
let scene_rows = scene_ppqs(state.tracks.as_slice(), state.scenes.as_slice());
@ -28,8 +28,8 @@ pub fn draw_expanded <'a> (
}
pub fn draw <'a, 'b> (
state: &Arranger<TuiOutput<'a>, Rect>,
to: &mut TuiOutput<'a>,
state: &Arranger<Tui>,
to: &mut Tui,
cols: &'b [(usize, usize)],
rows: &'b [(usize, usize)],
) -> Perhaps<Rect> {
@ -51,8 +51,8 @@ pub fn draw <'a, 'b> (
struct ColumnSeparators<'a>(u16, &'a [(usize, usize)]);
impl<'a> Render<TuiOutput<'a>, Rect> for ColumnSeparators<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for ColumnSeparators<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let Self(offset, cols) = self;
let style = Some(Style::default().fg(Nord::SEPARATOR));
@ -68,8 +68,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for ColumnSeparators<'a> {
struct RowSeparators<'a>(&'a [(usize, usize)]);
impl<'a> Render<TuiOutput<'a>, Rect> for RowSeparators<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for RowSeparators<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
let Self(rows) = self;
for (_, y) in rows.iter() {
@ -91,8 +91,8 @@ struct CursorFocus<'a>(
ArrangerFocus, u16, &'a [(usize, usize)], &'a [(usize, usize)]
);
impl<'a> Render<TuiOutput<'a>, Rect> for CursorFocus<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for CursorFocus<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
let Self(selected, offset, cols, rows) = *self;
let get_track_area = |t: usize| Rect {
@ -157,8 +157,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for CursorFocus<'a> {
struct TracksHeader<'a>(u16, &'a[(usize, usize)], &'a [Sequencer]);
impl<'a> Render<TuiOutput<'a>, Rect> for TracksHeader<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for TracksHeader<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
let Self(offset, track_cols, tracks) = *self;
let Rect { y, width, .. } = area;
@ -177,8 +177,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TracksHeader<'a> {
struct SceneRows<'a>(u16, &'a[(usize, usize)], &'a[(usize, usize)], &'a[Sequencer], &'a[Scene]);
impl<'a> Render<TuiOutput<'a>, Rect> for SceneRows<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for SceneRows<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let Self(offset, track_cols, scene_rows, tracks, scenes) = *self;
let black = Some(Style::default().fg(Nord::SEPARATOR));
@ -208,16 +208,15 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SceneRows<'a> {
struct SceneRow<'a>(&'a[Sequencer], &'a Scene, &'a[(usize, usize)], u16);
impl<'a> Render<TuiOutput<'a>, Rect> for SceneRow<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
let mut area = to.area;
impl<'a> Render<Tui> for SceneRow<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area();
let Self(tracks, scene, track_cols, offset) = self;
let Rect { x, y, width, .. } = area;
let playing = scene.is_playing(tracks);
(if playing { "" } else { " " }).blit(to.buffer, x, y, None)?;
scene.name.read().unwrap().blit(to.buffer, x + 1, y, Some(Style::default().white()))?;
fill_bg(to.buffer, Rect { x: x, y, width: offset.saturating_sub(1), height: area.height }, COLOR_BG1);
(if playing { "" } else { " " }).blit(to.buffer(), x, y, None)?;
scene.name.read().unwrap().blit(to.buffer(), x + 1, y, Some(Style::default().white()))?;
to.fill_bg(Rect { x: x, y, width: offset.saturating_sub(1), height: area.height }, COLOR_BG1);
for (track, (w, x)) in track_cols.iter().enumerate() {
let x = *x as u16 + offset;
if x > width {
@ -240,8 +239,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SceneRow<'a> {
struct SceneClip<'a>(&'a Sequencer, usize);
impl<'a> Render<TuiOutput<'a>, Rect> for SceneClip<'a> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for SceneClip<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let Self(track, clip) = self;
let style = Some(Style::default().white());