mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
don't crash on add track/scene
This commit is contained in:
parent
5a9ec0a63d
commit
6a738375e2
9 changed files with 205 additions and 207 deletions
69
src/view.rs
69
src/view.rs
|
|
@ -5,7 +5,9 @@ pub mod transport;
|
|||
pub mod plugin;
|
||||
pub mod border;
|
||||
pub mod theme;
|
||||
pub mod split;
|
||||
|
||||
pub use self::split::*;
|
||||
pub use self::border::*;
|
||||
pub use self::theme::*;
|
||||
pub use self::arranger::*;
|
||||
|
|
@ -28,70 +30,3 @@ render!(App |self, buf, area| {
|
|||
}
|
||||
Ok(area)
|
||||
});
|
||||
|
||||
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 trait Modal<T>: Device {
|
||||
fn handle_with_state (&self, state: &mut T, event: &AppEvent) -> Usually<bool>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum Direction { Down, Right }
|
||||
|
||||
impl Direction {
|
||||
pub fn split <'a, const N: usize> (&self, items: [&'a (dyn Render + Sync);N]) -> Split<'a, N> {
|
||||
Split(*self, items)
|
||||
}
|
||||
pub fn is_down (&self) -> bool {
|
||||
match self { Self::Down => true, _ => false }
|
||||
}
|
||||
pub fn is_right (&self) -> bool {
|
||||
match self { Self::Right => true, _ => false }
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue