fbpr: align cursor/keys/notes

This commit is contained in:
🪞👃🪞 2024-12-06 01:32:36 +01:00
parent 2561e5221d
commit b70d7a08a6
2 changed files with 18 additions and 24 deletions

View file

@ -56,7 +56,7 @@ impl Default for PhraseEditorModel {
size: Measure::new(), size: Measure::new(),
edit_mode: PhraseEditMode::Scroll, edit_mode: PhraseEditMode::Scroll,
note_lo: 0.into(), note_lo: 0.into(),
note_point: 24.into(), note_point: 0.into(),
time_start: 0.into(), time_start: 0.into(),
time_point: 0.into(), time_point: 0.into(),
time_scale: 24.into(), time_scale: 24.into(),

View file

@ -22,16 +22,16 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
let height = editor.size.h(); let height = editor.size.h();
let note_point = editor.note_point.load(Ordering::Relaxed); let note_point = editor.note_point.load(Ordering::Relaxed);
let mut note_lo = editor.note_lo.load(Ordering::Relaxed); let mut note_lo = editor.note_lo.load(Ordering::Relaxed);
if note_point < note_lo { //if note_point < note_lo {
note_lo = note_point; //note_lo = note_point;
editor.note_lo.store(note_lo, Ordering::Relaxed); //editor.note_lo.store(note_lo, Ordering::Relaxed);
} //}
let mut note_hi = 127.min(note_lo + height); let mut note_hi = 127.min((note_lo + height).saturating_sub(2));
if note_point > note_hi { //if note_point > note_hi {
note_lo += note_point - note_hi; //note_lo += note_point - note_hi;
note_hi = note_point; //note_hi = note_point;
editor.note_lo.store(note_lo, Ordering::Relaxed); //editor.note_lo.store(note_lo, Ordering::Relaxed);
} //}
Self { Self {
focused: state.editor_focused(), focused: state.editor_focused(),
entered: state.editor_entered(), entered: state.editor_entered(),
@ -105,20 +105,14 @@ impl<'a> Content for PhraseView<'a> {
lay!( lay!(
row!( row!(
Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{ Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{
Ok(if to.area().h() >= 2 { Ok(if to.area().h() >= 2 { view_mode.render_keys(to, *note_hi, *note_lo) })
view_mode.render_keys(to, *note_hi, *note_lo) }).fill_y().push_y(1),
})
}).fill_y(),
lay!( lay!(
Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{ Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{
size.set_wh(to.area.w(), to.area.h() as usize - 1); size.set_wh(to.area.w(), to.area.h() as usize - 1);
let draw = to.area().h() >= 2; let draw = to.area().h() >= 2;
Ok(if draw { Ok(if draw { view_mode.render_notes(to, buffer, *time_start, *note_hi) })
view_mode.render_notes( }).fill_x().push_y(1),
to, buffer, *time_start, *note_hi
)
})
}).fill_x(),
Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{ Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{
Ok(if *focused && *entered { Ok(if *focused && *entered {
view_mode.render_cursor( view_mode.render_cursor(
@ -127,7 +121,7 @@ impl<'a> Content for PhraseView<'a> {
*note_point, *note_len, *note_hi, *note_lo, *note_point, *note_len, *note_hi, *note_lo,
) )
}) })
}) }).push_y(1)
).fill_x() ).fill_x()
) )
.fill_x() .fill_x()
@ -247,7 +241,7 @@ impl PhraseViewMode {
match self { match self {
Self::PianoHorizontal { .. } => { Self::PianoHorizontal { .. } => {
let [x0, y0, _, h] = to.area().xywh(); let [x0, y0, _, h] = to.area().xywh();
for (y, note) in (note_lo..note_hi).rev().enumerate() { for (y, note) in (note_lo..=note_hi).rev().enumerate() {
to.blit(&match note % 12 { to.blit(&match note % 12 {
11 => "██", 11 => "██",
10 => " ", 10 => " ",
@ -283,7 +277,7 @@ impl PhraseViewMode {
match self { match self {
Self::PianoHorizontal { .. } => { Self::PianoHorizontal { .. } => {
let [x0, y0, w, _] = to.area().xywh(); let [x0, y0, w, _] = to.area().xywh();
for (y, note) in (note_lo..note_hi).rev().enumerate() { for (y, note) in (note_lo..=note_hi).rev().enumerate() {
if note == note_point { if note == note_point {
for x in 0..w { for x in 0..w {
let time_1 = time_start + x as usize * time_zoom; let time_1 = time_start + x as usize * time_zoom;