arranger: combine grid components; highlight cell

This commit is contained in:
🪞👃🪞 2024-09-20 23:24:32 +03:00
parent f15efdd2ba
commit a1a7fc3cdd

View file

@ -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);