mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
34 lines
1.4 KiB
Rust
34 lines
1.4 KiB
Rust
use crate::*;
|
|
use super::note_y_iter;
|
|
|
|
pub struct PianoHorizontalNotes<'a>(pub(crate) &'a PianoHorizontal);
|
|
|
|
render!(<Tui>(self: PianoHorizontalNotes<'a>)
|
|
|layout|Ok(Some([0, 0])),
|
|
|render|Ok({
|
|
let time_start = self.0.time_start().get();
|
|
let note_lo = self.0.note_lo().get();
|
|
let note_hi = self.0.note_hi();
|
|
let note_point = self.0.note_point();
|
|
let source = &self.0.buffer;
|
|
let [x0, y0, w, h] = render.area().xywh();
|
|
if h as usize != self.0.note_axis().get() {
|
|
panic!("area height mismatch");
|
|
}
|
|
for (area_x, screen_x) in (x0..x0+w).enumerate() {
|
|
for (area_y, screen_y, note) in note_y_iter(note_lo, note_hi, y0) {
|
|
let source_x = time_start + area_x;
|
|
let source_y = note_hi - area_y;
|
|
// TODO: enable loop rollover:
|
|
//let source_x = (time_start + area_x) % source.width.max(1);
|
|
//let source_y = (note_hi - area_y) % source.height.max(1);
|
|
let is_in_x = source_x < source.width;
|
|
let is_in_y = source_y < source.height;
|
|
if is_in_x && is_in_y {
|
|
if let Some(source_cell) = source.get(source_x, source_y) {
|
|
*render.buffer.get_mut(screen_x, screen_y) = source_cell.clone();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}));
|