mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-11 10:36:41 +01:00
170 lines
6.4 KiB
Rust
170 lines
6.4 KiB
Rust
//use crate::*;
|
|
//use Direction::*;
|
|
|
|
//pub struct Stack<'x, E, F1> {
|
|
//__: PhantomData<&'x (E, F1)>,
|
|
//direction: Direction,
|
|
//callback: F1
|
|
//}
|
|
|
|
//impl<'x, E, F1> Stack<'x, E, F1> {
|
|
//pub fn new (direction: Direction, callback: F1) -> Self {
|
|
//Self { direction, callback, __: Default::default(), }
|
|
//}
|
|
//pub fn above (callback: F1) -> Self {
|
|
//Self::new(Above, callback)
|
|
//}
|
|
//pub fn below (callback: F1) -> Self {
|
|
//Self::new(Below, callback)
|
|
//}
|
|
//pub fn north (callback: F1) -> Self {
|
|
//Self::new(North, callback)
|
|
//}
|
|
//pub fn south (callback: F1) -> Self {
|
|
//Self::new(South, callback)
|
|
//}
|
|
//pub fn east (callback: F1) -> Self {
|
|
//Self::new(East, callback)
|
|
//}
|
|
//pub fn west (callback: F1) -> Self {
|
|
//Self::new(West, callback)
|
|
//}
|
|
//}
|
|
|
|
//impl<'x, E: Out, F1: Fn(&mut dyn FnMut(&dyn Layout<E>))> Layout<E> for Stack<'x, E, F1> {
|
|
//fn layout (&self, to: E::Area) -> E::Area {
|
|
//let state = StackLayoutState::<E>::new(self.direction, to);
|
|
//(self.callback)(&mut |component: &dyn Layout<E>|{
|
|
//let StackLayoutState { x, y, w_remaining, h_remaining, .. } = *state.borrow();
|
|
//let [_, _, w, h] = component.layout([x, y, w_remaining, h_remaining].into()).xywh();
|
|
//state.borrow_mut().grow(w, h);
|
|
//});
|
|
//let StackLayoutState { w_used, h_used, .. } = *state.borrow();
|
|
//match self.direction {
|
|
//North | West => { todo!() },
|
|
//South | East => { [to.x(), to.y(), w_used, h_used].into() },
|
|
//_ => unreachable!(),
|
|
//}
|
|
//}
|
|
//}
|
|
//impl<'x, E: Out, F1: Fn(&mut dyn FnMut(&dyn Draw<E>))> Draw<E> for Stack<'x, E, F1> {
|
|
//fn draw (&self, to: &mut E) {
|
|
//let state = StackLayoutState::<E>::new(self.direction, to.area());
|
|
//let to = Rc::new(RefCell::new(to));
|
|
//(self.callback)(&mut |component: &dyn Draw<E>|{
|
|
//let StackLayoutState { x, y, w_remaining, h_remaining, .. } = *state.borrow();
|
|
//let layout = component.layout([x, y, w_remaining, h_remaining].into());
|
|
//state.borrow_mut().grow(layout.w(), layout.h());
|
|
//to.borrow_mut().place_at(layout, component);
|
|
//});
|
|
//}
|
|
//}
|
|
|
|
//#[derive(Copy, Clone)]
|
|
//struct StackLayoutState<E: Out> {
|
|
//direction: Direction,
|
|
//x: E::Unit,
|
|
//y: E::Unit,
|
|
//w_used: E::Unit,
|
|
//h_used: E::Unit,
|
|
//w_remaining: E::Unit,
|
|
//h_remaining: E::Unit,
|
|
//}
|
|
//impl<E: Out> StackLayoutState<E> {
|
|
//fn new (direction: Direction, area: E::Area) -> std::rc::Rc<std::cell::RefCell<Self>> {
|
|
//let [x, y, w_remaining, h_remaining] = area.xywh();
|
|
//std::rc::Rc::new(std::cell::RefCell::new(Self {
|
|
//direction,
|
|
//x, y, w_remaining, h_remaining,
|
|
//w_used: E::Unit::zero(), h_used: E::Unit::zero()
|
|
//}))
|
|
//}
|
|
//fn grow (&mut self, w: E::Unit, h: E::Unit) -> &mut Self {
|
|
//match self.direction {
|
|
//South => { self.y = self.y.plus(h);
|
|
//self.h_used = self.h_used.plus(h);
|
|
//self.h_remaining = self.h_remaining.minus(h);
|
|
//self.w_used = self.w_used.max(w); },
|
|
//East => { self.x = self.x.plus(w);
|
|
//self.w_used = self.w_used.plus(w);
|
|
//self.w_remaining = self.w_remaining.minus(w);
|
|
//self.h_used = self.h_used.max(h); },
|
|
//North | West => { todo!() },
|
|
//Above | Below => {},
|
|
//};
|
|
//self
|
|
//}
|
|
//fn area_remaining (&self) -> E::Area {
|
|
//[self.x, self.y, self.w_remaining, self.h_remaining].into()
|
|
//}
|
|
//}
|
|
|
|
////pub struct Stack<'a, E, F1> {
|
|
////__: PhantomData<&'a (E, F1)>,
|
|
////direction: Direction,
|
|
////callback: F1
|
|
////}
|
|
////impl<'a, E, F1> Stack<'a, E, F1> where
|
|
////E: Out, F1: Fn(&mut dyn FnMut(&'a dyn Draw<E>)) + Send + Sync,
|
|
////{
|
|
////pub fn north (callback: F1) -> Self { Self::new(North, callback) }
|
|
////pub fn south (callback: F1) -> Self { Self::new(South, callback) }
|
|
////pub fn east (callback: F1) -> Self { Self::new(East, callback) }
|
|
////pub fn west (callback: F1) -> Self { Self::new(West, callback) }
|
|
////pub fn above (callback: F1) -> Self { Self::new(Above, callback) }
|
|
////pub fn below (callback: F1) -> Self { Self::new(Below, callback) }
|
|
////pub fn new (direction: Direction, callback: F1) -> Self {
|
|
////Self { direction, callback, __: Default::default(), }
|
|
////}
|
|
////}
|
|
////impl<'a, E, F1> Draw<E> for Stack<'a, E, F1> where
|
|
////E: Out, F1: Fn(&mut dyn FnMut(&'a dyn Draw<E>)) + Send + Sync,
|
|
////{
|
|
////fn layout (&self, to: E::Area) -> E::Area {
|
|
////let state = StackLayoutState::<E>::new(self.direction, to);
|
|
////let mut adder = {
|
|
////let state = state.clone();
|
|
////move|component: &dyn Draw<E>|{
|
|
////let [w, h] = component.layout(state.borrow().area_remaining()).wh();
|
|
////state.borrow_mut().grow(w, h);
|
|
////}
|
|
////};
|
|
////(self.callback)(&mut adder);
|
|
////let StackLayoutState { w_used, h_used, .. } = *state.borrow();
|
|
////match self.direction {
|
|
////North | West => { todo!() },
|
|
////South | East => { [to.x(), to.y(), w_used, h_used].into() },
|
|
////Above | Below => { [to.x(), to.y(), to.w(), to.h()].into() },
|
|
////}
|
|
////}
|
|
////fn draw (&self, to: &mut E) {
|
|
////let state = StackLayoutState::<E>::new(self.direction, to.area());
|
|
////let mut adder = {
|
|
////let state = state.clone();
|
|
////move|component: &dyn Draw<E>|{
|
|
////let [x, y, w, h] = component.layout(state.borrow().area_remaining()).xywh();
|
|
////state.borrow_mut().grow(w, h);
|
|
////to.place_at([x, y, w, h].into(), component);
|
|
////}
|
|
////};
|
|
////(self.callback)(&mut adder);
|
|
////}
|
|
////}
|
|
|
|
//[>Stack::down(|add|{
|
|
//let mut i = 0;
|
|
//for (_, name) in self.dirs.iter() {
|
|
//if i >= self.scroll {
|
|
//add(&Tui::bold(i == self.index, name.as_str()))?;
|
|
//}
|
|
//i += 1;
|
|
//}
|
|
//for (_, name) in self.files.iter() {
|
|
//if i >= self.scroll {
|
|
//add(&Tui::bold(i == self.index, name.as_str()))?;
|
|
//}
|
|
//i += 1;
|
|
//}
|
|
//add(&format!("{}/{i}", self.index))?;
|
|
//Ok(())
|
|
//}));*/
|