horizontal arranger as split

This commit is contained in:
🪞👃🪞 2024-07-11 22:14:44 +03:00
parent 2c8f4857dd
commit b5df426188

View file

@ -35,15 +35,34 @@ impl<'a> ArrangerView<'a> {
.map(|name|(name.len() as u16).max(10) + 3)
.collect()
}
fn bg_color (&self) -> Color {
if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
}
}
}
impl<'a> Render for ArrangerView<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
if self.vertical {
fn render (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
area.height = area.height.min(if self.vertical {
self.scenes.len() as u16 + 3
} else {
self.tracks.len() as u16 * 2
});
fill_bg(buf, area, self.bg_color());
area = if self.vertical {
self.draw_vertical(buf, area)
} else {
self.draw_horizontal(buf, area)
}?;
if self.focused && self.entered {
QuarterV(Style::default().green().dim()).draw(buf, area)?;
}
Ok(area)
}
}
@ -51,27 +70,8 @@ impl<'a> ArrangerView<'a> {
fn draw_vertical (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
area.height = self.scenes.len() as u16 + 3;
let Rect { x, y, width, height } = area;
//let style = Some(Style::default().green().dim());
fill_bg(buf, area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
if self.focused && self.entered {
QuarterV(Style::default().green().dim()).draw(buf, Rect { x, y, width, height })?;
//lozenge_left(buf, x, y, height, style);
//lozenge_right(buf, x + width - 1, y, height, style);
}
let bg_color = if self.focused && self.entered {
Color::Rgb(30, 90, 25)
} else if self.focused {
Color::Rgb(25, 60, 15)
} else {
Color::Rgb(20, 45, 5)
};
let mut x2 = x;
let bg_color = self.bg_color();
for (i, w) in self.track_widths().iter().enumerate() {
let focus_column = i == self.cursor.0;
if x2 >= x + width {
@ -205,89 +205,181 @@ impl<'a> ArrangerView<'a> {
}
impl<'a> ArrangerView<'a> {
fn draw_horizontal (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
area.height = self.tracks.len() as u16 * 2 + 2;
//let style = Some(Style::default().green().dim());
let Rect { x, y, width, height } = area;
fill_bg(buf, area, if self.focused && self.entered {
Color::Rgb(25, 60, 15)
} else if self.focused {
Color::Rgb(20, 45, 5)
} else {
Color::Reset
});
if self.focused && self.entered {
//RailV::draw(buf, Rect { x, y, width, height });
QuarterV(Style::default().green().dim()).draw(buf, Rect { x, y, width, height })?;
//lozenge_left(buf, x, y, height, style);
//lozenge_right(buf, x + width - 1, y, height, style);
}
let mut x2 = 0;
self.horizontal_tracks(buf, area, &mut x2)?;
x2 = x2 + 1;
self.horizontal_scenes(buf, area, &mut x2)?;
if self.focused {
HELP.blit(buf, x + 2, y + height - 1, Some(Style::default().dim()))?;
}
Ok(area)
}
fn horizontal_size (&self) -> (u16, u16) {
let w = (4 + longest_track_name(&self.tracks) + self.scenes.len() as u16 * 10) as u16;
let h = (2 + self.tracks.len()) as u16;
(w, h)
}
fn horizontal_tracks (&self, buf: &mut Buffer, area: Rect, x2: &mut u16) -> Usually<()> {
let style = Some(Style::default().bold().not_dim().white());
let Rect { x, y, height, .. } = area;
"Mix".blit(buf, x + 1, y, style)?;
let style = Some(Style::default().bold());
for (i, track) in self.tracks.iter().enumerate() {
let y2 = y + 1 + i as u16 * 2;
if self.cursor.0 > 0 {
if i == self.cursor.0 - 1 {
">".blit(buf, x, y2, style)?;
}
}
let label = format!(" {:8}", &track.name);
label.blit(buf, x + 1, y2, style)?;
"RDM".blit(buf, x + 10, y2, Some(Style::default().dim()))?;
" 0.0dB".blit(buf, x + 15, y2, Some(Style::default().dim()))?;
*x2 = (*x2).max(label.len() as u16 + 13);
}
"".blit(buf, x + *x2, y, style)?;
for y in y+1..y+height-1 {
"".blit(buf, x + *x2, y, style)?;
}
//"╵".blit(buf, x + x2, y+height-1, style);
Ok(())
}
fn horizontal_scenes (&self, buf: &mut Buffer, area: Rect, x2: &mut u16) -> Usually<()> {
let Rect { x, y, height, .. } = area;
let bold = Some(Style::default().bold());
let sep = Some(Style::default().dim());
for scene in self.scenes.iter() {
let mut x3 = scene.name.len() as u16;
scene.name.blit(buf, x + *x2, y, bold)?;
for (i, clip) in scene.clips.iter().enumerate() {
if let Some(clip) = clip {
if let Some(phrase) = self.tracks[i].phrases.get(*clip) {
let y2 = y + 1 + i as u16 * 2;
let label = format!("{}", &phrase.name);
label.blit(buf, x + *x2, y2, None)?;
x3 = x3.max(label.len() as u16)
fn draw_horizontal (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let style1 = Some(Style::default().bold().not_dim());
let style2 = Some(Style::default().not_dim());
let style3 = Some(Style::default().yellow().bold().not_dim());
let style4 = Some(Style::default().dim());
let style5 = Some(Style::default().white().bold().not_dim());
Split::right([
// Track name
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
let mut width = 0;
for y in 0..area.height {
if y == 0 {
"MIX".blit(buf, area.x, area.y + y, style1)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
width = width.max(
track.name.blit(buf, area.x + 1, area.y + y, style5)?.width
);
if self.cursor.0 > 0 {
if index == self.cursor.0 - 1 {
"".blit(buf, area.x, area.y + y, style3)?;
}
}
} else {
area.height = y;
break
}
}
}
}
*x2 = *x2 + x3;
area.width = width + 1;
Ok(area)
},
"".blit(buf, x + *x2, y, sep)?;
for y in y+1..y+height-1 {
"".blit(buf, x + *x2, y, sep)?;
}
"".blit(buf, x + *x2, y+height-1, sep)?;
*x2 = *x2 + 1;
}
Ok(())
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
for y in 0..area.height {
if y == 0 {
" MON ".blit(buf, area.x, area.y + y, style2)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
" MON ".blit(buf, area.x, area.y + y, if track.monitoring {
Some(Style::default().not_dim().green().bold())
} else {
style4
})?;
} else {
area.height = y;
break
}
}
}
area.width = 4;
Ok(area)
},
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
for y in 0..area.height {
if y == 0 {
" REC ".blit(buf, area.x, area.y + y, style2)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
" REC ".blit(buf, area.x, area.y + y, if track.recording {
Some(Style::default().not_dim().red().bold())
} else {
style4
})?;
} else {
area.height = y;
break
}
}
}
area.width = 4;
Ok(area)
},
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
for y in 0..area.height {
if y == 0 {
" OVR ".blit(buf, area.x, area.y + y, style2)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
" OVR ".blit(buf, area.x, area.y + y, if track.overdub {
Some(Style::default().not_dim().yellow().bold())
} else {
style4
})?;
} else {
area.height = y;
break
}
}
}
area.width = 4;
Ok(area)
},
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
for y in 0..area.height {
if y == 0 {
" DEL ".blit(buf, area.x, area.y + y, style2)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
" DEL ".blit(buf, area.x, area.y + y, style4)?;
} else {
area.height = y;
break
}
}
}
area.width = 4;
Ok(area)
},
&|buf: &mut Buffer, mut area: Rect|{
area.x = area.x + 1;
for y in 0..area.height {
if y == 0 {
" GAIN ".blit(buf, area.x, area.y + y, style2)?;
} else if y % 2 == 1 {
let index = y as usize / 2;
if let Some(track) = self.tracks.get(index) {
" +0.0 ".blit(buf, area.x, area.y + y, style4)?;
} else {
area.height = y;
break
}
}
}
area.width = 7;
Ok(area)
},
// Scene columns
&|buf: &mut Buffer, area: Rect|{
let mut x2 = 0;
let Rect { x, y, height, .. } = area;
let sep = Some(Style::default().dim());
for scene in self.scenes.iter() {
"".blit(buf, x + x2, y, sep)?;
for y in y+1..y+height-1 {
"".blit(buf, x + x2, y, sep)?;
}
"".blit(buf, x + x2, y+height-1, sep)?;
let mut x3 = scene.name.len() as u16;
scene.name.blit(buf, x + x2, y, Some(Style::default().white().bold().not_dim()))?;
for (i, clip) in scene.clips.iter().enumerate() {
if let Some(clip) = clip {
let y2 = y + 1 + i as u16 * 2;
let label = format!("{}", if let Some(phrase) = self.tracks[i].phrases.get(*clip) {
&phrase.name
} else {
"...."
});
label.blit(buf, x + x2, y2, Some(Style::default().white().not_dim()))?;
x3 = x3.max(label.len() as u16)
}
}
x2 = x2 + x3;
x2 = x2 + 1;
}
Ok(Rect { x, y, height, width: x2 })
},
]).render(buf, area)
}
}
@ -305,14 +397,6 @@ fn highlight (focused: bool, highlight: bool) -> Style {
}
}
fn longest_track_name (tracks: &[Track]) -> u16 {
let mut w = 3u16;
for track in tracks.iter() {
w = w.max(track.name.len() as u16);
}
w
}
fn longest_scene_name (scenes: &[Scene]) -> u16 {
let mut w = 3u16;
for scene in scenes.iter() {