mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
remove LayoutSplit; merge split and bsp modules
This commit is contained in:
parent
0c9c386a79
commit
35a88cb70f
8 changed files with 117 additions and 154 deletions
|
|
@ -104,10 +104,10 @@ render!(<Tui>|self: ArrangerTui|{
|
|||
let transport = TransportView::from((self, Some(ItemPalette::from(TuiTheme::g(96))), true));
|
||||
let with_transport = |x|col!([row!(![&play, &transport]), &x]);
|
||||
let pool_size = if self.phrases.visible { self.splits[1] } else { 0 };
|
||||
let with_pool = |x|Split::left(false, pool_size, PoolView(&self.phrases), x);
|
||||
let with_pool = |x|Split::w(false, pool_size, PoolView(&self.phrases), x);
|
||||
let status = ArrangerStatus::from(self);
|
||||
let with_editbar = |x|Tui::split_n(false, 1, MidiEditStatus(&self.editor), x);
|
||||
let with_status = |x|Tui::split_n(false, 2, status, x);
|
||||
let with_editbar = |x|Split::n(false, 1, MidiEditStatus(&self.editor), x);
|
||||
let with_status = |x|Split::n(false, 2, status, x);
|
||||
let with_size = |x|lay!([&self.size, x]);
|
||||
let arranger = ||lay!(|add|{
|
||||
let color = self.color;
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ render!(<Tui>|self:Groovebox|{
|
|||
PhraseSelector::next_phrase(&self.player),
|
||||
]))),
|
||||
row!([
|
||||
Tui::split_n(false, 9,
|
||||
Split::n(false, 9,
|
||||
col!([
|
||||
row!(|add|{
|
||||
if let Some(sample) = &self.sampler.mapped[note_pt] {
|
||||
|
|
@ -152,9 +152,9 @@ render!(<Tui>|self:Groovebox|{
|
|||
})),
|
||||
]),
|
||||
]),
|
||||
Tui::split_w(false, pool_w,
|
||||
Split::w(false, pool_w,
|
||||
Tui::pull_y(1, Fill::h(Align::e(PoolView(&self.pool)))),
|
||||
Tui::split_e(false, sampler_w, Fill::wh(col!([
|
||||
Split::e(false, sampler_w, Fill::wh(col!([
|
||||
Meters(self.sampler.input_meter.as_ref()),
|
||||
GrooveboxSamples(self),
|
||||
])), Fill::h(&self.editor))
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ render!(<Tui>|self: SequencerTui|{
|
|||
let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
|
||||
let pool_w = if self.phrases.visible { phrase_w } else { 0 };
|
||||
let pool = Tui::pull_y(1, Fill::h(Align::e(PoolView(&self.phrases))));
|
||||
let with_pool = move|x|Tui::split_w(false, pool_w, pool, x);
|
||||
let with_pool = move|x|Split::w(false, pool_w, pool, x);
|
||||
let status = SequencerStatus::from(self);
|
||||
let with_status = |x|Tui::split_n(false, if self.status { 2 } else { 0 }, status, x);
|
||||
let with_editbar = |x|Tui::split_n(false, 1, MidiEditStatus(&self.editor), x);
|
||||
let with_status = |x|Split::n(false, if self.status { 2 } else { 0 }, status, x);
|
||||
let with_editbar = |x|Split::n(false, 1, MidiEditStatus(&self.editor), x);
|
||||
let with_size = |x|lay!([self.size, x]);
|
||||
let editor = with_editbar(with_pool(Fill::wh(&self.editor)));
|
||||
let color = self.player.play_phrase().as_ref().map(|(_,p)|
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use std::fmt::{Display, Debug};
|
|||
//////////////////////////////////////////////////////
|
||||
|
||||
pub(crate) mod align;
|
||||
pub(crate) mod bsp;
|
||||
pub(crate) mod cond; pub(crate) use cond::*;
|
||||
pub(crate) mod fill;
|
||||
pub(crate) mod fixed; pub(crate) use fixed::*;
|
||||
|
|
@ -25,8 +24,8 @@ pub(crate) mod stack; pub(crate) use stack::*;
|
|||
|
||||
pub use self::{
|
||||
align::*,
|
||||
bsp::*,
|
||||
fill::*,
|
||||
split::*,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
|
|
|||
103
src/space/bsp.rs
103
src/space/bsp.rs
|
|
@ -1,103 +0,0 @@
|
|||
use crate::*;
|
||||
|
||||
pub enum Bsp<E: Engine, X: Render<E>, Y: Render<E>> {
|
||||
/// X is north of Y
|
||||
N(Option<X>, Option<Y>),
|
||||
/// X is south of Y
|
||||
S(Option<X>, Option<Y>),
|
||||
/// X is east of Y
|
||||
E(Option<X>, Option<Y>),
|
||||
/// X is west of Y
|
||||
W(Option<X>, Option<Y>),
|
||||
/// X is above Y
|
||||
A(Option<X>, Option<Y>),
|
||||
/// X is below Y
|
||||
B(Option<X>, Option<Y>),
|
||||
/// Should be avoided.
|
||||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Bsp<E, X, Y> {
|
||||
pub fn new (x: X) -> Self { Self::A(Some(x), None) }
|
||||
pub fn n (x: X, y: Y) -> Self { Self::N(Some(x), Some(y)) }
|
||||
pub fn s (x: X, y: Y) -> Self { Self::S(Some(x), Some(y)) }
|
||||
pub fn e (x: X, y: Y) -> Self { Self::E(Some(x), Some(y)) }
|
||||
pub fn w (x: X, y: Y) -> Self { Self::W(Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::A(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::B(Some(x), Some(y)) }
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Default for Bsp<E, X, Y> {
|
||||
fn default () -> Self {
|
||||
Self::Null(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Render<E> for Bsp<E, X, Y> {
|
||||
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
Ok(Some(match self {
|
||||
Self::Null(_) => [0.into(), 0.into()].into(),
|
||||
Self::S(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w().max(b.w()), a.h() + b.h()].into()
|
||||
},
|
||||
Self::E(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w() + b.w(), a.h().max(b.h())].into()
|
||||
},
|
||||
Self::W(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w() + b.w(), a.h().max(b.h())].into()
|
||||
},
|
||||
Self::N(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w().max(b.w()), a.h() + b.h()].into()
|
||||
},
|
||||
_ => todo!()
|
||||
}))
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
let n = [0.into(), 0.into()].into();
|
||||
let s = to.area().wh().into();
|
||||
Ok(match self {
|
||||
Self::Null(_) => {},
|
||||
Self::S(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let h = s_a.h().into();
|
||||
to.render_in(to.area().clip_h(h).into(), a)?;
|
||||
to.render_in(to.area().shrink_y(h).push_y(h).into(), b)?;
|
||||
},
|
||||
Self::E(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let w = s_a.w().into();
|
||||
to.render_in(to.area().clip_w(w).into(), a)?;
|
||||
to.render_in(to.area().push_x(w).shrink_x(w).into(), b)?;
|
||||
},
|
||||
Self::W(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let w = (to.area().w() - s_a.w()).into();
|
||||
to.render_in(to.area().push_x(w).into(), a)?;
|
||||
to.render_in(to.area().shrink_x(w).into(), b)?;
|
||||
},
|
||||
Self::N(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let h = to.area().h() - s_a.h();
|
||||
to.render_in(to.area().push_y(h).into(), a)?;
|
||||
to.render_in(to.area().shrink_y(h).into(), b)?;
|
||||
},
|
||||
_ => todo!()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_bsp () {
|
||||
// TODO
|
||||
}
|
||||
|
|
@ -1,36 +1,6 @@
|
|||
use crate::*;
|
||||
use Direction::*;
|
||||
|
||||
impl<E: Engine> LayoutSplit<E> for E {}
|
||||
|
||||
pub trait LayoutSplit<E: Engine> {
|
||||
fn split <A: Render<E>, B: Render<E>> (
|
||||
flip: bool, direction: Direction, amount: E::Unit, a: A, b: B
|
||||
) -> Split<E, A, B> {
|
||||
Split::new(flip, direction, amount, a, b)
|
||||
}
|
||||
fn split_n <A: Render<E>, B: Render<E>> (
|
||||
flip: bool, amount: E::Unit, a: A, b: B
|
||||
) -> Split<E, A, B> {
|
||||
Self::split(flip, North, amount, a, b)
|
||||
}
|
||||
fn split_s <A: Render<E>, B: Render<E>> (
|
||||
flip: bool, amount: E::Unit, a: A, b: B
|
||||
) -> Split<E, A, B> {
|
||||
Self::split(flip, South, amount, a, b)
|
||||
}
|
||||
fn split_w <A: Render<E>, B: Render<E>> (
|
||||
flip: bool, amount: E::Unit, a: A, b: B
|
||||
) -> Split<E, A, B> {
|
||||
Self::split(flip, West, amount, a, b)
|
||||
}
|
||||
fn split_e <A: Render<E>, B: Render<E>> (
|
||||
flip: bool, amount: E::Unit, a: A, b: B
|
||||
) -> Split<E, A, B> {
|
||||
Self::split(flip, East, amount, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
/// A binary split with fixed proportion
|
||||
pub struct Split<E: Engine, A: Render<E>, B: Render<E>>(
|
||||
pub bool, pub Direction, pub E::Unit, A, B, PhantomData<E>
|
||||
|
|
@ -40,16 +10,16 @@ impl<E: Engine, A: Render<E>, B: Render<E>> Split<E, A, B> {
|
|||
pub fn new (flip: bool, direction: Direction, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
Self(flip, direction, proportion, a, b, Default::default())
|
||||
}
|
||||
pub fn up (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
pub fn n (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
Self(flip, North, proportion, a, b, Default::default())
|
||||
}
|
||||
pub fn down (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
pub fn s (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
Self(flip, South, proportion, a, b, Default::default())
|
||||
}
|
||||
pub fn left (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
pub fn e (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
Self(flip, West, proportion, a, b, Default::default())
|
||||
}
|
||||
pub fn right (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
pub fn w (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
||||
Self(flip, East, proportion, a, b, Default::default())
|
||||
}
|
||||
}
|
||||
|
|
@ -69,3 +39,105 @@ impl<E: Engine, A: Render<E>, B: Render<E>> Render<E> for Split<E, A, B> {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Bsp<E: Engine, X: Render<E>, Y: Render<E>> {
|
||||
/// X is north of Y
|
||||
N(Option<X>, Option<Y>),
|
||||
/// X is south of Y
|
||||
S(Option<X>, Option<Y>),
|
||||
/// X is east of Y
|
||||
E(Option<X>, Option<Y>),
|
||||
/// X is west of Y
|
||||
W(Option<X>, Option<Y>),
|
||||
/// X is above Y
|
||||
A(Option<X>, Option<Y>),
|
||||
/// X is below Y
|
||||
B(Option<X>, Option<Y>),
|
||||
/// Should be avoided.
|
||||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Bsp<E, X, Y> {
|
||||
pub fn new (x: X) -> Self { Self::A(Some(x), None) }
|
||||
pub fn n (x: X, y: Y) -> Self { Self::N(Some(x), Some(y)) }
|
||||
pub fn s (x: X, y: Y) -> Self { Self::S(Some(x), Some(y)) }
|
||||
pub fn e (x: X, y: Y) -> Self { Self::E(Some(x), Some(y)) }
|
||||
pub fn w (x: X, y: Y) -> Self { Self::W(Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::A(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::B(Some(x), Some(y)) }
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Default for Bsp<E, X, Y> {
|
||||
fn default () -> Self {
|
||||
Self::Null(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Render<E>, Y: Render<E>> Render<E> for Bsp<E, X, Y> {
|
||||
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
Ok(Some(match self {
|
||||
Self::Null(_) => [0.into(), 0.into()].into(),
|
||||
Self::S(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w().max(b.w()), a.h() + b.h()].into()
|
||||
},
|
||||
Self::E(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w() + b.w(), a.h().max(b.h())].into()
|
||||
},
|
||||
Self::W(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w() + b.w(), a.h().max(b.h())].into()
|
||||
},
|
||||
Self::N(a, b) => {
|
||||
let a = a.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
let b = b.min_size(to)?.unwrap_or([0.into(), 0.into()].into());
|
||||
[a.w().max(b.w()), a.h() + b.h()].into()
|
||||
},
|
||||
_ => todo!()
|
||||
}))
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
let n = [0.into(), 0.into()].into();
|
||||
let s = to.area().wh().into();
|
||||
Ok(match self {
|
||||
Self::Null(_) => {},
|
||||
Self::S(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let h = s_a.h().into();
|
||||
to.render_in(to.area().clip_h(h).into(), a)?;
|
||||
to.render_in(to.area().shrink_y(h).push_y(h).into(), b)?;
|
||||
},
|
||||
Self::E(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let w = s_a.w().into();
|
||||
to.render_in(to.area().clip_w(w).into(), a)?;
|
||||
to.render_in(to.area().push_x(w).shrink_x(w).into(), b)?;
|
||||
},
|
||||
Self::W(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let w = (to.area().w() - s_a.w()).into();
|
||||
to.render_in(to.area().push_x(w).into(), a)?;
|
||||
to.render_in(to.area().shrink_x(w).into(), b)?;
|
||||
},
|
||||
Self::N(a, b) => {
|
||||
let s_a = a.min_size(s)?.unwrap_or(n);
|
||||
let _ = b.min_size(s)?.unwrap_or(n);
|
||||
let h = to.area().h() - s_a.h();
|
||||
to.render_in(to.area().push_y(h).into(), a)?;
|
||||
to.render_in(to.area().shrink_y(h).into(), b)?;
|
||||
},
|
||||
_ => todo!()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_bsp () {
|
||||
// TODO
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue