From 97af45b576dd04dfc52c0e3466840514197893c1 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 18 Oct 2024 23:51:58 +0300 Subject: [PATCH] add widget dynamic helper and Split::up --- crates/tek_core/src/engine.rs | 4 +++ crates/tek_core/src/space.rs | 16 +++++++++++ crates/tek_sequencer/src/arranger.rs | 8 +++--- crates/tek_sequencer/src/arranger_tui.rs | 36 +++++++++++++++--------- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/crates/tek_core/src/engine.rs b/crates/tek_core/src/engine.rs index 7db9dc01..29d146ff 100644 --- a/crates/tek_core/src/engine.rs +++ b/crates/tek_core/src/engine.rs @@ -42,6 +42,10 @@ pub trait Output { /// Render widget in area fn render_in (&mut self, area: E::Area, widget: &dyn Widget) -> Usually<()>; } +/// Cast to dynamic pointer +pub fn widget > (w: &T) -> &dyn Widget { + w as &dyn Widget +} /// A renderable component pub trait Widget: Send + Sync { /// Engine for which this component is implemented diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index ee4e24ae..3dffb68c 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -94,6 +94,10 @@ pub trait Area: Copy { } #[inline] fn split_fixed (&self, direction: Direction, a: N) -> ([N;4],[N;4]) { match direction { + Direction::Up => ( + [self.x(), self.y() + self.h() - a, self.w(), a], + [self.x(), self.y(), self.w(), self.h() - a], + ), Direction::Down => ( [self.x(), self.y(), self.w(), a], [self.x(), self.y() + a, self.w(), self.h() - a], @@ -817,6 +821,18 @@ impl, B: Widget> Split { pub fn new (direction: Direction, proportion: E::Unit, a: A, b: B) -> Self { Self(direction, proportion, a, b, Default::default()) } + pub fn up (proportion: E::Unit, a: A, b: B) -> Self { + Self(Direction::Up, proportion, a, b, Default::default()) + } + pub fn down (proportion: E::Unit, a: A, b: B) -> Self { + Self(Direction::Down, proportion, a, b, Default::default()) + } + pub fn left (proportion: E::Unit, a: A, b: B) -> Self { + Self(Direction::Left, proportion, a, b, Default::default()) + } + pub fn right (proportion: E::Unit, a: A, b: B) -> Self { + Self(Direction::Right, proportion, a, b, Default::default()) + } } impl, B: Widget> Widget for Split { diff --git a/crates/tek_sequencer/src/arranger.rs b/crates/tek_sequencer/src/arranger.rs index 7133d6b6..7e800361 100644 --- a/crates/tek_sequencer/src/arranger.rs +++ b/crates/tek_sequencer/src/arranger.rs @@ -12,8 +12,6 @@ pub struct Arranger { pub phrases: Arc>>, /// Phrase editor view pub editor: PhraseEditor, - /// This allows the sequencer view to be moved or hidden. - pub show_sequencer: Option, /// Status bar pub status: ArrangerStatusBar, /// Height of arrangement @@ -36,7 +34,10 @@ pub enum ArrangerFocus { /// Status bar for arranger ap pub enum ArrangerStatusBar { Transport, - Arrangement, + ArrangementMix, + ArrangementTrack, + ArrangementScene, + ArrangementClip, PhrasePool, PhraseEditor, } @@ -116,7 +117,6 @@ impl Arranger { ) -> Self { let mut app = Self { focus_cursor: (0, 1), - show_sequencer: Some(tek_core::Direction::Down), editor: PhraseEditor::new(), status: ArrangerStatusBar::Transport, transport, diff --git a/crates/tek_sequencer/src/arranger_tui.rs b/crates/tek_sequencer/src/arranger_tui.rs index 8e00f1d5..1d4676a6 100644 --- a/crates/tek_sequencer/src/arranger_tui.rs +++ b/crates/tek_sequencer/src/arranger_tui.rs @@ -3,19 +3,29 @@ use crate::*; impl Content for Arranger { type Engine = Tui; fn content (&self) -> impl Widget { - Stack::down(move|add|{ - add(&self.transport)?; - let arrangement = &self.arrangement as &dyn Widget; - if let Some(direction) = self.show_sequencer { - add(&arrangement.split(direction, self.arrangement_split, - self.phrases.clone().split(direction.ccw(), self.phrases_split, - &self.editor as &dyn Widget - ).min_y(self.arrangement_split) - ).fill_y()) - } else { - add(&self.arrangement) - } - }) + Split::down( + 2, + widget(&self.transport), + Split::up( + 1, + widget(&self.status), + Split::down( + self.arrangement_split, + widget(&self.arrangement), + Split::right( + self.phrases_split, + self.phrases.clone(), + widget(&self.editor), + ) + ) + ) + ).fill_xy() + } +} +impl Content for ArrangerStatusBar { + type Engine = Tui; + fn content (&self) -> impl Widget { + "status bar" } } impl Content for Arrangement {