mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
add Layered
This commit is contained in:
parent
5d7347137b
commit
4603bbd0da
3 changed files with 112 additions and 93 deletions
|
|
@ -24,6 +24,12 @@ pub fn fill_fg (buf: &mut Buffer, area: Rect, color: Color) {
|
||||||
pub fn fill_bg (buf: &mut Buffer, area: Rect, color: Color) {
|
pub fn fill_bg (buf: &mut Buffer, area: Rect, color: Color) {
|
||||||
buffer_update(buf, area, &|cell,_,_|{cell.set_bg(color);})
|
buffer_update(buf, area, &|cell,_,_|{cell.set_bg(color);})
|
||||||
}
|
}
|
||||||
|
pub fn to_fill_bg (color: Color) -> impl Render {
|
||||||
|
move |buf: &mut Buffer, area: Rect|{
|
||||||
|
fill_bg(buf, area, color);
|
||||||
|
Ok(area)
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn fill_char (buf: &mut Buffer, area: Rect, c: char) {
|
pub fn fill_char (buf: &mut Buffer, area: Rect, c: char) {
|
||||||
buffer_update(buf, area, &|cell,_,_|{cell.set_char(c);})
|
buffer_update(buf, area, &|cell,_,_|{cell.set_char(c);})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,20 +156,20 @@ mod draw_vertical {
|
||||||
) -> Usually<Rect> {
|
) -> Usually<Rect> {
|
||||||
area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16;
|
area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16;
|
||||||
let offset = 3 + scene_name_max_len(state.scenes.as_ref()) as u16;
|
let offset = 3 + scene_name_max_len(state.scenes.as_ref()) as u16;
|
||||||
column_separators(buf, area, offset, cols)?;
|
Layered([
|
||||||
fill_bg(buf, area, Nord::bg_lo(state.focused, state.entered));
|
&to_fill_bg(Nord::bg_lo(state.focused, state.entered)),
|
||||||
cursor_focus(state, buf, area, offset, cols, rows)?;
|
&column_separators(offset, cols),
|
||||||
Split::down([
|
&cursor_focus(state, offset, cols, rows),
|
||||||
|
&Split::down([
|
||||||
&tracks_header(state, cols, offset),
|
&tracks_header(state, cols, offset),
|
||||||
&scene_rows(state, cols, rows, offset),
|
&scene_rows(state, cols, rows, offset),
|
||||||
]).render(buf, area)?;
|
]),
|
||||||
row_separators(buf, area, rows);
|
&row_separators(rows),
|
||||||
Ok(area)
|
]).render(buf, area)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_separators (
|
fn column_separators <'a> (offset: u16, cols: &'a [(usize, usize)]) -> impl Render + 'a {
|
||||||
buf: &mut Buffer, area: Rect, offset: u16, cols: &[(usize, usize)]
|
move |buf: &mut Buffer, area: Rect|{
|
||||||
) -> Usually<()> {
|
|
||||||
let style = Some(Style::default().fg(Color::Rgb(0,0,0)));
|
let style = Some(Style::default().fg(Color::Rgb(0,0,0)));
|
||||||
for (_, x) in cols.iter() {
|
for (_, x) in cols.iter() {
|
||||||
let x = offset + area.x + *x as u16 - 1;
|
let x = offset + area.x + *x as u16 - 1;
|
||||||
|
|
@ -177,10 +177,12 @@ mod draw_vertical {
|
||||||
"▎".blit(buf, x, y, style)?;
|
"▎".blit(buf, x, y, style)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(area)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn row_separators (buf: &mut Buffer, area: Rect, rows: &[(usize, usize)]) {
|
fn row_separators <'a> (rows: &'a [(usize, usize)]) -> impl Render + 'a {
|
||||||
|
move |buf: &mut Buffer, area: Rect| {
|
||||||
for (_, y) in rows.iter() {
|
for (_, y) in rows.iter() {
|
||||||
let y = area.y + (*y / 96) as u16 + 1;
|
let y = area.y + (*y / 96) as u16 + 1;
|
||||||
for x in area.x..area.width+area.y-2 {
|
for x in area.x..area.width+area.y-2 {
|
||||||
|
|
@ -189,23 +191,23 @@ mod draw_vertical {
|
||||||
cell.underline_color = Color::Rgb(0, 0, 0);
|
cell.underline_color = Color::Rgb(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(area)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor_focus (
|
fn cursor_focus <'a> (
|
||||||
state: &Arranger,
|
state: &'a Arranger, offset: u16, cols: &'a [(usize, usize)], rows: &'a [(usize, usize)],
|
||||||
buf: &mut Buffer,
|
) -> impl Render + 'a {
|
||||||
area: Rect,
|
move |buf: &mut Buffer, area: Rect| {
|
||||||
offset: u16,
|
|
||||||
cols: &[(usize, usize)],
|
|
||||||
rows: &[(usize, usize)],
|
|
||||||
) -> Usually<()> {
|
|
||||||
match state.selected {
|
match state.selected {
|
||||||
ArrangerFocus::Mix => if state.focused
|
ArrangerFocus::Mix => if state.focused
|
||||||
&& state.entered
|
&& state.entered
|
||||||
&& state.selected == ArrangerFocus::Mix
|
&& state.selected == ArrangerFocus::Mix
|
||||||
{
|
{
|
||||||
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
Corners(Style::default().green().not_dim()).draw(buf, area)
|
||||||
|
} else {
|
||||||
|
Ok(area)
|
||||||
},
|
},
|
||||||
ArrangerFocus::Track(t) => {
|
ArrangerFocus::Track(t) => {
|
||||||
let area = Rect {
|
let area = Rect {
|
||||||
|
|
@ -215,7 +217,7 @@ mod draw_vertical {
|
||||||
height: area.height
|
height: area.height
|
||||||
};
|
};
|
||||||
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
Corners(Style::default().green().not_dim()).draw(buf, area)
|
||||||
},
|
},
|
||||||
ArrangerFocus::Scene(s) => {
|
ArrangerFocus::Scene(s) => {
|
||||||
let area = Rect {
|
let area = Rect {
|
||||||
|
|
@ -225,7 +227,7 @@ mod draw_vertical {
|
||||||
height: (rows[s].0 / 96) as u16
|
height: (rows[s].0 / 96) as u16
|
||||||
};
|
};
|
||||||
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
fill_bg(buf, area, Nord::bg_hi(state.focused, state.entered));
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
Corners(Style::default().green().not_dim()).draw(buf, area)
|
||||||
},
|
},
|
||||||
ArrangerFocus::Clip(t, s) => {
|
ArrangerFocus::Clip(t, s) => {
|
||||||
let track_area = Rect {
|
let track_area = Rect {
|
||||||
|
|
@ -251,10 +253,10 @@ mod draw_vertical {
|
||||||
fill_bg(buf, track_area, lo);
|
fill_bg(buf, track_area, lo);
|
||||||
fill_bg(buf, scene_area, lo);
|
fill_bg(buf, scene_area, lo);
|
||||||
fill_bg(buf, area, hi);
|
fill_bg(buf, area, hi);
|
||||||
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
Corners(Style::default().green().not_dim()).draw(buf, area)
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
Ok(())
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tracks_header <'a> (
|
pub fn tracks_header <'a> (
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,16 @@
|
||||||
use crate::{core::*, view::*};
|
use crate::{core::*, view::*};
|
||||||
|
|
||||||
|
pub struct Layered<'a, const N: usize>(pub [&'a (dyn Render + Sync); N]);
|
||||||
|
|
||||||
|
impl<'a, const N: usize> Render for Layered<'a, N> {
|
||||||
|
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
|
for layer in self.0.iter() {
|
||||||
|
layer.render(buf, area)?;
|
||||||
|
}
|
||||||
|
Ok(area)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct If<'a>(pub bool, pub &'a (dyn Render + Sync));
|
pub struct If<'a>(pub bool, pub &'a (dyn Render + Sync));
|
||||||
|
|
||||||
impl<'a> Render for If<'a> {
|
impl<'a> Render for If<'a> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue