modularize keymaps

This commit is contained in:
🪞👃🪞 2024-07-09 13:30:08 +03:00
parent d8c9abf744
commit 876d26e287
8 changed files with 235 additions and 275 deletions

View file

@ -6,17 +6,15 @@ pub mod sequencer;
pub mod transport;
pub mod plugin;
pub mod border;
pub mod split;
pub use self::border::*;
pub use self::layout::*;
pub use self::split::*;
pub use self::transport::TransportView;
pub use self::arranger::*;
pub use self::chain::ChainView;
pub use self::sequencer::SequencerView;
use crate::{render, App, AppSection, core::*};
use crate::{render, App, core::*};
render!(App |self, buf, area| {
let track = self.track_cursor;
@ -34,48 +32,55 @@ render!(App |self, buf, area| {
modal.render(buf, area)?;
}
Ok(area)
//let transport = transport.render(buf, area)?;
//let y = y + transport.height;
//let arranger = arranger.render(buf, Rect { x, y, width, height })?;
//let style_entered = if self.entered {
//Style::default().green()
//} else {
//Style::default().green().dim()
//};
//if self.section == AppSection::Arranger {
//QuarterV(style_entered).draw(buf, arranger)
//}
//let y = y + arranger.height;
//if self.track_cursor > 0 {
//let chain = ChainView::new(&self, false);
//let phrase = SequencerView::new(&self);
//let chain = chain.render(buf, chain_area)?;
//if self.section == AppSection::Chain {
//QuarterV(style_entered).draw(buf, Rect { width, ..chain })
//}
//let phrase = phrase.render(buf, Rect {
//x, y, width, height: height - height / 3
//})?;
//if self.section == AppSection::Sequencer {
//QuarterV(style_entered).draw(buf, phrase)
//}
//} else {
//let area = Rect { x, y, width, height };
//let mut x = area.x;
//for track in self.tracks.iter() {
//let chain = ChainView {
//focused: self.section == AppSection::Chain,
//track: Some(track),
//vertical: true,
//};
//track.name.blit(buf, x + 1, area.y, Some(Style::default().white().bold()));
//let chain = chain.render(buf, Rect {
//x, y: area.y + 1, width: width, height: height - y - 1
//})?;
//x = x + chain.width.max(track.name.len() as u16);
//}
//};
});
pub struct If<'a>(pub bool, pub &'a (dyn Render + Sync));
impl<'a> Render for If<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
if self.0 {
self.1.render(buf, area)
} else {
().render(buf, area)
}
}
}
pub enum Direction {
Down,
Right,
}
pub struct Split<'a, const N: usize>(pub Direction, pub [&'a (dyn Render + Sync);N]);
impl<'a, const N: usize> Split<'a, N> {
pub fn down (items: [&'a (dyn Render + Sync);N]) -> Self {
Self(Direction::Down, items)
}
pub fn right (items: [&'a (dyn Render + Sync);N]) -> Self {
Self(Direction::Right, items)
}
}
impl<'a, const N: usize> Render for Split<'a, N> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { mut x, mut y, mut width, mut height } = area;
for item in self.1 {
if width == 0 || height == 0 {
break
}
let result = item.render(buf, Rect { x, y, width, height })?;
match self.0 {
Direction::Down => {
y = y + result.height;
height = height.saturating_sub(result.height);
},
Direction::Right => {
x = x + result.width;
width = width.saturating_sub(result.width);
},
}
}
Ok(area)
}
}