diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 0f9a8809..76ab9281 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -17,7 +17,7 @@ impl Point for [N;2] { fn y (&self) -> N { self[1] } } -pub trait Area { +pub trait Area: Copy { fn x (&self) -> N; fn y (&self) -> N; fn w (&self) -> N; diff --git a/crates/tek_sequencer/src/arranger_rename.rs b/crates/tek_sequencer/src/arranger_rename.rs index c438ccc9..9df36554 100644 --- a/crates/tek_sequencer/src/arranger_rename.rs +++ b/crates/tek_sequencer/src/arranger_rename.rs @@ -34,13 +34,8 @@ impl ArrangerRenameModal { impl Render for ArrangerRenameModal { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let area = to.area(); - let y = area.y + area.height / 2; - let bg_area = Rect { - x: 1, - y: y - 1, - width: area.width - 2, - height: 3 - }; + let y = area.y() + area.h() / 2; + let bg_area = [1, y - 1, area.w() - 2, 3]; to.fill_bg(bg_area, Nord::BG0); Lozenge(Style::default().bold().white().dim()).draw(to.with_rect(bg_area)); let label = match self.target { @@ -50,11 +45,11 @@ impl Render for ArrangerRenameModal { ArrangerFocus::Clip(_, _) => "Rename clip:", }; let style = Some(Style::default().not_bold().white().not_dim()); - to.blit(&label, area.x + 3, y, style)?; + to.blit(&label, area.x() + 3, y, style)?; let style = Some(Style::default().bold().white().not_dim()); - to.blit(&self.value, area.x + 3 + label.len() as u16 + 1, y, style)?; + to.blit(&self.value, area.x() + 3 + label.len() as u16 + 1, y, style)?; let style = Some(Style::default().bold().white().not_dim().reversed()); - to.blit(&"▂", area.x + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style)?; + to.blit(&"▂", area.x() + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style)?; Ok(Some(area)) } } diff --git a/crates/tek_sequencer/src/arranger_view_h.rs b/crates/tek_sequencer/src/arranger_view_h.rs index 105eefa7..8ddeaa24 100644 --- a/crates/tek_sequencer/src/arranger_view_h.rs +++ b/crates/tek_sequencer/src/arranger_view_h.rs @@ -1,8 +1,8 @@ use crate::*; pub fn draw (state: &Arranger, to: &mut Tui) -> Perhaps<[u16;4]> { - let mut area = to.area(); - area.height = area.height.min((2 + state.tracks.len() * 2) as u16); + let area = to.area(); + let area = [area.x(), area.y(), area.w(), area.h().min((2 + state.tracks.len() * 2) as u16)]; let tracks = state.tracks.as_slice(); Layered::new() //.add(FillBg(Nord::bg_lo(state.focused, state.entered))) @@ -22,21 +22,21 @@ struct TrackNameColumn<'a>(&'a [Sequencer], ArrangerFocus); impl<'a> Render for TrackNameColumn<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let Self(tracks, selected) = self; - let mut area = to.area(); let yellow = Some(Style::default().yellow().bold().not_dim()); let white = Some(Style::default().white().bold().not_dim()); - area.width = 3 + 5.max(track_name_max_len(tracks)) as u16; + let area = to.area(); + let area = [area.x(), area.y(), 3 + 5.max(track_name_max_len(tracks)) as u16, area.h()]; let offset = 0; // track scroll offset - for y in 0..area.height { + for y in 0..area.h() { if y == 0 { - to.blit(&"Mixer", area.x + 1, area.y + y, Some(DIM))?; + to.blit(&"Mixer", area.x() + 1, area.y() + y, Some(DIM))?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2 + offset; if let Some(track) = tracks.get(index) { let selected = selected.track() == Some(index); let style = if selected { yellow } else { white }; - to.blit(&format!(" {index:>02} "), area.x, area.y + y, style)?; - to.blit(&*track.name.read().unwrap(), area.x + 4, area.y + y, style)?; + to.blit(&format!(" {index:>02} "), area.x(), area.y() + y, style)?; + to.blit(&*track.name.read().unwrap(), area.x() + 4, area.y() + y, style)?; } } } @@ -53,14 +53,14 @@ impl<'a> Render for TrackMonitorColumn<'a> { let on = Some(Style::default().not_dim().green().bold()); let off = Some(DIM); area.x += 1; - for y in 0..area.height { + for y in 0..area.h() { if y == 0 { //" MON ".blit(to.buffer, area.x, area.y + y, style2)?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2; if let Some(track) = tracks.get(index) { let style = if track.monitoring { on } else { off }; - to.blit(&" MON ", area.x, area.y + y, style)?; + to.blit(&" MON ", area.x(), area.y() + y, style)?; } else { area.height = y; break @@ -81,14 +81,14 @@ impl<'a> Render for TrackRecordColumn<'a> { let on = Some(Style::default().not_dim().red().bold()); let off = Some(Style::default().dim()); area.x += 1; - for y in 0..area.height { + for y in 0..area.h() { if y == 0 { //" REC ".blit(to.buffer, area.x, area.y + y, style2)?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2; if let Some(track) = tracks.get(index) { let style = if track.recording { on } else { off }; - to.blit(&" REC ", area.x, area.y + y, style)?; + to.blit(&" REC ", area.x(), area.y() + y, style)?; } else { area.height = y; break @@ -109,13 +109,13 @@ impl<'a> Render for TrackOverdubColumn<'a> { let on = Some(Style::default().not_dim().yellow().bold()); let off = Some(Style::default().dim()); area.x = area.x + 1; - for y in 0..area.height { + for y in 0..area.h() { if y == 0 { //" OVR ".blit(to.buffer, area.x, area.y + y, style2)?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2; if let Some(track) = tracks.get(index) { - to.blit(&" OVR ", area.x, area.y + y, if track.overdub { + to.blit(&" OVR ", area.x(), area.y() + y, if track.overdub { on } else { off @@ -139,13 +139,13 @@ impl<'a> Render for TrackEraseColumn<'a> { let mut area = to.area(); let off = Some(Style::default().dim()); area.x = area.x + 1; - for y in 0..area.height { + for y in 0..area.h() { if y == 0 { //" DEL ".blit(to.buffer, area.x, area.y + y, style2)?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2; if let Some(_) = tracks.get(index) { - to.blit(&" DEL ", area.x, area.y + y, off)?; + to.blit(&" DEL ", area.x(), area.y() + y, off)?; } else { area.height = y; break @@ -164,14 +164,14 @@ impl<'a> Render for TrackGainColumn<'a> { let Self(tracks) = self; let mut area = to.area(); let off = Some(Style::default().dim()); - area.x = area.x + 1; - for y in 0..area.height { + area.x = area.x() + 1; + for y in 0..area.h() { if y == 0 { //" GAIN ".blit(to.buffer, area.x, area.y + y, style2)?; } else if y % 2 == 0 { let index = (y as usize - 2) / 2; if let Some(_) = tracks.get(index) { - to.blit(&" +0.0 ", area.x, area.y + y, off)?; + to.blit(&" +0.0 ", area.x(), area.y() + y, off)?; } else { area.height = y; break diff --git a/crates/tek_sequencer/src/arranger_view_v.rs b/crates/tek_sequencer/src/arranger_view_v.rs index 68917596..360119ed 100644 --- a/crates/tek_sequencer/src/arranger_view_v.rs +++ b/crates/tek_sequencer/src/arranger_view_v.rs @@ -33,8 +33,8 @@ pub fn draw <'a, 'b> ( cols: &'b [(usize, usize)], rows: &'b [(usize, usize)], ) -> Perhaps<[u16;4]> { - let mut area = to.area(); - area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16; + let area = to.area(); + let area = [area.x(), area.y(), area.w(), 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(); let scenes = state.scenes.as_ref(); @@ -57,8 +57,8 @@ impl<'a> Render for ColumnSeparators<'a> { 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 { + let x = offset + area.x() + *x as u16 - 1; + for y in area.y()..area.y2() { to.blit(&"▎", x, y, style)?; } } @@ -73,11 +73,11 @@ impl<'a> Render for RowSeparators<'a> { let area = to.area(); let Self(rows) = self; for (_, y) in rows.iter() { - let y = area.y + (*y / 96) as u16 + 1; + let y = area.y() + (*y / 96) as u16 + 1; if y >= to.buffer().area.height { break } - for x in area.x..(area.width+area.y).saturating_sub(2) { + for x in area.x()..area.x2().saturating_sub(2) { 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 for CursorFocus<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { - let mut area = to.area(); + let area = to.area(); let Self(selected, offset, cols, rows) = *self; let get_track_area = |t: usize| [ offset + area.x() + cols[t].1 as u16 - 1, diff --git a/crates/tek_sequencer/src/sequencer_view.rs b/crates/tek_sequencer/src/sequencer_view.rs index 4f6e5f8e..669ec239 100644 --- a/crates/tek_sequencer/src/sequencer_view.rs +++ b/crates/tek_sequencer/src/sequencer_view.rs @@ -168,8 +168,10 @@ fn fill_seq_fg (buf: &mut BigBuffer, phrase: &Phrase) -> Usually<()> { } pub(crate) fn keys_vert () -> Buffer { - let area = Rect { x: 0, y: 0, width: 5, height: 64 }; - let mut buffer = Buffer::empty(area); + let area = [0, 0, 5, 64]; + let mut buffer = Buffer::empty(Rect { + x: area.x(), y: area.y(), width: area.w(), height: area.h() + }); buffer_update(&mut buffer, area, &|cell, x, y| { let y = 63 - y; match x { diff --git a/crates/tek_sequencer/src/sequencer_view_h.rs b/crates/tek_sequencer/src/sequencer_view_h.rs index 29b64b05..019113df 100644 --- a/crates/tek_sequencer/src/sequencer_view_h.rs +++ b/crates/tek_sequencer/src/sequencer_view_h.rs @@ -11,13 +11,13 @@ impl Sequencer { .add_ref(&SequenceRange) .add_ref(&SequenceLoopRange) .add_ref(&SequenceNoteRange) - .render(to.with_area(area.x, area.y, area.height, 10))?; - area.x = area.x + 10; - area.width = area.width.saturating_sub(10); - area.height = area.height.min(66); + .render(to.with_area(area.x(), area.y(), area.h(), 10))?; + area.x = area.x() + 10; + area.width = area.w().saturating_sub(10); + area.height = area.h().min(66); Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(area))?; - area.x = area.x + 1; - area.width = area.width.saturating_sub(1); + area.x = area.x() + 1; + area.width = area.w().saturating_sub(1); Layered::new() .add_ref(&SequenceKeys(&self)) .add_ref(&self.phrase.as_ref().map(|phrase|SequenceTimer(&self, phrase.clone()))) @@ -51,7 +51,7 @@ struct SequenceName<'a>(&'a Sequencer); impl<'a> Render for SequenceName<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let [x, y, ..] = to.area(); - let frame = Rect { x, y, width: 10, height: 4 }; + let frame = [x, y, 10, 4]; Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?; to.blit(&"Name:", x + 1, y + 1, STYLE_LABEL)?; to.blit(&*self.0.name.read().unwrap(), x + 1, y + 2, STYLE_VALUE)?; @@ -64,7 +64,7 @@ struct SequenceRange; impl<'a> Render for SequenceRange { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let [x, y, ..] = to.area(); - let frame = Rect { x, y, width: 10, height: 6 }; + let frame = [x, y, 10, 6]; Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?; to.blit(&"Start: ", x + 1, y + 1, STYLE_LABEL)?; to.blit(&" 1.1.1", x + 1, y + 2, STYLE_VALUE)?; @@ -79,7 +79,7 @@ struct SequenceLoopRange; impl<'a> Render for SequenceLoopRange { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let [x, y, ..] = to.area(); - let range = Rect { x, y, width: 10, height: 7 }; + let range = [x, y, 10, 7]; Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?; to.blit(&"Loop [ ]", x + 1, y + 1, STYLE_LABEL)?; to.blit(&"From: ", x + 1, y + 2, STYLE_LABEL)?; @@ -95,7 +95,7 @@ struct SequenceNoteRange; impl<'a> Render for SequenceNoteRange { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let [x, y, ..] = to.area(); - let range = Rect { x, y, width: 10, height: 9 }; + let range = [x, y, 10, 9]; Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?; to.blit(&"Notes: ", x + 1, y + 1, STYLE_LABEL)?; to.blit(&"C#0-C#9 ", x + 1, y + 2, STYLE_VALUE)?; @@ -113,15 +113,10 @@ struct SequenceKeys<'a>(&'a Sequencer); impl<'a> Render for SequenceKeys<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let area = to.area(); - if area.height < 2 { + if area.h() < 2 { return Ok(Some(area)) } - let area = Rect { - x: area.x, - y: area.y + 1, - width: 5, - height: area.height - 2 - }; + let area = [area.x(), area.y() + 1, 5, area.h() - 2]; buffer_update(to.buffer(), area, &|cell, x, y|{ let y = y + self.0.note_axis.start as u16; if x < self.0.keys.area.width && y < self.0.keys.area.height { @@ -137,15 +132,15 @@ struct SequenceNotes<'a>(&'a Sequencer); impl<'a> Render for SequenceNotes<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let area = to.area(); - if area.height < 2 { + if area.h() < 2 { return Ok(Some(area)) } - let area = Rect { - x: area.x + Sequencer::H_KEYS_OFFSET as u16, - y: area.y + 1, - width: area.width.saturating_sub(Sequencer::H_KEYS_OFFSET as u16), - height: area.height.saturating_sub(2), - }; + let area = [ + area.x() + Sequencer::H_KEYS_OFFSET as u16, + area.y() + 1, + area.w().saturating_sub(Sequencer::H_KEYS_OFFSET as u16), + area.h().saturating_sub(2), + ]; to.buffer_update(area, &move |cell, x, y|{ let src_x = ((x as usize + self.0.time_axis.start) * self.0.time_axis.scale) as usize; let src_y = (y as usize + self.0.note_axis.start) as usize; @@ -167,12 +162,12 @@ impl<'a> Render for SequenceCursor<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let area = to.area(); if let (Some(time), Some(note)) = (self.0.time_axis.point, self.0.note_axis.point) { - let x = area.x + Sequencer::H_KEYS_OFFSET as u16 + time as u16; - let y = area.y + 1 + note as u16 / 2; + let x = area.x() + Sequencer::H_KEYS_OFFSET as u16 + time as u16; + let y = area.y() + 1 + note as u16 / 2; let c = if note % 2 == 0 { "▀" } else { "▄" }; to.blit(&c, x, y, self.0.style_focus()) } else { - Ok(Some(Rect::default())) + Ok(Some([0,0,0,0])) } } } @@ -183,8 +178,8 @@ impl<'a> Render for SequenceZoom<'a> { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { let area = to.area(); let quant = ppq_to_name(self.0.time_axis.scale); - let quant_x = area.x + area.width - 1 - quant.len() as u16; - let quant_y = area.y + area.height - 2; + let quant_x = area.x() + area.w() - 1 - quant.len() as u16; + let quant_y = area.y() + area.h() - 2; to.blit(&quant, quant_x, quant_y, self.0.style_focus()) } } @@ -205,8 +200,8 @@ impl<'a> Render for SequenceTimer<'a> { let step = (time0 + x2) * time_z; let next_step = (time0 + x2 + 1) * time_z; let style = Sequencer::style_timer_step(now, step as usize, next_step as usize); - to.blit(&"-", x as u16, area.y, Some(style))?; + to.blit(&"-", x as u16, area.y(), Some(style))?; } - return Ok(Some(Rect { x: area.x, y: area.y, width: area.width, height: 1 })) + return Ok(Some([area.x(), area.y(), area.w(), 1])) } } diff --git a/crates/tek_sequencer/src/transport_view.rs b/crates/tek_sequencer/src/transport_view.rs index 7e1100a6..c3b1814b 100644 --- a/crates/tek_sequencer/src/transport_view.rs +++ b/crates/tek_sequencer/src/transport_view.rs @@ -4,15 +4,15 @@ const CORNERS: Corners = Corners(NOT_DIM_GREEN); impl Render for TransportToolbar { fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { - let mut area = to.area(); - area.height = 2; + let area = to.area(); + let area = [area.x(), area.y(), area.w(), 2]; let area = Split::right() .add_ref(&self.playing) .add_ref(&self.bpm) .add_ref(&self.quant) .add_ref(&self.sync) .add_ref(&self.clock) - .render(to)?; + .render(to.with_rect(area))?; //if self.is_focused() { //fill_bg(buf, area, COLOR_BG0); //CORNERS_DIM.draw(buf, area)?; @@ -38,11 +38,10 @@ impl Render for TransportPlayPauseButton { Some(TransportState::Stopped) => "⏹ STOPPED", _ => unreachable!(), }; - let mut area = to.blit(&label, x + 1, y, style)?.unwrap(); - area.width = area.width + 1; - area.height = area.height + 1; + let area = to.blit(&label, x + 1, y, style)?.unwrap(); + let area = [area.x(), area.y(), area.w() + 1, area.h() + 1]; if *focused { - let area = Rect { x: area.x - 1, width: area.width - 1, ..area }; + let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ]; CORNERS.draw(to)?; to.fill_bg(area, COLOR_BG1); } @@ -59,9 +58,9 @@ impl Render for TransportBPM { let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0); to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD))?; let width = bpm.len() as u16; - let area = Rect { x, y, width: (width + 2).max(10), height: 2 }; + let area = [x, y, (width + 2).max(10), 2]; if *focused { - let area = Rect { x: area.x - 1, width: area.width - 1, ..area }; + let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ]; CORNERS.draw(to)?; to.fill_bg(area, COLOR_BG1); } @@ -77,9 +76,9 @@ impl Render for TransportQuantize { let name = ppq_to_name(*value as usize); let width = name.len() as u16; to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?; - let area = Rect { x, y, width: (width + 2).max(10), height: 2 }; + let area = [x, y, (width + 2).max(10), 2]; if *focused { - let area = Rect { x: area.x - 1, width: area.width - 1, ..area }; + let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ]; CORNERS.draw(to)?; to.fill_bg(area, COLOR_BG1); } @@ -95,9 +94,9 @@ impl Render for TransportSync { let name = ppq_to_name(*value as usize); let width = name.len() as u16; to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?; - let area = Rect { x, y, width: (width + 2).max(10), height: 2 }; + let area = [x, y, (width + 2).max(10), 2]; if *focused { - let area = Rect { x: area.x - 1, width: area.width - 1, ..area }; + let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ]; CORNERS.draw(to)?; to.fill_bg(area, COLOR_BG1); } @@ -117,10 +116,10 @@ impl Render for TransportClock { to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?; let timer = format!("{minutes}:{seconds:02}:{msecs:03}"); to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?; - let mut area = to.area(); - area.width = area.width + 1; + let area = to.area(); + let area = [area.x(), area.y(), area.w() + 1, area.h()]; if *focused { - let area = Rect { x: area.x - 1, ..area }; + let area = [area.x() - 1, area.y(), area.w(), area.h() ]; CORNERS.draw(to)?; to.fill_bg(area, COLOR_BG1); }