mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
b25977d878
commit
a55e84c29f
4 changed files with 85 additions and 2 deletions
|
|
@ -1,3 +1,85 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Stack<E, F> {
|
||||
__: PhantomData<E>,
|
||||
direction: Direction,
|
||||
callback: F
|
||||
}
|
||||
impl<E, F> Stack<E, F> {
|
||||
pub fn new (direction: Direction, callback: F) -> Self {
|
||||
Self { direction, callback, __: Default::default(), }
|
||||
}
|
||||
pub fn north (callback: F) -> Self {
|
||||
Self::new(Direction::North, callback)
|
||||
}
|
||||
pub fn south (callback: F) -> Self {
|
||||
Self::new(Direction::South, callback)
|
||||
}
|
||||
pub fn east (callback: F) -> Self {
|
||||
Self::new(Direction::East, callback)
|
||||
}
|
||||
pub fn west (callback: F) -> Self {
|
||||
Self::new(Direction::West, callback)
|
||||
}
|
||||
}
|
||||
impl<E: Output, F: Fn(&mut dyn FnMut(&dyn Render<E>)->())->()> Content<E> for Stack<E, F> {
|
||||
fn layout (&self, mut to: E::Area) -> E::Area {
|
||||
let mut x = to.x();
|
||||
let mut y = to.y();
|
||||
let mut w = to.w();
|
||||
let mut h = to.h();
|
||||
(self.callback)(&mut move |component: &dyn Render<E>|{
|
||||
let layout = component.layout([x, y, w, h].into());
|
||||
match self.direction {
|
||||
Direction::North => {
|
||||
todo!()
|
||||
},
|
||||
Direction::South => {
|
||||
y = y + layout.h();
|
||||
h = h.minus(layout.h());
|
||||
},
|
||||
Direction::East => {
|
||||
x = x + layout.w();
|
||||
w = w.minus(layout.w());
|
||||
},
|
||||
Direction::West => {
|
||||
todo!()
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
});
|
||||
to
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
let mut x = to.x();
|
||||
let mut y = to.y();
|
||||
let mut w = to.w();
|
||||
let mut h = to.h();
|
||||
(self.callback)(&mut move |component: &dyn Render<E>|{
|
||||
let layout = component.layout([x, y, w, h].into());
|
||||
match self.direction {
|
||||
Direction::North => {
|
||||
todo!()
|
||||
},
|
||||
Direction::South => {
|
||||
y = y + layout.h();
|
||||
h = h.minus(layout.h());
|
||||
to.place(layout, component);
|
||||
},
|
||||
Direction::East => {
|
||||
x = x + layout.w();
|
||||
w = w.minus(layout.w());
|
||||
to.place(layout, component);
|
||||
},
|
||||
Direction::West => {
|
||||
todo!()
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*Stack::down(|add|{
|
||||
let mut i = 0;
|
||||
for (_, name) in self.dirs.iter() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue