compact launch grid

This commit is contained in:
🪞👃🪞 2024-06-29 20:46:57 +03:00
parent fad0caef88
commit 3886e34519
5 changed files with 75 additions and 90 deletions

View file

@ -15,8 +15,8 @@ impl<'a> LauncherGridView<'a> {
pub fn draw (&mut self) -> Usually<Rect> {
//self.separator_h(0, false);
//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.separator_h((self.state.cursor.1 * 2) as u16, true);
//self.separator_h(((self.state.cursor.1 + 1) * 2) as u16, true);
draw_box_styled(self.buf, self.area, Some(
if self.focused {
Style::default().green().dim()
@ -26,7 +26,7 @@ impl<'a> LauncherGridView<'a> {
));
let columns = self.column_names();
let (mut x, y) = (self.area.x, self.area.y);
let mut x = self.area.x;
for (i, w) in self.column_widths().iter().enumerate() {
if x >= self.area.x + self.area.width {
break
@ -42,18 +42,18 @@ impl<'a> LauncherGridView<'a> {
break
}
column.blit(
self.buf, x + 2, y + 1, Some(self.highlight(i == self.state.cursor.0).bold())
self.buf, x + 2, y, Some(self.highlight(i == self.state.cursor.0).bold())
);
if i == 0 {
self.scenes(x + 2, y + 3);
self.scenes(x + 2, y + 1);
} else if i < columns.len() {
self.clips(x + 2, y + 3, i - 1);
self.clips(x + 2, y + 1, i - 1);
}
let w = (column.len() as u16).max(12) + 3;
x = x + w;
}
"Add track…".blit(self.buf, x + 2, y + 1, Some(Style::default().dim()));
"Add track…".blit(self.buf, x + 2, y, Some(Style::default().dim()));
Ok(self.area)
}
@ -70,85 +70,70 @@ impl<'a> LauncherGridView<'a> {
}
fn scenes (&mut self, x: u16, y: u16) {
let mut y2 = 0;
let mut index = 0usize;
loop {
if y2 >= self.area.height {
if index >= self.state.scenes.len() {
break
}
if y2 % 2 == 0 {
let index = (y2 / 2) as usize;
if let Some(scene) = self.state.scenes.get(index) {
format!("{}", scene.name).blit(
self.buf, x, y + y2,
Some(self.highlight(index + 1 == self.state.cursor.1))
)
} else {
break
}
if y + index as u16 >= self.area.height {
break
}
y2 = y2 + 1;
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())
)
}
index = index + 1;
}
"Add scene…".blit(self.buf, x, y + y2, Some(Style::default().dim()));
let hi = (0 == self.state.cursor.0) &&
(self.state.scenes.len() + 1 == self.state.cursor.1);
"Add scene…".blit(self.buf, x, y + index as u16, Some(if hi {
self.highlight(true)
} else {
Style::default().dim()
}));
}
fn clips (&mut self, x: u16, y: u16, track: usize) {
let mut y2 = 0;
let mut index = 0;
loop {
if y2 >= self.area.height {
if index >= self.state.scenes.len() {
break
}
if y2 % 2 == 0 {
let index = (y2 / 2) as usize;
if index >= self.state.scenes.len() {
break
}
if let Some(scene) = self.state.scenes.get(index) {
let hi = (track + 1 == self.state.cursor.0) &&
(index + 1 == self.state.cursor.1);
let style = Some(self.highlight(hi));
let clip = scene.clips.get(track);
if let Some(Some(clip)) = clip {
if let Some(phrase) = self.state.tracks[track].sequencer.state().sequences.get(*clip) {
format!("{}", phrase.name).blit(self.buf, x, y + y2, style);
} else {
"????".blit(self.buf, x, y + y2, Some(Style::default().dim()))
}
} else {
" ·········".blit(self.buf, x, y + y2, Some(Style::default().dim()))
}
if hi {
draw_box_styled(self.buf, Rect {
x: x - 2,
y: y + y2 - 1,
width: 16,
height: 3
}, style);
if self.focused {
let style = Some(self.highlight(hi).bold().yellow());
if let Some(Some(_)) = clip { } else {
"+ Add clip".blit(self.buf, x + 1, y + y2, Some(Style::default().dim()));
"+".blit(self.buf, x + 1, y + y2, style);
}
"".blit(self.buf, x + 6, y + y2 - 1, style);
"".blit(self.buf, x + 6, y + y2 + 1, style);
",".blit(self.buf, x - 1, y + y2, style);
"".blit(self.buf, x - 2, y + y2, style);
".".blit(self.buf, x + 12, y + y2, style);
"".blit(self.buf, x + 13, y + y2, style);
}
}
}
if y + index as u16 >= self.area.height {
break
}
y2 = y2 + 1;
if let Some(scene) = self.state.scenes.get(index) {
let hi = (track + 1 == self.state.cursor.0) &&
(index + 1 == self.state.cursor.1);
let style = Some(self.highlight(hi));
let clip = scene.clips.get(track);
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);
if let Some(phrase) = phrase {
format!("{}", phrase.name)
} else {
format!("????")
}
} else {
format!(" ·········")
};
label.blit(self.buf, x, y + index, style);
}
index = index + 1;
}
let hi = (track + 1 == self.state.cursor.0) &&
(self.state.scenes.len() + 1 == self.state.cursor.1);
" + Add clip".blit(self.buf, x, y + y2, Some(Style::default().dim()));
if hi {
draw_box_styled(
self.buf, Rect { x: x - 2, y: y + y2 - 1, width: 16, height: 3 }, Some(Style::default().green())
);
}
" + Add clip".blit(self.buf, x, y + index as u16, Some(if hi {
self.highlight(true)
} else {
Style::default().dim()
}));
}
fn highlight (&self, highlight: bool) -> Style {
@ -170,15 +155,11 @@ impl<'a> LauncherGridView<'a> {
fn separator_v (&mut self, x: u16, highlight: bool) {
let style = Some(self.highlight(highlight));
"".blit(self.buf, x, self.area.y + 0, style);
"".blit(self.buf, x, self.area.y + 1, style);
"".blit(self.buf, x, self.area.y + 2, style);
"".blit(self.buf, x, self.area.y + 3, style);
"".blit(self.buf, x, self.area.y + 4, style);
for y in self.area.y+5..self.area.y+self.area.height-1 {
//"┬".blit(self.buf, x, self.area.y + 0, style);
for y in self.area.y+1..self.area.y+self.area.height-1 {
"".blit(self.buf, x, y, style);
}
"".blit(self.buf, x, self.area.y+self.area.height-1, style);
//"┴".blit(self.buf, x, self.area.y+self.area.height-1, style);
}
}