From b70d7a08a6e171d868c2b0444d4bb3b75b2a4639 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 6 Dec 2024 01:32:36 +0100 Subject: [PATCH] fbpr: align cursor/keys/notes --- crates/tek_tui/src/tui_model_phrase_editor.rs | 2 +- crates/tek_tui/src/tui_view_phrase_editor.rs | 40 ++++++++----------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/crates/tek_tui/src/tui_model_phrase_editor.rs b/crates/tek_tui/src/tui_model_phrase_editor.rs index 214ec26a..8e5a7d3d 100644 --- a/crates/tek_tui/src/tui_model_phrase_editor.rs +++ b/crates/tek_tui/src/tui_model_phrase_editor.rs @@ -56,7 +56,7 @@ impl Default for PhraseEditorModel { size: Measure::new(), edit_mode: PhraseEditMode::Scroll, note_lo: 0.into(), - note_point: 24.into(), + note_point: 0.into(), time_start: 0.into(), time_point: 0.into(), time_scale: 24.into(), diff --git a/crates/tek_tui/src/tui_view_phrase_editor.rs b/crates/tek_tui/src/tui_view_phrase_editor.rs index 46e1fcc3..ec9a5514 100644 --- a/crates/tek_tui/src/tui_view_phrase_editor.rs +++ b/crates/tek_tui/src/tui_view_phrase_editor.rs @@ -22,16 +22,16 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> { let height = editor.size.h(); let note_point = editor.note_point.load(Ordering::Relaxed); let mut note_lo = editor.note_lo.load(Ordering::Relaxed); - if note_point < note_lo { - note_lo = note_point; - editor.note_lo.store(note_lo, Ordering::Relaxed); - } - let mut note_hi = 127.min(note_lo + height); - if note_point > note_hi { - note_lo += note_point - note_hi; - note_hi = note_point; - editor.note_lo.store(note_lo, Ordering::Relaxed); - } + //if note_point < note_lo { + //note_lo = note_point; + //editor.note_lo.store(note_lo, Ordering::Relaxed); + //} + let mut note_hi = 127.min((note_lo + height).saturating_sub(2)); + //if note_point > note_hi { + //note_lo += note_point - note_hi; + //note_hi = note_point; + //editor.note_lo.store(note_lo, Ordering::Relaxed); + //} Self { focused: state.editor_focused(), entered: state.editor_entered(), @@ -105,20 +105,14 @@ impl<'a> Content for PhraseView<'a> { lay!( row!( Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{ - Ok(if to.area().h() >= 2 { - view_mode.render_keys(to, *note_hi, *note_lo) - }) - }).fill_y(), + Ok(if to.area().h() >= 2 { view_mode.render_keys(to, *note_hi, *note_lo) }) + }).fill_y().push_y(1), lay!( Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{ size.set_wh(to.area.w(), to.area.h() as usize - 1); let draw = to.area().h() >= 2; - Ok(if draw { - view_mode.render_notes( - to, buffer, *time_start, *note_hi - ) - }) - }).fill_x(), + Ok(if draw { view_mode.render_notes(to, buffer, *time_start, *note_hi) }) + }).fill_x().push_y(1), Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{ Ok(if *focused && *entered { view_mode.render_cursor( @@ -127,7 +121,7 @@ impl<'a> Content for PhraseView<'a> { *note_point, *note_len, *note_hi, *note_lo, ) }) - }) + }).push_y(1) ).fill_x() ) .fill_x() @@ -247,7 +241,7 @@ impl PhraseViewMode { match self { Self::PianoHorizontal { .. } => { 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 { 11 => "██", 10 => " ", @@ -283,7 +277,7 @@ impl PhraseViewMode { match self { Self::PianoHorizontal { .. } => { 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 { for x in 0..w { let time_1 = time_start + x as usize * time_zoom;