mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
wip: render: remove render! macro
This commit is contained in:
parent
bf165c6be1
commit
1d4db3c629
13 changed files with 337 additions and 304 deletions
|
|
@ -15,30 +15,34 @@ pub struct Sampler {
|
|||
}
|
||||
|
||||
process!(Sampler = Sampler::process);
|
||||
|
||||
handle!(Sampler |self, event| handle_keymap(self, event, KEYMAP_SAMPLER));
|
||||
render!(Sampler |self, buf, area| {
|
||||
let Rect { x, y, height, .. } = area;
|
||||
let style = Style::default().gray();
|
||||
let title = format!(" {} ({})", self.name, self.voices.read().unwrap().len());
|
||||
title.blit(buf, x+1, y, Some(style.white().bold().not_dim()))?;
|
||||
let mut width = title.len() + 2;
|
||||
let mut y1 = 1;
|
||||
let mut j = 0;
|
||||
for (note, sample) in self.mapped.iter()
|
||||
.map(|(note, sample)|(Some(note), sample))
|
||||
.chain(self.unmapped.iter().map(|sample|(None, sample)))
|
||||
{
|
||||
if y1 >= height {
|
||||
break
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for Sampler {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Usually<Rect> {
|
||||
let Rect { x, y, height, .. } = area;
|
||||
let style = Style::default().gray();
|
||||
let title = format!(" {} ({})", self.name, self.voices.read().unwrap().len());
|
||||
title.blit(buf, x+1, y, Some(style.white().bold().not_dim()))?;
|
||||
let mut width = title.len() + 2;
|
||||
let mut y1 = 1;
|
||||
let mut j = 0;
|
||||
for (note, sample) in self.mapped.iter()
|
||||
.map(|(note, sample)|(Some(note), sample))
|
||||
.chain(self.unmapped.iter().map(|sample|(None, sample)))
|
||||
{
|
||||
if y1 >= height {
|
||||
break
|
||||
}
|
||||
let active = j == self.cursor.0;
|
||||
width = width.max(draw_sample(buf, x, y + y1, note, &*sample.read().unwrap(), active)?);
|
||||
y1 = y1 + 1;
|
||||
j = j + 1;
|
||||
}
|
||||
let active = j == self.cursor.0;
|
||||
width = width.max(draw_sample(buf, x, y + y1, note, &*sample.read().unwrap(), active)?);
|
||||
y1 = y1 + 1;
|
||||
j = j + 1;
|
||||
let height = ((2 + y1) as u16).min(height);
|
||||
Ok(Rect { x, y, width: (width as u16).min(area.width), height })
|
||||
}
|
||||
let height = ((2 + y1) as u16).min(height);
|
||||
Ok(Rect { x, y, width: (width as u16).min(area.width), height })
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_sample (
|
||||
buf: &mut Buffer, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue