mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
implement fixed Split
This commit is contained in:
parent
e555074bdf
commit
cd0b8a6812
4 changed files with 50 additions and 15 deletions
|
|
@ -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>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue