From a1a7fc3cdde5f1e813ab0144bdbb90b899a4e220 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 20 Sep 2024 23:24:32 +0300 Subject: [PATCH] arranger: combine grid components; highlight cell --- crates/tek_sequencer/src/sequencer.rs | 29 ++++++++------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/crates/tek_sequencer/src/sequencer.rs b/crates/tek_sequencer/src/sequencer.rs index 8c6e3f23..8e7cd4d5 100644 --- a/crates/tek_sequencer/src/sequencer.rs +++ b/crates/tek_sequencer/src/sequencer.rs @@ -500,9 +500,8 @@ impl<'a, 'b> Content for ArrangerViewVertical<'a, 'b, Tui> { let scenes = state.scenes.as_ref(); let offset = 4 + scene_name_max_len(scenes) as u16; Layers::new(move |add|{ - add(&ColumnSeparators(offset, cols))?; - add(&RowSeparators(rows))?; - add(&CursorFocus(state.focused, state.selected, offset, cols, rows))?; + add(&ArrangerVerticalGrid(offset, rows, cols))?; + add(&ArrangerVerticalCursor(state.focused, state.selected, offset, cols, rows))?; add(&Split::down(|add|{ add(&Push::X(offset, Split::right(move |add|{ for (track, (w, _)) in tracks.iter().zip(*cols) { @@ -562,13 +561,13 @@ pub fn scene_name_max_len (scenes: &[Scene]) -> usize { /////////////////////////////////////////////////////////////////////////////////////////////////// -struct ColumnSeparators<'a>(u16, &'a [(usize, usize)]); +struct ArrangerVerticalGrid<'a>(u16, &'a [(usize, usize)], &'a [(usize, usize)]); -impl<'a> Widget for ColumnSeparators<'a> { +impl<'a> Widget for ArrangerVerticalGrid<'a> { type Engine = Tui; fn render (&self, to: &mut TuiOutput) -> Usually<()> { let area = to.area(); - let Self(offset, cols) = self; + let Self(offset, rows, cols) = self; let style = Some(Style::default().fg(Nord::SEPARATOR)); for (_, x) in cols.iter() { let x = offset + area.x() + *x as u16 - 1; @@ -576,19 +575,6 @@ impl<'a> Widget for ColumnSeparators<'a> { to.blit(&"▎", x, y, style); } } - Ok(()) - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -struct RowSeparators<'a>(&'a [(usize, usize)]); - -impl<'a> Widget for RowSeparators<'a> { - type Engine = Tui; - fn render (&self, to: &mut TuiOutput) -> Usually<()> { - let area = to.area(); - let Self(rows) = self; for (_, y) in rows.iter() { let y = area.y() + (*y / 96) as u16 + 1; if y >= to.buffer.area.height { @@ -608,11 +594,11 @@ impl<'a> Widget for RowSeparators<'a> { /////////////////////////////////////////////////////////////////////////////////////////////////// -struct CursorFocus<'a>( +struct ArrangerVerticalCursor<'a>( bool, ArrangerFocus, u16, &'a [(usize, usize)], &'a [(usize, usize)] ); -impl<'a> Widget for CursorFocus<'a> { +impl<'a> Widget for ArrangerVerticalCursor<'a> { type Engine = Tui; fn render (&self, to: &mut TuiOutput) -> Usually<()> { let area = to.area(); @@ -670,6 +656,7 @@ impl<'a> Widget for CursorFocus<'a> { } if focused { if let Some(clip_area) = clip_area { + to.render_in(clip_area, &CORNERS)?; to.fill_bg(clip_area, COLOR_BG0); } else if let Some(track_area) = track_area { to.fill_bg(track_area, COLOR_BG0);