mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
This commit is contained in:
parent
b25977d878
commit
a55e84c29f
4 changed files with 85 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ mod align; pub use self::align::*;
|
|||
mod bsp; pub use self::bsp::*;
|
||||
mod cond; pub use self::cond::*;
|
||||
mod map; pub use self::map::*;
|
||||
mod stack; pub use self::stack::*;
|
||||
//mod reduce; pub use self::reduce::*;
|
||||
mod thunk; pub use self::thunk::*;
|
||||
mod transform; pub use self::transform::*;
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub trait Output: Send + Sync + Sized {
|
|||
/// Mutable pointer to area
|
||||
fn area_mut (&mut self) -> &mut Self::Area;
|
||||
/// Render widget in area
|
||||
fn place (&mut self, area: Self::Area, content: &impl Render<Self>);
|
||||
fn place <T: Render<Self> + ?Sized> (&mut self, area: Self::Area, content: &T);
|
||||
#[inline] fn x (&self) -> Self::Unit { self.area().x() }
|
||||
#[inline] fn y (&self) -> Self::Unit { self.area().y() }
|
||||
#[inline] fn w (&self) -> Self::Unit { self.area().w() }
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ impl Output for TuiOut {
|
|||
type Area = [Self::Unit;4];
|
||||
#[inline] fn area (&self) -> [u16;4] { self.area }
|
||||
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
|
||||
#[inline] fn place (&mut self, area: [u16;4], content: &impl Render<TuiOut>) {
|
||||
#[inline] fn place <T: Render<Self> + ?Sized> (&mut self, area: [u16;4], content: &T) {
|
||||
let last = self.area();
|
||||
*self.area_mut() = area;
|
||||
content.render(self);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue