wip: 21 errors!

This commit is contained in:
🪞👃🪞 2024-09-05 17:38:32 +03:00
parent 694970bf0d
commit ea5bc2e3b1
30 changed files with 392 additions and 362 deletions

View file

@ -33,7 +33,7 @@ pub fn draw <'a, 'b> (
cols: &'b [(usize, usize)],
rows: &'b [(usize, usize)],
) -> Perhaps<Rect> {
let mut area = to.area;
let mut area = to.area();
area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16;
let offset = 3 + scene_name_max_len(state.scenes.as_ref()) as u16;
let tracks = state.tracks.as_ref();
@ -53,13 +53,13 @@ struct ColumnSeparators<'a>(u16, &'a [(usize, usize)]);
impl<'a> Render<Tui> for ColumnSeparators<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let area = to.area();
let Self(offset, cols) = self;
let style = Some(Style::default().fg(Nord::SEPARATOR));
for (_, x) in cols.iter() {
let x = offset + area.x + *x as u16 - 1;
for y in area.y..area.height+area.y {
"".blit(to.buffer, x, y, style)?;
to.blit(&"", x, y, style)?;
}
}
Ok(Some(area))
@ -70,15 +70,15 @@ struct RowSeparators<'a>(&'a [(usize, usize)]);
impl<'a> Render<Tui> for RowSeparators<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
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 {
if y >= to.buffer().area.height {
break
}
for x in area.x..area.width+area.y-2 {
let cell = to.buffer.get_mut(x, y);
let cell = to.buffer().get_mut(x, y);
cell.modifier = Modifier::UNDERLINED;
cell.underline_color = Nord::SEPARATOR;
}
@ -93,7 +93,7 @@ struct CursorFocus<'a>(
impl<'a> Render<Tui> for CursorFocus<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
let mut area = to.area();
let Self(selected, offset, cols, rows) = *self;
let get_track_area = |t: usize| Rect {
x: offset + area.x + cols[t].1 as u16 - 1,
@ -118,7 +118,7 @@ impl<'a> Render<Tui> for CursorFocus<'a> {
let mut clip_area: Option<Rect> = None;
let area = match selected {
ArrangerFocus::Mix => {
fill_bg(to.buffer, area, COLOR_BG0);
to.fill_bg(area, COLOR_BG0);
area
},
ArrangerFocus::Track(t) => {
@ -137,21 +137,21 @@ impl<'a> Render<Tui> for CursorFocus<'a> {
},
};
if let Some(Rect { x, y, width, height }) = track_area {
fill_fg(to.buffer, Rect { x, y, width: 1, height }, COLOR_BG5);
fill_fg(to.buffer, Rect { x: x + width, y, width: 1, height }, COLOR_BG5);
to.fill_fg(Rect { x, y, width: 1, height }, COLOR_BG5);
to.fill_fg(Rect { x: x + width, y, width: 1, height }, COLOR_BG5);
}
if let Some(Rect { y, height, .. }) = scene_area {
fill_ul(to.buffer, Rect { x: area.x, y: y - 1, width: area.width, height: 1 }, COLOR_BG5);
fill_ul(to.buffer, Rect { x: area.x, y: y + height - 1, width: area.width, height: 1 }, COLOR_BG5);
to.fill_ul(Rect { x: area.x, y: y - 1, width: area.width, height: 1 }, COLOR_BG5);
to.fill_ul(Rect { x: area.x, y: y + height - 1, width: area.width, height: 1 }, COLOR_BG5);
}
if let Some(clip_area) = clip_area {
fill_bg(to.buffer, clip_area, COLOR_BG0);
to.fill_bg(clip_area, COLOR_BG0);
} else if let Some(track_area) = track_area {
fill_bg(to.buffer, track_area, COLOR_BG0);
to.fill_bg(track_area, COLOR_BG0);
} else if let Some(scene_area) = scene_area {
fill_bg(to.buffer, scene_area, COLOR_BG0);
to.fill_bg(scene_area, COLOR_BG0);
}
Ok(area)
Ok(Some(area))
}
}
@ -159,7 +159,7 @@ struct TracksHeader<'a>(u16, &'a[(usize, usize)], &'a [Sequencer]);
impl<'a> Render<Tui> for TracksHeader<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area;
let area = to.area();
let Self(offset, track_cols, tracks) = *self;
let Rect { y, width, .. } = area;
for (track, (w, x)) in tracks.iter().zip(track_cols) {
@ -168,8 +168,8 @@ impl<'a> Render<Tui> for TracksHeader<'a> {
break
}
let name = track.name.read().unwrap();
fill_bg(to.buffer, Rect { x: offset + x, y, width: *w as u16, height: 2 }, COLOR_BG1);
name.blit(to.buffer, offset + x + 1, y, Some(Style::default().white()))?;
to.fill_bg(Rect { x: offset + x, y, width: *w as u16, height: 2 }, COLOR_BG1);
to.blit(&*name, offset + x + 1, y, Some(Style::default().white()))?;
}
Ok(Some(Rect { x: area.x, y, width, height: 2 }))
}
@ -179,15 +179,15 @@ struct SceneRows<'a>(u16, &'a[(usize, usize)], &'a[(usize, usize)], &'a[Sequence
impl<'a> Render<Tui> for SceneRows<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let area = to.area();
let Self(offset, track_cols, scene_rows, tracks, scenes) = *self;
let black = Some(Style::default().fg(Nord::SEPARATOR));
let Rect { mut y, height, .. } = area;
let Rect { mut y, height: _height, .. } = area;
for (_, x) in track_cols.iter() {
let x = *x as u16;
if x > 0 {
for y in area.y-2..y-2 {
"".blit(to.buffer, x - 1, y, black)?;
to.blit(&"", x - 1, y, black)?;
}
}
}
@ -196,10 +196,8 @@ impl<'a> Render<Tui> for SceneRows<'a> {
//break
//}
let h = 1.max((pulses / 96) as u16);
SceneRow(tracks, scene, track_cols, offset).render(&mut TuiOutput {
buffer: to.buffer,
area: Rect { x: area.x, y, width: area.width, height: h, }
})?;
SceneRow(tracks, scene, track_cols, offset)
.render(to.with_area(area.x, y, area.width, h))?;
y = y + h
}
Ok(Some(area))
@ -210,29 +208,24 @@ struct SceneRow<'a>(&'a[Sequencer], &'a Scene, &'a[(usize, usize)], u16);
impl<'a> Render<Tui> for SceneRow<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area();
let 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()))?;
to.blit(&if playing { "" } else { " " }, x, y, None)?;
to.blit(&*scene.name.read().unwrap(), 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 {
break
}
if let (Some(track), Some(Some(clip))) = (
tracks.get(track), scene.clips.get(track)
) {
SceneClip(track, *clip).render(&mut TuiOutput {
buffer: to.buffer,
area: Rect { x, y, width: *w as u16, height: area.height, }
})?;
SceneClip(track, *clip).render(to.with_area(x, y, *w as u16, area.height))?;
}
}
Ok(Some(area))
}
}
@ -241,20 +234,20 @@ struct SceneClip<'a>(&'a Sequencer, usize);
impl<'a> Render<Tui> for SceneClip<'a> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area;
let area = to.area();
let Self(track, clip) = self;
let style = Some(Style::default().white());
if let Some(phrase) = track.phrases.get(*clip) {
let phrase = phrase.read().unwrap();
let name = phrase.name.read().unwrap();
format!("{clip:02} {name}").blit(to.buffer, area.x + 1, area.y, style)?;
fill_bg(to.buffer, area, if track.sequence == Some(*clip) {
to.blit(&format!("{clip:02} {name}"), area.x + 1, area.y, style)?;
to.fill_bg(area, if track.sequence == Some(*clip) {
Nord::PLAYING
} else {
COLOR_BG1
});
} else {
fill_bg(to.buffer, area, COLOR_BG0)
to.fill_bg(area, COLOR_BG0)
}
Ok(Some(area))
}