mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
big ass refactor (rip client)
This commit is contained in:
parent
94c1f83ef2
commit
8c3cf53c67
56 changed files with 2232 additions and 1891 deletions
|
|
@ -1,169 +0,0 @@
|
|||
use crate::core::*;
|
||||
use super::*;
|
||||
pub struct SceneGrid<'a> {
|
||||
pub buf: &'a mut Buffer,
|
||||
pub area: Rect,
|
||||
pub name: &'a str,
|
||||
pub focused: bool,
|
||||
pub scenes: &'a[Scene],
|
||||
pub tracks: &'a[Track],
|
||||
pub cursor: &'a(usize, usize),
|
||||
}
|
||||
impl<'a> SceneGrid<'a> {
|
||||
pub fn new (
|
||||
buf: &'a mut Buffer,
|
||||
area: Rect,
|
||||
name: &'a str,
|
||||
focused: bool,
|
||||
scenes: &'a[Scene],
|
||||
tracks: &'a[Track],
|
||||
cursor: &'a(usize, usize),
|
||||
) -> Self {
|
||||
Self {
|
||||
buf,
|
||||
area,
|
||||
name,
|
||||
focused,
|
||||
scenes,
|
||||
tracks,
|
||||
cursor,
|
||||
}
|
||||
}
|
||||
pub fn draw (&mut self) -> Usually<Rect> {
|
||||
self.area.height = self.scenes.len() as u16 + 2;
|
||||
let style = Some(Style::default().green().dim());
|
||||
if self.focused {
|
||||
let Rect { x, y, width, height } = self.area;
|
||||
lozenge_left(self.buf, x, y, height, style);
|
||||
lozenge_right(self.buf, x + width - 1, y, height, style);
|
||||
}
|
||||
let columns = self.column_names();
|
||||
let mut x = self.area.x;
|
||||
for (i, w) in self.column_widths().iter().enumerate() {
|
||||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
self.separator_v(x, i == self.cursor.0);
|
||||
x = x + w;
|
||||
self.separator_v(x, i == self.cursor.0);
|
||||
}
|
||||
let (mut x, y) = (self.area.x, self.area.y);
|
||||
for (i, title) in columns.iter().enumerate() {
|
||||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
title.blit(
|
||||
self.buf, x+1, y, Some(self.highlight(i == self.cursor.0).bold())
|
||||
);
|
||||
if i == 0 {
|
||||
self.scenes(x+1, y + 1);
|
||||
} else if i < columns.len() {
|
||||
self.clips(x+1, y + 1, i - 1);
|
||||
}
|
||||
let w = (title.len() as u16).max(10) + 3;
|
||||
x = x + w;
|
||||
}
|
||||
"+Add track…".blit(self.buf, x + 2, y, Some(Style::default().dim()));
|
||||
Ok(self.area)
|
||||
}
|
||||
|
||||
fn column_names (&self) -> Vec<&'a str> {
|
||||
let mut column_names = vec![self.name];
|
||||
for track in self.tracks.iter() {
|
||||
column_names.push(track.name.as_str());
|
||||
}
|
||||
column_names
|
||||
}
|
||||
|
||||
fn column_widths (&self) -> Vec<u16> {
|
||||
self.column_names().iter().map(|name|(name.len() as u16).max(10) + 3).collect()
|
||||
}
|
||||
|
||||
fn scenes (&mut self, x: u16, y: u16) -> u16 {
|
||||
let mut index = 0usize;
|
||||
loop {
|
||||
if index >= self.scenes.len() {
|
||||
break
|
||||
}
|
||||
if y + index as u16 >= self.area.height {
|
||||
break
|
||||
}
|
||||
if let Some(scene) = self.scenes.get(index) {
|
||||
let style = Some(self.highlight(
|
||||
(0 == self.cursor.0) && (index + 1 == self.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;
|
||||
}
|
||||
let hi = (0 == self.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
"+Add scene…".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
Style::default().dim()
|
||||
}));
|
||||
index as u16
|
||||
}
|
||||
|
||||
fn clips (&mut self, x: u16, y: u16, track: usize) -> u16 {
|
||||
let mut index = 0;
|
||||
loop {
|
||||
if index >= self.scenes.len() {
|
||||
break
|
||||
}
|
||||
if y + index as u16 >= self.area.height {
|
||||
break
|
||||
}
|
||||
if let Some(scene) = self.scenes.get(index) {
|
||||
let hi = (track + 1 == self.cursor.0) &&
|
||||
(index + 1 == self.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.tracks[track].sequencer.state();
|
||||
let phrase = track.phrases.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.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
" + Add clip".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
Style::default().dim()
|
||||
}));
|
||||
index as u16
|
||||
}
|
||||
|
||||
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_v (&mut self, x: u16, highlight: bool) {
|
||||
let style = Some(self.highlight(highlight));
|
||||
for y in self.area.y+1..self.area.y+self.area.height-1 {
|
||||
"┊".blit(self.buf, x, y, style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue