phrase list select and append/insert

This commit is contained in:
🪞👃🪞 2024-10-10 09:44:28 +03:00
parent 333e8bf98a
commit dc3edc86ff
2 changed files with 27 additions and 4 deletions

View file

@ -22,6 +22,10 @@ pub enum SequencerFocus { Transport, PhrasePool, PhraseEditor }
/// Contains all phrases in a project
pub struct PhrasePool<E: Engine> {
_engine: PhantomData<E>,
/// Scroll offset
pub scroll: usize,
/// Highlighted phrase
pub phrase: usize,
/// Phrases in the pool
pub phrases: Vec<Arc<RwLock<Option<Phrase>>>>,
/// Whether this widget is focused
@ -120,6 +124,8 @@ impl<E: Engine> PhrasePool<E> {
pub fn new () -> Self {
Self {
_engine: Default::default(),
scroll: 0,
phrase: 0,
phrases: vec![Arc::new(RwLock::new(Some(Phrase::default())))],
focused: false
}

View file

@ -45,8 +45,13 @@ impl Content for PhrasePool<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
col!(
"Phrases:",
col!((i, phrase) in self.phrases.iter().enumerate() => format!("{i}"))
"Phrases:".fill_x().fixed_y(2),
col!((i, phrase) in self.phrases.iter().enumerate() =>
format!("{i}").fixed_y(2).bg(if i == self.phrase {
Color::Rgb(40, 50, 30)
} else {
Color::Rgb(28, 35, 25)
}))
)
.fill_xy()
.bg(Color::Rgb(28, 35, 25))
@ -62,8 +67,20 @@ impl Content for PhrasePool<Tui> {
impl Handle<Tui> for PhrasePool<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
match from.event() {
key!(KeyCode::Up) => todo!(),
key!(KeyCode::Down) => todo!(),
key!(KeyCode::Up) => self.phrase = if self.phrase > 0 {
self.phrase - 1
} else {
self.phrases.len() - 1
},
key!(KeyCode::Down) => {
self.phrase = (self.phrase + 1) % self.phrases.len()
},
key!(KeyCode::Char('i')) => {
self.phrases.insert(self.phrase, Arc::new(RwLock::new(Some(Phrase::default()))))
},
key!(KeyCode::Char('a')) => {
self.phrases.push(Arc::new(RwLock::new(Some(Phrase::default()))))
},
_ => return Ok(None),
}
return Ok(Some(true))