add widget dynamic helper and Split::up

This commit is contained in:
🪞👃🪞 2024-10-18 23:51:58 +03:00
parent 038451e2f4
commit 97af45b576
4 changed files with 47 additions and 17 deletions

View file

@ -42,6 +42,10 @@ pub trait Output<E: Engine> {
/// Render widget in area
fn render_in (&mut self, area: E::Area, widget: &dyn Widget<Engine = E>) -> Usually<()>;
}
/// Cast to dynamic pointer
pub fn widget <E: Engine, T: Widget<Engine = E>> (w: &T) -> &dyn Widget<Engine = E> {
w as &dyn Widget<Engine = E>
}
/// A renderable component
pub trait Widget: Send + Sync {
/// Engine for which this component is implemented

View file

@ -94,6 +94,10 @@ pub trait Area<N: Number>: 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<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Split<E, A, B> {
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<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Split<E, A, B> {

View file

@ -12,8 +12,6 @@ pub struct Arranger<E: Engine> {
pub phrases: Arc<RwLock<PhrasePool<E>>>,
/// Phrase editor view
pub editor: PhraseEditor<E>,
/// This allows the sequencer view to be moved or hidden.
pub show_sequencer: Option<tek_core::Direction>,
/// 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<E: Engine> Arranger<E> {
) -> Self {
let mut app = Self {
focus_cursor: (0, 1),
show_sequencer: Some(tek_core::Direction::Down),
editor: PhraseEditor::new(),
status: ArrangerStatusBar::Transport,
transport,

View file

@ -3,19 +3,29 @@ use crate::*;
impl Content for Arranger<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
Stack::down(move|add|{
add(&self.transport)?;
let arrangement = &self.arrangement as &dyn Widget<Engine = Tui>;
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<Engine = Tui>
).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<Engine = Tui> {
"status bar"
}
}
impl Content for Arrangement<Tui> {