wip: borrow checker battles

This commit is contained in:
🪞👃🪞 2024-09-04 16:57:48 +03:00
parent 1d4db3c629
commit 7fbb40fad6
38 changed files with 778 additions and 708 deletions

View file

@ -2,7 +2,7 @@
use crate::*;
/// Represents the tracks and scenes of the composition.
pub struct Arranger {
pub struct Arranger<T, U> {
/// Name of arranger
pub name: Arc<RwLock<String>>,
/// Collection of tracks.
@ -14,14 +14,11 @@ pub struct Arranger {
/// Display mode of arranger
pub mode: ArrangerViewMode,
/// Slot for modal dialog displayed on top of app.
pub modal: Option<Box<dyn ExitableComponent>>,
pub modal: Option<Box<dyn ExitableComponent<T, U>>>,
/// Whether the arranger is currently focused
pub focused: bool
}
focusable!(Arranger (focused));
impl Arranger {
impl<T, U> Arranger<T, U> {
pub fn new (name: &str) -> Self {
Self {
name: Arc::new(RwLock::new(name.into())),
@ -83,3 +80,56 @@ impl Arranger {
}
}
}
/// Display mode of arranger
pub enum ArrangerViewMode {
VerticalExpanded,
VerticalCompact1,
VerticalCompact2,
Horizontal,
}
/// Arranger display mode can be cycled
impl ArrangerViewMode {
/// Cycle arranger display mode
pub fn to_next (&mut self) {
*self = match self {
Self::VerticalExpanded => Self::VerticalCompact1,
Self::VerticalCompact1 => Self::VerticalCompact2,
Self::VerticalCompact2 => Self::Horizontal,
Self::Horizontal => Self::VerticalExpanded,
}
}
}
/// Render arranger to terminal
impl<'a> Render<TuiOutput<'a>, Rect> for Arranger<TuiOutput<'a>, Rect> {
fn render (&'a self, to: &'a mut TuiOutput<'a>) -> Perhaps<Rect> {
let area = (|to|match self.mode {
ArrangerViewMode::Horizontal =>
super::arranger_view_h::draw(self, to),
ArrangerViewMode::VerticalCompact1 =>
super::arranger_view_v::draw_compact_1(self, to),
ArrangerViewMode::VerticalCompact2 =>
super::arranger_view_v::draw_compact_2(self, to),
ArrangerViewMode::VerticalExpanded =>
super::arranger_view_v::draw_expanded(self, to),
})(&mut to.area(Rect {
x: to.area.x + 1,
width: to.area.width - 2,
y: to.area.y + 1,
height: to.area.height - 2
}))?.unwrap();
Lozenge(Style::default().fg(Nord::BG2)).draw(&mut to.area(Rect {
x: area.x.saturating_sub(1),
width: area.width + 2,
y: area.y.saturating_sub(1),
height: area.height + 2,
}))
}
}
impl<'a> Focusable<TuiOutput<'a>, Rect> for Arranger<TuiOutput<'a>, Rect> {
fn is_focused (&self) -> bool {
self.focused
}
fn set_focused (&mut self, focused: bool) {
self.focused = focused
}
}