mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
phrase list select and append/insert
This commit is contained in:
parent
333e8bf98a
commit
dc3edc86ff
2 changed files with 27 additions and 4 deletions
|
|
@ -22,6 +22,10 @@ pub enum SequencerFocus { Transport, PhrasePool, PhraseEditor }
|
||||||
/// Contains all phrases in a project
|
/// Contains all phrases in a project
|
||||||
pub struct PhrasePool<E: Engine> {
|
pub struct PhrasePool<E: Engine> {
|
||||||
_engine: PhantomData<E>,
|
_engine: PhantomData<E>,
|
||||||
|
/// Scroll offset
|
||||||
|
pub scroll: usize,
|
||||||
|
/// Highlighted phrase
|
||||||
|
pub phrase: usize,
|
||||||
/// Phrases in the pool
|
/// Phrases in the pool
|
||||||
pub phrases: Vec<Arc<RwLock<Option<Phrase>>>>,
|
pub phrases: Vec<Arc<RwLock<Option<Phrase>>>>,
|
||||||
/// Whether this widget is focused
|
/// Whether this widget is focused
|
||||||
|
|
@ -120,6 +124,8 @@ impl<E: Engine> PhrasePool<E> {
|
||||||
pub fn new () -> Self {
|
pub fn new () -> Self {
|
||||||
Self {
|
Self {
|
||||||
_engine: Default::default(),
|
_engine: Default::default(),
|
||||||
|
scroll: 0,
|
||||||
|
phrase: 0,
|
||||||
phrases: vec![Arc::new(RwLock::new(Some(Phrase::default())))],
|
phrases: vec![Arc::new(RwLock::new(Some(Phrase::default())))],
|
||||||
focused: false
|
focused: false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,13 @@ impl Content for PhrasePool<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
col!(
|
col!(
|
||||||
"Phrases:",
|
"Phrases:".fill_x().fixed_y(2),
|
||||||
col!((i, phrase) in self.phrases.iter().enumerate() => format!("{i}"))
|
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()
|
.fill_xy()
|
||||||
.bg(Color::Rgb(28, 35, 25))
|
.bg(Color::Rgb(28, 35, 25))
|
||||||
|
|
@ -62,8 +67,20 @@ impl Content for PhrasePool<Tui> {
|
||||||
impl Handle<Tui> for PhrasePool<Tui> {
|
impl Handle<Tui> for PhrasePool<Tui> {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
match from.event() {
|
match from.event() {
|
||||||
key!(KeyCode::Up) => todo!(),
|
key!(KeyCode::Up) => self.phrase = if self.phrase > 0 {
|
||||||
key!(KeyCode::Down) => todo!(),
|
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(None),
|
||||||
}
|
}
|
||||||
return Ok(Some(true))
|
return Ok(Some(true))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue