use crate::*; impl Widget for Sampler { type Engine = Tui; fn layout (&self, to: [u16;2]) -> Perhaps<[u16;2]> { todo!() } fn render (&self, to: &mut TuiOutput) -> Usually<()> { tui_render_sampler(self, to) } } pub fn tui_render_sampler (sampler: &Sampler, to: &mut TuiOutput) -> Usually<()> { let [x, y, _, height] = to.area(); let style = Style::default().gray(); let title = format!(" {} ({})", sampler.name, sampler.voices.read().unwrap().len()); to.blit(&title, 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 sampler.mapped.iter() .map(|(note, sample)|(Some(note), sample)) .chain(sampler.unmapped.iter().map(|sample|(None, sample))) { if y1 >= height { break } let active = j == sampler.cursor.0; width = width.max( draw_sample(to, x, y + y1, note, &*sample.read().unwrap(), active)? ); y1 = y1 + 1; j = j + 1; } let height = ((2 + y1) as u16).min(height); //Ok(Some([x, y, (width as u16).min(to.area().w()), height])) Ok(()) } fn draw_sample ( to: &mut TuiOutput, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool ) -> Usually { let style = if focus { Style::default().green() } else { Style::default() }; if focus { to.blit(&"🬴", x+1, y, Some(style.bold())); } let label1 = format!("{:3} {:12}", note.map(|n|n.to_string()).unwrap_or(String::default()), sample.name); let label2 = format!("{:>6} {:>6} +0.0", sample.start, sample.end); to.blit(&label1, x+2, y, Some(style.bold())); to.blit(&label2, x+3+label1.len()as u16, y, Some(style)); Ok(label1.len() + label2.len() + 4) } impl Widget for AddSampleModal { type Engine = Tui; fn layout (&self, to: [u16;2]) -> Perhaps<[u16;2]> { todo!() //Align::Center(()).layout(to) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { todo!() //let area = to.area(); //to.make_dim(); //let area = center_box( //area, //64.max(area.w().saturating_sub(8)), //20.max(area.w().saturating_sub(8)), //); //to.fill_fg(area, Color::Reset); //to.fill_bg(area, Nord::bg_lo(true, true)); //to.fill_char(area, ' '); //to.blit(&format!("{}", &self.dir.to_string_lossy()), area.x()+2, area.y()+1, Some(Style::default().bold()))?; //to.blit(&"Select sample:", area.x()+2, area.y()+2, Some(Style::default().bold()))?; //for (i, (is_dir, name)) in self.subdirs.iter() //.map(|path|(true, path)) //.chain(self.files.iter().map(|path|(false, path))) //.enumerate() //.skip(self.offset) //{ //if i >= area.h() as usize - 4 { //break //} //let t = if is_dir { "" } else { "" }; //let line = format!("{t} {}", name.to_string_lossy()); //let line = &line[..line.len().min(area.w() as usize - 4)]; //to.blit(&line, area.x() + 2, area.y() + 3 + i as u16, Some(if i == self.cursor { //Style::default().green() //} else { //Style::default().white() //}))?; //} //Lozenge(Style::default()).draw(to) } }