sweeeeping sweep

This commit is contained in:
🪞👃🪞 2024-12-31 04:12:09 +01:00
parent c9b09b7dea
commit e677d1d7d4
38 changed files with 766 additions and 691 deletions

View file

@ -3,9 +3,28 @@ use super::note_y_iter;
pub struct PianoHorizontalKeys<'a>(pub(crate) &'a PianoHorizontal);
render!(<Tui>(self: PianoHorizontalKeys<'a>)
|layout|Ok(Some([0, 0])),
|render|Ok(render_keys_v(render, self)));
render!(Tui: |self: PianoHorizontalKeys<'a>, to|{
let state = self.0;
let color = state.color();
let note_lo = state.note_lo().get();
let note_hi = state.note_hi();
let note_point = state.note_point();
let [x, y0, w, h] = to.area().xywh();
let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0)));
let off_style = Some(Style::default().fg(TuiTheme::g(160)));
let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(color.rgb).bold());
for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
to.blit(&to_key(note), x, screen_y, key_style);
if note > 127 {
continue
}
if note == note_point {
to.blit(&format!("{:<5}", to_note_name(note)), x, screen_y, on_style)
} else {
to.blit(&to_note_name(note), x, screen_y, off_style)
};
}
});
has_color!(|self: PianoHorizontalKeys<'a>|self.0.color.base);
@ -21,28 +40,6 @@ impl<'a> NotePoint for PianoHorizontalKeys<'a> {
fn set_note_point (&self, x: usize) { self.0.set_note_point(x) }
}
pub fn render_keys_v <T: HasColor + NoteRange + NotePoint> (to: &mut TuiOutput, state: &T) {
let color = state.color();
let note_lo = state.note_lo().get();
let note_hi = state.note_hi();
let note_point = state.note_point();
let [x, y0, w, h] = to.area().xywh();
let key_style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0)));
let off_style = Some(Style::default().fg(TuiTheme::g(160)));
let on_style = Some(Style::default().fg(TuiTheme::g(255)).bg(color.rgb).bold());
for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
to.blit(&to_key(note), x, screen_y, key_style);
if note > 127 {
continue
}
if note == note_point {
to.blit(&format!("{:<5}", to_note_name(note)), x, screen_y, on_style)
} else {
to.blit(&to_note_name(note), x, screen_y, off_style)
};
}
}
fn to_key (note: usize) -> &'static str {
match note % 12 {
11 => "████▌",