mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +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
|
|
@ -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<Tui> 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<Tui> 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<Tui> 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<Tui> 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<Tui> 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<Tui> 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<Tui> 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<Tui> 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<Tui> 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]))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue