mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
implement fixed Split
This commit is contained in:
parent
e555074bdf
commit
cd0b8a6812
4 changed files with 50 additions and 15 deletions
|
|
@ -62,7 +62,8 @@ pub trait Number: Send + Sync + Copy
|
|||
+ Div<Self, Output=Self>
|
||||
+ Ord + PartialEq + Eq
|
||||
+ Debug + Display + Default
|
||||
+ From<u16>
|
||||
+ From<u16> + Into<u16>
|
||||
+ Into<f64>
|
||||
{
|
||||
fn minus (self, other: Self) -> Self {
|
||||
if self >= other {
|
||||
|
|
@ -81,5 +82,6 @@ impl<T> Number for T where
|
|||
+ Div<Self, Output=Self>
|
||||
+ Ord + PartialEq + Eq
|
||||
+ Debug + Display + Default
|
||||
+ From<u16>
|
||||
+ From<u16> + Into<u16>
|
||||
+ Into<f64>
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,15 @@ pub trait Area<N: Number>: Copy {
|
|||
#[inline] fn clip (&self, wh: impl Size<N>) -> [N;4] {
|
||||
[self.x(), self.y(), wh.w(), wh.h()]
|
||||
}
|
||||
#[inline] fn split_fixed (&self, direction: Direction, a: N) -> ([N;4],[N;4]) {
|
||||
match direction {
|
||||
Direction::Down => (
|
||||
[self.x(), self.y(), self.w(), a],
|
||||
[self.x(), self.y() + a, self.w(), self.h() - a],
|
||||
),
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Number> Area<N> for (N, N, N, N) {
|
||||
|
|
@ -829,3 +838,33 @@ where
|
|||
#[macro_export] macro_rules! row {
|
||||
($($expr:expr),* $(,)?) => { Stack::right(move|add|{ $(add(&$expr)?;)* Ok(()) }) }
|
||||
}
|
||||
|
||||
/// A binary split with fixed proportion
|
||||
pub struct Split<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>>(
|
||||
pub Direction, pub E::Unit, A, B, PhantomData<E>
|
||||
);
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Split<E, A, B> {
|
||||
type Engine = E;
|
||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
Ok(Some(to))
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
let (a, b) = to.area().split_fixed(self.0, self.1);
|
||||
to.render_in(a.into(), &self.2)?;
|
||||
to.render_in(b.into(), &self.3)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A scrollable area.
|
||||
pub struct Scroll<
|
||||
E: Engine,
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
>(pub F, pub Direction, pub u64, PhantomData<E>);
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ impl Widget for AddSampleModal {
|
|||
|
||||
impl Handle<Tui> for AddSampleModal {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
if handle_keymap(self, &from.event(), KEYMAP_ADD_SAMPLE)? {
|
||||
if from.handle_keymap(self, KEYMAP_ADD_SAMPLE)? {
|
||||
return Ok(Some(true))
|
||||
}
|
||||
Ok(Some(true))
|
||||
|
|
|
|||
|
|
@ -72,30 +72,24 @@ struct ArrangerStandalone<E: Engine> {
|
|||
impl Content for ArrangerStandalone<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Layers::new(|add|{
|
||||
Layers::new(move|add|{
|
||||
add(&Stack::down(move|add|{
|
||||
add(&(&self.transport as &dyn Widget<Engine = Tui>).debug())?;
|
||||
if let (Some(direction), Some(sequencer)) = (
|
||||
self.show_sequencer,
|
||||
self.arranger.sequencer(),
|
||||
) {
|
||||
add(&Stack::new(direction, move|add|{
|
||||
add(&(&self.arranger as &dyn Widget<Engine = Tui>)
|
||||
.shrink_y(30)
|
||||
.debug())?;
|
||||
add(&(sequencer as &dyn Widget<Engine = Tui>)
|
||||
.min_y(20)
|
||||
.debug())?;
|
||||
Ok(())
|
||||
}))
|
||||
let arranger = &self.arranger as &dyn Widget<Engine = Tui>;
|
||||
let sequencer = sequencer as &dyn Widget<Engine = Tui>;
|
||||
add(&Split::new(direction, 40, arranger, sequencer.min_y(20)))
|
||||
} else {
|
||||
add(&self.arranger)
|
||||
}
|
||||
}));
|
||||
}))?;
|
||||
if let Some(ref modal) = self.arranger.modal {
|
||||
add(&Background(COLOR_BG1))?;
|
||||
add(&Foreground(COLOR_BG2))?;
|
||||
add(&modal as &dyn Widget<Engine = Tui>)?;
|
||||
//add(modal as &dyn Widget<Engine = Tui>)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue