mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor: down to 50 errors
considering whether to implement layout methods on Area
This commit is contained in:
parent
06f8bd1116
commit
7bcd40b425
7 changed files with 77 additions and 86 deletions
|
|
@ -17,7 +17,7 @@ impl<N: Number> Point<N> for [N;2] {
|
||||||
fn y (&self) -> N { self[1] }
|
fn y (&self) -> N { self[1] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Area<N: Number> {
|
pub trait Area<N: Number>: Copy {
|
||||||
fn x (&self) -> N;
|
fn x (&self) -> N;
|
||||||
fn y (&self) -> N;
|
fn y (&self) -> N;
|
||||||
fn w (&self) -> N;
|
fn w (&self) -> N;
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,8 @@ impl ArrangerRenameModal {
|
||||||
impl Render<Tui> for ArrangerRenameModal {
|
impl Render<Tui> for ArrangerRenameModal {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let y = area.y + area.height / 2;
|
let y = area.y() + area.h() / 2;
|
||||||
let bg_area = Rect {
|
let bg_area = [1, y - 1, area.w() - 2, 3];
|
||||||
x: 1,
|
|
||||||
y: y - 1,
|
|
||||||
width: area.width - 2,
|
|
||||||
height: 3
|
|
||||||
};
|
|
||||||
to.fill_bg(bg_area, Nord::BG0);
|
to.fill_bg(bg_area, Nord::BG0);
|
||||||
Lozenge(Style::default().bold().white().dim()).draw(to.with_rect(bg_area));
|
Lozenge(Style::default().bold().white().dim()).draw(to.with_rect(bg_area));
|
||||||
let label = match self.target {
|
let label = match self.target {
|
||||||
|
|
@ -50,11 +45,11 @@ impl Render<Tui> for ArrangerRenameModal {
|
||||||
ArrangerFocus::Clip(_, _) => "Rename clip:",
|
ArrangerFocus::Clip(_, _) => "Rename clip:",
|
||||||
};
|
};
|
||||||
let style = Some(Style::default().not_bold().white().not_dim());
|
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());
|
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());
|
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))
|
Ok(Some(area))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub fn draw (state: &Arranger<Tui>, to: &mut Tui) -> Perhaps<[u16;4]> {
|
pub fn draw (state: &Arranger<Tui>, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let mut area = to.area();
|
let area = to.area();
|
||||||
area.height = area.height.min((2 + state.tracks.len() * 2) as u16);
|
let area = [area.x(), area.y(), area.w(), area.h().min((2 + state.tracks.len() * 2) as u16)];
|
||||||
let tracks = state.tracks.as_slice();
|
let tracks = state.tracks.as_slice();
|
||||||
Layered::new()
|
Layered::new()
|
||||||
//.add(FillBg(Nord::bg_lo(state.focused, state.entered)))
|
//.add(FillBg(Nord::bg_lo(state.focused, state.entered)))
|
||||||
|
|
@ -22,21 +22,21 @@ struct TrackNameColumn<'a>(&'a [Sequencer], ArrangerFocus);
|
||||||
impl<'a> Render<Tui> for TrackNameColumn<'a> {
|
impl<'a> Render<Tui> for TrackNameColumn<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let Self(tracks, selected) = self;
|
let Self(tracks, selected) = self;
|
||||||
let mut area = to.area();
|
|
||||||
let yellow = Some(Style::default().yellow().bold().not_dim());
|
let yellow = Some(Style::default().yellow().bold().not_dim());
|
||||||
let white = Some(Style::default().white().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
|
let offset = 0; // track scroll offset
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
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 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2 + offset;
|
let index = (y as usize - 2) / 2 + offset;
|
||||||
if let Some(track) = tracks.get(index) {
|
if let Some(track) = tracks.get(index) {
|
||||||
let selected = selected.track() == Some(index);
|
let selected = selected.track() == Some(index);
|
||||||
let style = if selected { yellow } else { white };
|
let style = if selected { yellow } else { white };
|
||||||
to.blit(&format!(" {index:>02} "), area.x, 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)?;
|
to.blit(&*track.name.read().unwrap(), area.x() + 4, area.y() + y, style)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,14 +53,14 @@ impl<'a> Render<Tui> for TrackMonitorColumn<'a> {
|
||||||
let on = Some(Style::default().not_dim().green().bold());
|
let on = Some(Style::default().not_dim().green().bold());
|
||||||
let off = Some(DIM);
|
let off = Some(DIM);
|
||||||
area.x += 1;
|
area.x += 1;
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
//" MON ".blit(to.buffer, area.x, area.y + y, style2)?;
|
//" MON ".blit(to.buffer, area.x, area.y + y, style2)?;
|
||||||
} else if y % 2 == 0 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2;
|
let index = (y as usize - 2) / 2;
|
||||||
if let Some(track) = tracks.get(index) {
|
if let Some(track) = tracks.get(index) {
|
||||||
let style = if track.monitoring { on } else { off };
|
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 {
|
} else {
|
||||||
area.height = y;
|
area.height = y;
|
||||||
break
|
break
|
||||||
|
|
@ -81,14 +81,14 @@ impl<'a> Render<Tui> for TrackRecordColumn<'a> {
|
||||||
let on = Some(Style::default().not_dim().red().bold());
|
let on = Some(Style::default().not_dim().red().bold());
|
||||||
let off = Some(Style::default().dim());
|
let off = Some(Style::default().dim());
|
||||||
area.x += 1;
|
area.x += 1;
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
//" REC ".blit(to.buffer, area.x, area.y + y, style2)?;
|
//" REC ".blit(to.buffer, area.x, area.y + y, style2)?;
|
||||||
} else if y % 2 == 0 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2;
|
let index = (y as usize - 2) / 2;
|
||||||
if let Some(track) = tracks.get(index) {
|
if let Some(track) = tracks.get(index) {
|
||||||
let style = if track.recording { on } else { off };
|
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 {
|
} else {
|
||||||
area.height = y;
|
area.height = y;
|
||||||
break
|
break
|
||||||
|
|
@ -109,13 +109,13 @@ impl<'a> Render<Tui> for TrackOverdubColumn<'a> {
|
||||||
let on = Some(Style::default().not_dim().yellow().bold());
|
let on = Some(Style::default().not_dim().yellow().bold());
|
||||||
let off = Some(Style::default().dim());
|
let off = Some(Style::default().dim());
|
||||||
area.x = area.x + 1;
|
area.x = area.x + 1;
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
//" OVR ".blit(to.buffer, area.x, area.y + y, style2)?;
|
//" OVR ".blit(to.buffer, area.x, area.y + y, style2)?;
|
||||||
} else if y % 2 == 0 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2;
|
let index = (y as usize - 2) / 2;
|
||||||
if let Some(track) = tracks.get(index) {
|
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
|
on
|
||||||
} else {
|
} else {
|
||||||
off
|
off
|
||||||
|
|
@ -139,13 +139,13 @@ impl<'a> Render<Tui> for TrackEraseColumn<'a> {
|
||||||
let mut area = to.area();
|
let mut area = to.area();
|
||||||
let off = Some(Style::default().dim());
|
let off = Some(Style::default().dim());
|
||||||
area.x = area.x + 1;
|
area.x = area.x + 1;
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
//" DEL ".blit(to.buffer, area.x, area.y + y, style2)?;
|
//" DEL ".blit(to.buffer, area.x, area.y + y, style2)?;
|
||||||
} else if y % 2 == 0 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2;
|
let index = (y as usize - 2) / 2;
|
||||||
if let Some(_) = tracks.get(index) {
|
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 {
|
} else {
|
||||||
area.height = y;
|
area.height = y;
|
||||||
break
|
break
|
||||||
|
|
@ -164,14 +164,14 @@ impl<'a> Render<Tui> for TrackGainColumn<'a> {
|
||||||
let Self(tracks) = self;
|
let Self(tracks) = self;
|
||||||
let mut area = to.area();
|
let mut area = to.area();
|
||||||
let off = Some(Style::default().dim());
|
let off = Some(Style::default().dim());
|
||||||
area.x = area.x + 1;
|
area.x = area.x() + 1;
|
||||||
for y in 0..area.height {
|
for y in 0..area.h() {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
//" GAIN ".blit(to.buffer, area.x, area.y + y, style2)?;
|
//" GAIN ".blit(to.buffer, area.x, area.y + y, style2)?;
|
||||||
} else if y % 2 == 0 {
|
} else if y % 2 == 0 {
|
||||||
let index = (y as usize - 2) / 2;
|
let index = (y as usize - 2) / 2;
|
||||||
if let Some(_) = tracks.get(index) {
|
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 {
|
} else {
|
||||||
area.height = y;
|
area.height = y;
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ pub fn draw <'a, 'b> (
|
||||||
cols: &'b [(usize, usize)],
|
cols: &'b [(usize, usize)],
|
||||||
rows: &'b [(usize, usize)],
|
rows: &'b [(usize, usize)],
|
||||||
) -> Perhaps<[u16;4]> {
|
) -> Perhaps<[u16;4]> {
|
||||||
let mut area = to.area();
|
let area = to.area();
|
||||||
area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16;
|
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 offset = 3 + scene_name_max_len(state.scenes.as_ref()) as u16;
|
||||||
let tracks = state.tracks.as_ref();
|
let tracks = state.tracks.as_ref();
|
||||||
let scenes = state.scenes.as_ref();
|
let scenes = state.scenes.as_ref();
|
||||||
|
|
@ -57,8 +57,8 @@ impl<'a> Render<Tui> for ColumnSeparators<'a> {
|
||||||
let Self(offset, cols) = self;
|
let Self(offset, cols) = self;
|
||||||
let style = Some(Style::default().fg(Nord::SEPARATOR));
|
let style = Some(Style::default().fg(Nord::SEPARATOR));
|
||||||
for (_, x) in cols.iter() {
|
for (_, x) in cols.iter() {
|
||||||
let x = offset + area.x + *x as u16 - 1;
|
let x = offset + area.x() + *x as u16 - 1;
|
||||||
for y in area.y..area.height+area.y {
|
for y in area.y()..area.y2() {
|
||||||
to.blit(&"▎", x, y, style)?;
|
to.blit(&"▎", x, y, style)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,11 +73,11 @@ impl<'a> Render<Tui> for RowSeparators<'a> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let Self(rows) = self;
|
let Self(rows) = self;
|
||||||
for (_, y) in rows.iter() {
|
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 {
|
if y >= to.buffer().area.height {
|
||||||
break
|
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);
|
let cell = to.buffer().get_mut(x, y);
|
||||||
cell.modifier = Modifier::UNDERLINED;
|
cell.modifier = Modifier::UNDERLINED;
|
||||||
cell.underline_color = Nord::SEPARATOR;
|
cell.underline_color = Nord::SEPARATOR;
|
||||||
|
|
@ -93,7 +93,7 @@ struct CursorFocus<'a>(
|
||||||
|
|
||||||
impl<'a> Render<Tui> for CursorFocus<'a> {
|
impl<'a> Render<Tui> for CursorFocus<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
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 Self(selected, offset, cols, rows) = *self;
|
||||||
let get_track_area = |t: usize| [
|
let get_track_area = |t: usize| [
|
||||||
offset + area.x() + cols[t].1 as u16 - 1,
|
offset + area.x() + cols[t].1 as u16 - 1,
|
||||||
|
|
|
||||||
|
|
@ -168,8 +168,10 @@ fn fill_seq_fg (buf: &mut BigBuffer, phrase: &Phrase) -> Usually<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn keys_vert () -> Buffer {
|
pub(crate) fn keys_vert () -> Buffer {
|
||||||
let area = Rect { x: 0, y: 0, width: 5, height: 64 };
|
let area = [0, 0, 5, 64];
|
||||||
let mut buffer = Buffer::empty(area);
|
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| {
|
buffer_update(&mut buffer, area, &|cell, x, y| {
|
||||||
let y = 63 - y;
|
let y = 63 - y;
|
||||||
match x {
|
match x {
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ impl Sequencer {
|
||||||
.add_ref(&SequenceRange)
|
.add_ref(&SequenceRange)
|
||||||
.add_ref(&SequenceLoopRange)
|
.add_ref(&SequenceLoopRange)
|
||||||
.add_ref(&SequenceNoteRange)
|
.add_ref(&SequenceNoteRange)
|
||||||
.render(to.with_area(area.x, area.y, area.height, 10))?;
|
.render(to.with_area(area.x(), area.y(), area.h(), 10))?;
|
||||||
area.x = area.x + 10;
|
area.x = area.x() + 10;
|
||||||
area.width = area.width.saturating_sub(10);
|
area.width = area.w().saturating_sub(10);
|
||||||
area.height = area.height.min(66);
|
area.height = area.h().min(66);
|
||||||
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(area))?;
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(area))?;
|
||||||
area.x = area.x + 1;
|
area.x = area.x() + 1;
|
||||||
area.width = area.width.saturating_sub(1);
|
area.width = area.w().saturating_sub(1);
|
||||||
Layered::new()
|
Layered::new()
|
||||||
.add_ref(&SequenceKeys(&self))
|
.add_ref(&SequenceKeys(&self))
|
||||||
.add_ref(&self.phrase.as_ref().map(|phrase|SequenceTimer(&self, phrase.clone())))
|
.add_ref(&self.phrase.as_ref().map(|phrase|SequenceTimer(&self, phrase.clone())))
|
||||||
|
|
@ -51,7 +51,7 @@ struct SequenceName<'a>(&'a Sequencer);
|
||||||
impl<'a> Render<Tui> for SequenceName<'a> {
|
impl<'a> Render<Tui> for SequenceName<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let [x, y, ..] = to.area();
|
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))?;
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?;
|
||||||
to.blit(&"Name:", x + 1, y + 1, STYLE_LABEL)?;
|
to.blit(&"Name:", x + 1, y + 1, STYLE_LABEL)?;
|
||||||
to.blit(&*self.0.name.read().unwrap(), x + 1, y + 2, STYLE_VALUE)?;
|
to.blit(&*self.0.name.read().unwrap(), x + 1, y + 2, STYLE_VALUE)?;
|
||||||
|
|
@ -64,7 +64,7 @@ struct SequenceRange;
|
||||||
impl<'a> Render<Tui> for SequenceRange {
|
impl<'a> Render<Tui> for SequenceRange {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let [x, y, ..] = to.area();
|
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))?;
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?;
|
||||||
to.blit(&"Start: ", x + 1, y + 1, STYLE_LABEL)?;
|
to.blit(&"Start: ", x + 1, y + 1, STYLE_LABEL)?;
|
||||||
to.blit(&" 1.1.1", x + 1, y + 2, STYLE_VALUE)?;
|
to.blit(&" 1.1.1", x + 1, y + 2, STYLE_VALUE)?;
|
||||||
|
|
@ -79,7 +79,7 @@ struct SequenceLoopRange;
|
||||||
impl<'a> Render<Tui> for SequenceLoopRange {
|
impl<'a> Render<Tui> for SequenceLoopRange {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let [x, y, ..] = to.area();
|
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))?;
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?;
|
||||||
to.blit(&"Loop [ ]", x + 1, y + 1, STYLE_LABEL)?;
|
to.blit(&"Loop [ ]", x + 1, y + 1, STYLE_LABEL)?;
|
||||||
to.blit(&"From: ", x + 1, y + 2, STYLE_LABEL)?;
|
to.blit(&"From: ", x + 1, y + 2, STYLE_LABEL)?;
|
||||||
|
|
@ -95,7 +95,7 @@ struct SequenceNoteRange;
|
||||||
impl<'a> Render<Tui> for SequenceNoteRange {
|
impl<'a> Render<Tui> for SequenceNoteRange {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let [x, y, ..] = to.area();
|
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))?;
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?;
|
||||||
to.blit(&"Notes: ", x + 1, y + 1, STYLE_LABEL)?;
|
to.blit(&"Notes: ", x + 1, y + 1, STYLE_LABEL)?;
|
||||||
to.blit(&"C#0-C#9 ", x + 1, y + 2, STYLE_VALUE)?;
|
to.blit(&"C#0-C#9 ", x + 1, y + 2, STYLE_VALUE)?;
|
||||||
|
|
@ -113,15 +113,10 @@ struct SequenceKeys<'a>(&'a Sequencer);
|
||||||
impl<'a> Render<Tui> for SequenceKeys<'a> {
|
impl<'a> Render<Tui> for SequenceKeys<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
if area.height < 2 {
|
if area.h() < 2 {
|
||||||
return Ok(Some(area))
|
return Ok(Some(area))
|
||||||
}
|
}
|
||||||
let area = Rect {
|
let area = [area.x(), area.y() + 1, 5, area.h() - 2];
|
||||||
x: area.x,
|
|
||||||
y: area.y + 1,
|
|
||||||
width: 5,
|
|
||||||
height: area.height - 2
|
|
||||||
};
|
|
||||||
buffer_update(to.buffer(), area, &|cell, x, y|{
|
buffer_update(to.buffer(), area, &|cell, x, y|{
|
||||||
let y = y + self.0.note_axis.start as u16;
|
let y = y + self.0.note_axis.start as u16;
|
||||||
if x < self.0.keys.area.width && y < self.0.keys.area.height {
|
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<Tui> for SequenceNotes<'a> {
|
impl<'a> Render<Tui> for SequenceNotes<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
if area.height < 2 {
|
if area.h() < 2 {
|
||||||
return Ok(Some(area))
|
return Ok(Some(area))
|
||||||
}
|
}
|
||||||
let area = Rect {
|
let area = [
|
||||||
x: area.x + Sequencer::H_KEYS_OFFSET as u16,
|
area.x() + Sequencer::H_KEYS_OFFSET as u16,
|
||||||
y: area.y + 1,
|
area.y() + 1,
|
||||||
width: area.width.saturating_sub(Sequencer::H_KEYS_OFFSET as u16),
|
area.w().saturating_sub(Sequencer::H_KEYS_OFFSET as u16),
|
||||||
height: area.height.saturating_sub(2),
|
area.h().saturating_sub(2),
|
||||||
};
|
];
|
||||||
to.buffer_update(area, &move |cell, x, y|{
|
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_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;
|
let src_y = (y as usize + self.0.note_axis.start) as usize;
|
||||||
|
|
@ -167,12 +162,12 @@ impl<'a> Render<Tui> for SequenceCursor<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
if let (Some(time), Some(note)) = (self.0.time_axis.point, self.0.note_axis.point) {
|
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 x = area.x() + Sequencer::H_KEYS_OFFSET as u16 + time as u16;
|
||||||
let y = area.y + 1 + note as u16 / 2;
|
let y = area.y() + 1 + note as u16 / 2;
|
||||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||||
to.blit(&c, x, y, self.0.style_focus())
|
to.blit(&c, x, y, self.0.style_focus())
|
||||||
} else {
|
} else {
|
||||||
Ok(Some(Rect::default()))
|
Ok(Some([0,0,0,0]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,8 +178,8 @@ impl<'a> Render<Tui> for SequenceZoom<'a> {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let quant = ppq_to_name(self.0.time_axis.scale);
|
let quant = ppq_to_name(self.0.time_axis.scale);
|
||||||
let quant_x = area.x + area.width - 1 - quant.len() as u16;
|
let quant_x = area.x() + area.w() - 1 - quant.len() as u16;
|
||||||
let quant_y = area.y + area.height - 2;
|
let quant_y = area.y() + area.h() - 2;
|
||||||
to.blit(&quant, quant_x, quant_y, self.0.style_focus())
|
to.blit(&quant, quant_x, quant_y, self.0.style_focus())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +200,8 @@ impl<'a> Render<Tui> for SequenceTimer<'a> {
|
||||||
let step = (time0 + x2) * time_z;
|
let step = (time0 + x2) * time_z;
|
||||||
let next_step = (time0 + x2 + 1) * time_z;
|
let next_step = (time0 + x2 + 1) * time_z;
|
||||||
let style = Sequencer::style_timer_step(now, step as usize, next_step as usize);
|
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]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ const CORNERS: Corners = Corners(NOT_DIM_GREEN);
|
||||||
|
|
||||||
impl Render<Tui> for TransportToolbar {
|
impl Render<Tui> for TransportToolbar {
|
||||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||||
let mut area = to.area();
|
let area = to.area();
|
||||||
area.height = 2;
|
let area = [area.x(), area.y(), area.w(), 2];
|
||||||
let area = Split::right()
|
let area = Split::right()
|
||||||
.add_ref(&self.playing)
|
.add_ref(&self.playing)
|
||||||
.add_ref(&self.bpm)
|
.add_ref(&self.bpm)
|
||||||
.add_ref(&self.quant)
|
.add_ref(&self.quant)
|
||||||
.add_ref(&self.sync)
|
.add_ref(&self.sync)
|
||||||
.add_ref(&self.clock)
|
.add_ref(&self.clock)
|
||||||
.render(to)?;
|
.render(to.with_rect(area))?;
|
||||||
//if self.is_focused() {
|
//if self.is_focused() {
|
||||||
//fill_bg(buf, area, COLOR_BG0);
|
//fill_bg(buf, area, COLOR_BG0);
|
||||||
//CORNERS_DIM.draw(buf, area)?;
|
//CORNERS_DIM.draw(buf, area)?;
|
||||||
|
|
@ -38,11 +38,10 @@ impl Render<Tui> for TransportPlayPauseButton {
|
||||||
Some(TransportState::Stopped) => "⏹ STOPPED",
|
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let mut area = to.blit(&label, x + 1, y, style)?.unwrap();
|
let area = to.blit(&label, x + 1, y, style)?.unwrap();
|
||||||
area.width = area.width + 1;
|
let area = [area.x(), area.y(), area.w() + 1, area.h() + 1];
|
||||||
area.height = area.height + 1;
|
|
||||||
if *focused {
|
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)?;
|
CORNERS.draw(to)?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
to.fill_bg(area, COLOR_BG1);
|
||||||
}
|
}
|
||||||
|
|
@ -59,9 +58,9 @@ impl Render<Tui> for TransportBPM {
|
||||||
let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0);
|
let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0);
|
||||||
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD))?;
|
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD))?;
|
||||||
let width = bpm.len() as u16;
|
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 {
|
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)?;
|
CORNERS.draw(to)?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
to.fill_bg(area, COLOR_BG1);
|
||||||
}
|
}
|
||||||
|
|
@ -77,9 +76,9 @@ impl Render<Tui> for TransportQuantize {
|
||||||
let name = ppq_to_name(*value as usize);
|
let name = ppq_to_name(*value as usize);
|
||||||
let width = name.len() as u16;
|
let width = name.len() as u16;
|
||||||
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?;
|
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 {
|
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)?;
|
CORNERS.draw(to)?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
to.fill_bg(area, COLOR_BG1);
|
||||||
}
|
}
|
||||||
|
|
@ -95,9 +94,9 @@ impl Render<Tui> for TransportSync {
|
||||||
let name = ppq_to_name(*value as usize);
|
let name = ppq_to_name(*value as usize);
|
||||||
let width = name.len() as u16;
|
let width = name.len() as u16;
|
||||||
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?;
|
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 {
|
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)?;
|
CORNERS.draw(to)?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
to.fill_bg(area, COLOR_BG1);
|
||||||
}
|
}
|
||||||
|
|
@ -117,10 +116,10 @@ impl Render<Tui> for TransportClock {
|
||||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?;
|
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?;
|
||||||
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
|
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
|
||||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?;
|
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?;
|
||||||
let mut area = to.area();
|
let area = to.area();
|
||||||
area.width = area.width + 1;
|
let area = [area.x(), area.y(), area.w() + 1, area.h()];
|
||||||
if *focused {
|
if *focused {
|
||||||
let area = Rect { x: area.x - 1, ..area };
|
let area = [area.x() - 1, area.y(), area.w(), area.h() ];
|
||||||
CORNERS.draw(to)?;
|
CORNERS.draw(to)?;
|
||||||
to.fill_bg(area, COLOR_BG1);
|
to.fill_bg(area, COLOR_BG1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue