mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
wip: refactor into crates
This commit is contained in:
parent
96e17e7f7c
commit
5ae99b4ada
87 changed files with 2281 additions and 2217 deletions
58
crates/tek_chain/src/chain_view.rs
Normal file
58
crates/tek_chain/src/chain_view.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use crate::*;
|
||||
use tek_core::Direction;
|
||||
|
||||
pub struct ChainView<'a> {
|
||||
pub track: Option<&'a Chain>,
|
||||
pub direction: Direction,
|
||||
pub focused: bool,
|
||||
pub entered: bool,
|
||||
}
|
||||
|
||||
impl<'a> ChainView<'a> {
|
||||
pub fn horizontal (app: &'a App) -> Self {
|
||||
Self::new(app, Direction::Right)
|
||||
}
|
||||
pub fn vertical (app: &'a App) -> Self {
|
||||
Self::new(app, Direction::Down)
|
||||
}
|
||||
pub fn new (app: &'a App, direction: Direction) -> Self {
|
||||
Self {
|
||||
direction,
|
||||
entered: app.entered,
|
||||
focused: app.section == AppFocus::Chain,
|
||||
track: app.arranger.track()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render for ChainView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
|
||||
if let Some(track) = self.track {
|
||||
match self.direction {
|
||||
Direction::Down => area.width = area.width.min(40),
|
||||
Direction::Right => area.width = area.width.min(10),
|
||||
}
|
||||
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
|
||||
let (area, areas) = self.direction
|
||||
.split_focus(0, track.devices.as_slice(), if self.focused {
|
||||
Style::default().green().dim()
|
||||
} else {
|
||||
Style::default().dim()
|
||||
})
|
||||
.render_areas(buf, area)?;
|
||||
if self.focused && self.entered {
|
||||
Corners(Style::default().green().not_dim()).draw(buf, areas[0])?;
|
||||
}
|
||||
Ok(area)
|
||||
} else {
|
||||
let Rect { x, y, width, height } = area;
|
||||
let label = "No track selected";
|
||||
let x = x + (width - label.len() as u16) / 2;
|
||||
let y = y + height / 2;
|
||||
label.blit(buf, x, y, Some(Style::default().dim().bold()))?;
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue