mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
big worky on sequencer and launcher
This commit is contained in:
parent
a4c3593840
commit
8a8d7b8704
14 changed files with 852 additions and 680 deletions
157
src/device/launcher/grid.rs
Normal file
157
src/device/launcher/grid.rs
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
use crate::prelude::*;
|
||||
use super::*;
|
||||
pub struct LauncherGridView<'a> {
|
||||
state: &'a Launcher,
|
||||
buf: &'a mut Buffer,
|
||||
area: Rect,
|
||||
focused: bool,
|
||||
separator: String
|
||||
}
|
||||
impl<'a> LauncherGridView<'a> {
|
||||
pub fn new (state: &'a Launcher, buf: &'a mut Buffer, area: Rect, focused: bool) -> Self {
|
||||
let separator = format!("├{}┤", "-".repeat((area.width - 2).into()));
|
||||
Self { state, buf, area, separator, focused }
|
||||
}
|
||||
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);
|
||||
let columns = self.column_names();
|
||||
|
||||
let (mut x, y) = (self.area.x, self.area.y);
|
||||
for (i, w) in self.column_widths().iter().enumerate() {
|
||||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
self.separator_v(x, i == self.state.cursor.0);
|
||||
x = x + w;
|
||||
self.separator_v(x, i == self.state.cursor.0);
|
||||
}
|
||||
|
||||
let (mut x, y) = (self.area.x, self.area.y);
|
||||
for (i, column) in columns.iter().enumerate() {
|
||||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
column.blit(
|
||||
self.buf, x + 2, y + 1, Some(self.highlight(i == self.state.cursor.0).bold())
|
||||
);
|
||||
if i == 0 {
|
||||
self.scenes(x + 2, y + 3);
|
||||
} else if i < columns.len() {
|
||||
self.clips(x + 2, y + 3, 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()));
|
||||
draw_box_styled(self.buf, self.area, Some(self.highlight(self.focused)));
|
||||
Ok(self.area)
|
||||
}
|
||||
|
||||
fn column_names (&self) -> Vec<&'a str> {
|
||||
let mut columns = vec![self.state.name.as_str()];
|
||||
for track in self.state.tracks.iter() {
|
||||
columns.push(track.name.as_str());
|
||||
}
|
||||
columns
|
||||
}
|
||||
|
||||
fn column_widths (&self) -> Vec<u16> {
|
||||
self.column_names().iter().map(|name|(name.len() as u16).max(12) + 3).collect()
|
||||
}
|
||||
|
||||
fn scenes (&mut self, x: u16, y: u16) {
|
||||
let mut y2 = 0;
|
||||
loop {
|
||||
if y2 >= self.area.height {
|
||||
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
|
||||
}
|
||||
}
|
||||
y2 = y2 + 1;
|
||||
}
|
||||
"+Add scene…".blit(self.buf, x, y + y2, Some(Style::default().dim()));
|
||||
}
|
||||
|
||||
fn clips (&mut self, x: u16, y: u16, track: usize) {
|
||||
let mut y2 = 0;
|
||||
loop {
|
||||
if y2 >= self.area.height {
|
||||
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));
|
||||
if let Some(Some(clip)) = scene.clips.get(track) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
y2 = y2 + 1;
|
||||
}
|
||||
"+Add clip…".blit(self.buf, x, y + y2, Some(Style::default().dim()));
|
||||
}
|
||||
|
||||
fn highlight (&self, highlight: bool) -> Style {
|
||||
if highlight {
|
||||
if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
}
|
||||
} else {
|
||||
Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn separator_h (&mut self, y: u16, highlight: bool) {
|
||||
let style = Some(self.highlight(highlight));
|
||||
self.separator.blit(self.buf, self.area.x, self.area.y + y, style);
|
||||
}
|
||||
|
||||
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, y, style);
|
||||
}
|
||||
"┴".blit(self.buf, x, self.area.y+self.area.height-1, style);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue