browse phrases

This commit is contained in:
🪞👃🪞 2024-06-30 19:38:51 +03:00
parent 625956766e
commit 83830d9cb3
9 changed files with 86 additions and 84 deletions

View file

@ -17,6 +17,7 @@ impl<'a> LauncherGridView<'a> {
//self.separator_h(2, false);
//self.separator_h((self.state.cursor.1 * 2) as u16, true);
//self.separator_h(((self.state.cursor.1 + 1) * 2) as u16, true);
self.area.height = self.state.scenes.len() as u16 + 2;
let style = Some(Style::default().green().dim());
if self.focused {
let Rect { x, y, width, height } = self.area;
@ -37,19 +38,19 @@ impl<'a> LauncherGridView<'a> {
}
let (mut x, y) = (self.area.x, self.area.y);
for (i, column) in columns.iter().enumerate() {
for (i, title) in columns.iter().enumerate() {
if x >= self.area.x + self.area.width {
break
}
column.blit(
self.buf, x + 2, y, Some(self.highlight(i == self.state.cursor.0).bold())
title.blit(
self.buf, x+1, y, Some(self.highlight(i == self.state.cursor.0).bold())
);
if i == 0 {
self.scenes(x + 2, y + 1);
self.scenes(x+1, y + 1);
} else if i < columns.len() {
self.clips(x + 2, y + 1, i - 1);
self.clips(x+1, y + 1, i - 1);
}
let w = (column.len() as u16).max(12) + 3;
let w = (title.len() as u16).max(10) + 3;
x = x + w;
}
@ -66,10 +67,10 @@ impl<'a> LauncherGridView<'a> {
}
fn column_widths (&self) -> Vec<u16> {
self.column_names().iter().map(|name|(name.len() as u16).max(12) + 3).collect()
self.column_names().iter().map(|name|(name.len() as u16).max(10) + 3).collect()
}
fn scenes (&mut self, x: u16, y: u16) {
fn scenes (&mut self, x: u16, y: u16) -> u16 {
let mut index = 0usize;
loop {
if index >= self.state.scenes.len() {
@ -79,12 +80,11 @@ impl<'a> LauncherGridView<'a> {
break
}
if let Some(scene) = self.state.scenes.get(index) {
format!("{}", scene.name).blit(
self.buf, x, y + index as u16,
Some(self.highlight(
(0 == self.state.cursor.0) && (index + 1 == self.state.cursor.1)
).bold())
)
let style = Some(self.highlight(
(0 == self.state.cursor.0) && (index + 1 == self.state.cursor.1)
).bold());
"".blit(self.buf, x, y + index as u16, style);
scene.name.blit(self.buf, x+1, y + index as u16, style);
}
index = index + 1;
}
@ -95,9 +95,10 @@ impl<'a> LauncherGridView<'a> {
} else {
Style::default().dim()
}));
index as u16
}
fn clips (&mut self, x: u16, y: u16, track: usize) {
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
let mut index = 0;
loop {
if index >= self.state.scenes.len() {
@ -114,9 +115,9 @@ impl<'a> LauncherGridView<'a> {
let index = index as u16;
let label = if let Some(Some(clip)) = clip {
let track = self.state.tracks[track].sequencer.state();
let phrase = track.sequences.get(*clip);
let phrase = track.phrases.get(*clip);
if let Some(phrase) = phrase {
format!(" {}", phrase.name)
format!("{}", phrase.name)
} else {
format!("????")
}
@ -134,6 +135,7 @@ impl<'a> LauncherGridView<'a> {
} else {
Style::default().dim()
}));
index as u16
}
fn highlight (&self, highlight: bool) -> Style {