mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
use crate::{core::*, model::*, view::*};
|
|
|
|
pub struct ChainView<'a> {
|
|
pub track: Option<&'a Track>,
|
|
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 == AppSection::Chain,
|
|
track: match app.track_cursor {
|
|
0 => None,
|
|
_ => app.tracks.get(app.track_cursor - 1)
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = self.direction
|
|
.split_focus(0, track.devices.as_slice(), if self.focused {
|
|
Style::default().green().dim()
|
|
} else {
|
|
Style::default().dim()
|
|
})
|
|
.render(buf, area)?;
|
|
if self.focused && self.entered {
|
|
Corners(Style::default().green().not_dim()).draw(buf, area)?;
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
}
|