flatten workspace into 1 crate

This commit is contained in:
🪞👃🪞 2024-12-29 00:10:30 +01:00
parent 7c4e1e2166
commit d926422c67
147 changed files with 66 additions and 126 deletions

71
src/space/split.rs Normal file
View file

@ -0,0 +1,71 @@
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>
);
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 {
Self(flip, North, proportion, a, b, Default::default())
}
pub fn down (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 {
Self(flip, West, proportion, a, b, Default::default())
}
pub fn right (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
Self(flip, East, proportion, a, b, Default::default())
}
}
impl<E: Engine, A: Render<E>, B: Render<E>> Render<E> for Split<E, A, B> {
fn min_size (&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.1, self.2);
Ok(if self.0 {
to.render_in(a.into(), &self.4)?;
to.render_in(b.into(), &self.3)?;
} else {
to.render_in(a.into(), &self.3)?;
to.render_in(b.into(), &self.4)?;
})
}
}