mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
70 lines
2.5 KiB
Rust
70 lines
2.5 KiB
Rust
use crate::*;
|
|
|
|
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, Direction::Up, 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, Direction::Down, 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, Direction::Left, 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, Direction::Right, 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, Direction::Up, proportion, a, b, Default::default())
|
|
}
|
|
pub fn down (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
|
Self(flip, Direction::Down, proportion, a, b, Default::default())
|
|
}
|
|
pub fn left (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
|
Self(flip, Direction::Left, proportion, a, b, Default::default())
|
|
}
|
|
pub fn right (flip: bool, proportion: E::Unit, a: A, b: B) -> Self {
|
|
Self(flip, Direction::Right, 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)?;
|
|
})
|
|
}
|
|
}
|