fbpr: styles

This commit is contained in:
🪞👃🪞 2024-12-04 18:55:19 +01:00
parent 59d4da1b22
commit d652feb705

View file

@ -21,33 +21,28 @@ pub struct PhraseView<'a> {
impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> { impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
fn from (state: &'a T) -> Self { fn from (state: &'a T) -> Self {
let editor = state.editor(); let editor = state.editor();
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);
let mut note_hi = 127.min(note_lo + height + 1);
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 + 1);
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(),
note_len: editor.note_len, note_len: editor.note_len,
phrase: &editor.phrase, phrase: &editor.phrase,
buffer: &editor.buffer, buffer: &editor.buffer,
now: &editor.now, now: &editor.now,
size: &editor.size, size: &editor.size,
view_mode: &editor.view_mode, view_mode: &editor.view_mode,
note_point, note_point,
note_range: (note_lo, note_hi), note_range: (note_lo, note_hi),
@ -86,7 +81,6 @@ impl<'a> Content for PhraseView<'a> {
let lower_left = format!( let lower_left = format!(
"{note_lo} {note_lo_name}" "{note_lo} {note_lo_name}"
); );
let mut lower_right = format!( let mut lower_right = format!(
@ -137,20 +131,22 @@ impl<'a> Content for PhraseView<'a> {
}) })
}) })
).fill_x() ).fill_x()
).fill_x().bg(Color::Rgb(40, 50, 30)).border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{ ).fill_x()
Color::Rgb(100, 110, 40) .bg(Color::Rgb(40, 50, 30))
} else { .border(Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(if *focused{
Color::Rgb(70, 80, 50) 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|{ 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_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(); //let playhead_active = playhead_inactive.clone().yellow().bold().not_dim();
//if let Some(_) = phrase { //if let Some(_) = phrase {
//let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length; //let now = now.get() as usize; // TODO FIXME: self.now % phrase.read().unwrap().length;
//let time_clamp = time_clamp; //let time_clamp = time_clamp;
//for x in 0..(time_clamp/time_scale).saturating_sub(*time_start) { //for x in 0..(time_clamp/time_zoom).saturating_sub(*time_start) {
//let this_step = time_start + (x + 0) * time_scale; //let this_step = time_start + (x + 0) * time_zoom;
//let next_step = time_start + (x + 1) * time_scale; //let next_step = time_start + (x + 1) * time_zoom;
//let x = to.area().x() + x as u16; //let x = to.area().x() + x as u16;
//let active = this_step <= now && now < next_step; //let active = this_step <= now && now < next_step;
//let character = if active { "|" } else { "·" }; //let character = if active { "|" } else { "·" };
@ -239,7 +235,6 @@ impl PhraseViewMode {
//let source_y = (note_hi - y) % source.height.max(1); //let source_y = (note_hi - y) % source.height.max(1);
if source_x < source.width && source_y < source.height { if source_x < source.width && source_y < source.height {
let target_cell = target.get_mut(target_x, target_y); 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) { if let Some(source_cell) = source.get(source_x, source_y) {
*target_cell = source_cell.clone(); *target_cell = source_cell.clone();
} }
@ -251,7 +246,7 @@ impl PhraseViewMode {
} }
} }
fn blit_keys (&self, to: &mut TuiOutput, note_hi: usize, note_lo: usize) { 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 { match self {
Self::PianoHorizontal { .. } => { Self::PianoHorizontal { .. } => {
let [x0, y0, _, h] = to.area().xywh(); let [x0, y0, _, h] = to.area().xywh();
@ -281,22 +276,27 @@ impl PhraseViewMode {
to: &mut TuiOutput, to: &mut TuiOutput,
time_point: usize, time_point: usize,
time_start: usize, time_start: usize,
time_scale: usize, time_zoom: usize,
note_point: usize, note_point: usize,
note_len: usize, note_len: usize,
note_hi: usize, note_hi: usize,
note_lo: usize, note_lo: usize,
) { ) {
let style = Some(Style::default().fg(Color::Rgb(0,255,0)));
match self { match self {
Self::PianoHorizontal { .. } => { 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() { 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_scale; let time_1 = time_start + x as usize * time_zoom;
let time_2 = time_1 + time_scale; let time_2 = time_1 + time_zoom;
if time_1 <= time_point && time_point < time_2 { 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 break
} }
} }
@ -347,6 +347,7 @@ impl PhraseViewMode {
//'·' //'·'
//}); //});
//cell.set_fg(Color::Rgb(48, 64, 56)); //cell.set_fg(Color::Rgb(48, 64, 56));
let style = Style::default().fg(Color::Rgb(255, 255, 255));
let mut notes_on = [false;128]; let mut notes_on = [false;128];
for (y, _) in (127..0).enumerate() { for (y, _) in (127..0).enumerate() {
for (x, _) in (0..phrase.length).step_by(time_zoom).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_fg(Color::Rgb(255, 255, 255));
cell.set_bg(Color::Rgb(0, 0, 0)); cell.set_bg(Color::Rgb(0, 0, 0));
cell.set_char('▄'); cell.set_char('▄');
cell.set_style(style);
} else { } else {
cell.set_char('x'); cell.set_char('x');
} }
@ -372,7 +374,9 @@ impl PhraseViewMode {
match event { match event {
MidiMessage::NoteOn { key, .. } => { MidiMessage::NoteOn { key, .. } => {
let note = key.as_int() as usize; 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 notes_on[note] = true
}, },
MidiMessage::NoteOff { key, .. } => { MidiMessage::NoteOff { key, .. } => {