From d652feb70584b297ef59a3c0d29c090180a8202f Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 4 Dec 2024 18:55:19 +0100 Subject: [PATCH] fbpr: styles --- crates/tek_tui/src/tui_view_phrase_editor.rs | 66 +++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/crates/tek_tui/src/tui_view_phrase_editor.rs b/crates/tek_tui/src/tui_view_phrase_editor.rs index 9840d01b..7047c1f7 100644 --- a/crates/tek_tui/src/tui_view_phrase_editor.rs +++ b/crates/tek_tui/src/tui_view_phrase_editor.rs @@ -21,33 +21,28 @@ pub struct PhraseView<'a> { impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> { fn from (state: &'a T) -> Self { let editor = state.editor(); - let height = editor.size.h(); - let note_point = editor.note_point.load(Ordering::Relaxed); - let mut note_lo = editor.note_lo.load(Ordering::Relaxed); + let mut note_hi = 127.min(note_lo + height + 1); 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 + 1); 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(), - note_len: editor.note_len, - phrase: &editor.phrase, - buffer: &editor.buffer, - now: &editor.now, - size: &editor.size, - view_mode: &editor.view_mode, + focused: state.editor_focused(), + entered: state.editor_entered(), + note_len: editor.note_len, + phrase: &editor.phrase, + buffer: &editor.buffer, + now: &editor.now, + size: &editor.size, + view_mode: &editor.view_mode, note_point, note_range: (note_lo, note_hi), @@ -86,7 +81,6 @@ impl<'a> Content for PhraseView<'a> { let lower_left = format!( "{note_lo} {note_lo_name}" - ); let mut lower_right = format!( @@ -137,20 +131,22 @@ impl<'a> Content for PhraseView<'a> { }) }) ).fill_x() - ).fill_x().bg(Color::Rgb(40, 50, 30)).border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{ - Color::Rgb(100, 110, 40) - } else { - Color::Rgb(70, 80, 50) - }))), + ).fill_x() + .bg(Color::Rgb(40, 50, 30)) + .border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{ + Color::Rgb(100, 110, 40) + } else { + Color::Rgb(70, 80, 50) + }))), CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{ //let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30)); //let playhead_active = playhead_inactive.clone().yellow().bold().not_dim(); //if let Some(_) = phrase { //let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length; //let time_clamp = time_clamp; - //for x in 0..(time_clamp/time_scale).saturating_sub(*time_start) { - //let this_step = time_start + (x + 0) * time_scale; - //let next_step = time_start + (x + 1) * time_scale; + //for x in 0..(time_clamp/time_zoom).saturating_sub(*time_start) { + //let this_step = time_start + (x + 0) * time_zoom; + //let next_step = time_start + (x + 1) * time_zoom; //let x = to.area().x() + x as u16; //let active = this_step <= now && now < next_step; //let character = if active { "|" } else { "·" }; @@ -239,7 +235,6 @@ impl PhraseViewMode { //let source_y = (note_hi - y) % source.height.max(1); if source_x < source.width && source_y < source.height { let target_cell = target.get_mut(target_x, target_y); - target_cell.set_char('x'); if let Some(source_cell) = source.get(source_x, source_y) { *target_cell = source_cell.clone(); } @@ -251,7 +246,7 @@ impl PhraseViewMode { } } fn blit_keys (&self, to: &mut TuiOutput, note_hi: usize, note_lo: usize) { - let style = Some(Style::default().fg(Color::White).bg(Color::Rgb(0, 0, 0))); + let style = Some(Style::default().fg(Color::Rgb(192, 192, 192)).bg(Color::Rgb(0, 0, 0))); match self { Self::PianoHorizontal { .. } => { let [x0, y0, _, h] = to.area().xywh(); @@ -281,22 +276,27 @@ impl PhraseViewMode { to: &mut TuiOutput, time_point: usize, time_start: usize, - time_scale: usize, + time_zoom: usize, note_point: usize, note_len: usize, note_hi: usize, note_lo: usize, ) { + let style = Some(Style::default().fg(Color::Rgb(0,255,0))); match self { Self::PianoHorizontal { .. } => { - let [x0, y0, w, h] = to.area().xywh(); + let [x0, y0, w, _] = to.area().xywh(); 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_scale; - let time_2 = time_1 + time_scale; + let time_1 = time_start + x as usize * time_zoom; + let time_2 = time_1 + time_zoom; if time_1 <= time_point && time_point < time_2 { - to.blit(&"█", x0 + x as u16, y0 + y as u16, None); + to.blit(&"█", x0 + x as u16, y0 + y as u16, style); + let tail = note_len as u16 / time_zoom as u16; + for x_tail in (x0 + x + 1)..(x0 + x + tail) { + to.blit(&"▄", x_tail, y0 + y as u16, style); + } break } } @@ -347,6 +347,7 @@ impl PhraseViewMode { //'·' //}); //cell.set_fg(Color::Rgb(48, 64, 56)); + let style = Style::default().fg(Color::Rgb(255, 255, 255)); let mut notes_on = [false;128]; for (y, _) in (127..0).enumerate() { for (x, _) in (0..phrase.length).step_by(time_zoom).enumerate() { @@ -364,6 +365,7 @@ impl PhraseViewMode { cell.set_fg(Color::Rgb(255, 255, 255)); cell.set_bg(Color::Rgb(0, 0, 0)); cell.set_char('▄'); + cell.set_style(style); } else { cell.set_char('x'); } @@ -372,7 +374,9 @@ impl PhraseViewMode { match event { MidiMessage::NoteOn { key, .. } => { let note = key.as_int() as usize; - target.get_mut(x, 127 - note).unwrap().set_char('█'); + let cell = target.get_mut(x, 127 - note).unwrap(); + cell.set_char('█'); + cell.set_style(style); notes_on[note] = true }, MidiMessage::NoteOff { key, .. } => {