add align_s/n; position playhead

This commit is contained in:
🪞👃🪞 2024-10-22 01:10:35 +03:00
parent 61992ab2a2
commit 9cd9131d5d
5 changed files with 79 additions and 104 deletions

View file

@ -43,16 +43,7 @@ impl Content for PhrasePool<Tui> {
let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)};
let title = format!("Phrases ({})", phrases.len());
let title = TuiStyle::fg(title, title_color).push_x(1);
Layers::new(move|add|{
add(&content)?;
add(&title)?;
//if self.focused {
//let commands = "[A]ppend [I]nsert [D]uplicate [C]olor re[N]ame leng[T]h [,.] Move";
//let lower_left = Align::SW(TuiStyle::fg(commands, title_color).push_x(1));
//add(&lower_left)?;
//}
Ok(())
})
Layers::new(move|add|{ add(&content)?; add(&title)?; Ok(()) })
}
}
impl Content for PhraseEditor<Tui> {
@ -75,26 +66,6 @@ impl Content for PhraseEditor<Tui> {
}
Ok(())
}).fill_y();
let playhead = CustomWidget::new(|_|Ok(Some([32u16,2u16])), move|to: &mut TuiOutput|{
if let Some(_) = phrase {
let time_0 = time_axis.start;
let time_z = time_axis.scale;
let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length;
let [x, y, width, _] = to.area();
let x2 = x as usize + Self::H_KEYS_OFFSET;
let x3 = x as usize + width as usize;
for x in x2..x3 {
let step = (time_0 + x2) * time_z;
let next_step = (time_0 + x2 + 1) * time_z;
let mut style = Style::default();
if step <= now && now < next_step {
style = style.yellow().bold().not_dim()
}
to.blit(&"-", x as u16, y, Some(style));
}
}
Ok(())
}).fill_x();
let notes = CustomWidget::new(|_|Ok(Some([32u16,4u16])), move|to: &mut TuiOutput|{
if to.area().h() >= 2 && to.area().w() >= offset {
let area = to.area().push_x(offset).shrink_x(offset);
@ -124,32 +95,45 @@ impl Content for PhraseEditor<Tui> {
}
Ok(())
});
let playhead = CustomWidget::new(|_|Ok(Some([32u16,2u16])), move|to: &mut TuiOutput|{
if let Some(_) = phrase {
let time_0 = time_axis.start;
let time_z = time_axis.scale;
let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length;
let [x, y, width, _] = to.area();
let x2 = x as usize + Self::H_KEYS_OFFSET;
let x3 = x as usize + width as usize;
for x in x2..x3 {
let step = (time_0 + x2) * time_z;
let next_step = (time_0 + x2 + 1) * time_z;
let mut style = Style::default().fg(Color::Rgb(255,255,255));
if step <= now && now < next_step {
style = style.yellow().bold().not_dim()
}
to.blit(&"-", x as u16, y, Some(style));
}
}
Ok(())
}).align_sw().fill_xy().push_xy(1, 1);
let border_color = if *focused{Color::Rgb(100, 110, 40)}else{Color::Rgb(70, 80, 50)};
let title_color = if *focused{Color::Rgb(150, 160, 90)}else{Color::Rgb(120, 130, 100)};
let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color));
let piano_roll = lay!(keys, playhead, notes, cursor).fill_x();
let piano_roll = lay!(keys, notes, cursor).fill_x();
let content_bg = Color::Rgb(40, 50, 30);
let content = piano_roll.bg(content_bg).border(border);
let mut upper_left = String::from("Sequencer");
let mut lower_left = String::new();
let mut lower_right = format!("Zoom: {}", ppq_to_name(time_axis.scale));
if let Some(phrase) = phrase {
upper_left = format!("{upper_left}: {}", phrase.read().unwrap().name);
}
if *focused {
if *entered {
//lower_left = "[Esc] Exit edit mode [A]ppend [S]et".to_string();
lower_right = format!("[,.] Note: {} [<>] {lower_right}", ppq_to_name(*note_len));
} else {
//lower_left = "[Enter] Edit notes".to_string();
lower_right = format!("[,.] {lower_right}");
}
let mut upper_right = format!("Zoom: {}", ppq_to_name(time_axis.scale));
if *focused && *entered {
upper_right = format!("Note: {} {upper_right}", ppq_to_name(*note_len));
}
lay!(
content,
playhead,
TuiStyle::fg(upper_left.to_string(), title_color).push_x(1).align_nw().fill_xy(),
TuiStyle::fg(lower_left.to_string(), title_color).push_x(1).align_sw().fill_xy(),
TuiStyle::fg(lower_right.to_string(), title_color).pull_x(1).align_se().fill_xy(),
TuiStyle::fg(upper_right.to_string(), title_color).pull_x(1).align_ne().fill_xy(),
)
}
}