mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: add TuiStyle, unifying Modal
This commit is contained in:
parent
7c555848e4
commit
29f11b5977
6 changed files with 467 additions and 434 deletions
|
|
@ -108,26 +108,151 @@ impl<N: Number> Area<N> for [N;4] {
|
|||
#[inline] fn h (&self) -> N { self[3] }
|
||||
}
|
||||
|
||||
pub struct Split<
|
||||
E: Engine,
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
>(pub F, pub Direction, PhantomData<E>);
|
||||
pub trait Layout<E: Engine>: Widget<Engine = E> + Sized {
|
||||
fn align_center (self) -> Align<Self> {
|
||||
Align::Center(self)
|
||||
}
|
||||
fn align_x (self) -> Align<Self> {
|
||||
Align::X(self)
|
||||
}
|
||||
fn align_y (self) -> Align<Self> {
|
||||
Align::Y(self)
|
||||
}
|
||||
fn fixed_x (self, x: E::Unit) -> Fixed<E::Unit, Self> {
|
||||
Fixed::X(x, self)
|
||||
}
|
||||
fn fixed_y (self, y: E::Unit) -> Fixed<E::Unit, Self> {
|
||||
Fixed::Y(y, self)
|
||||
}
|
||||
fn fixed_xy (self, x: E::Unit, y: E::Unit) -> Fixed<E::Unit, Self> {
|
||||
Fixed::XY(x, y, self)
|
||||
}
|
||||
fn min_x (self, x: E::Unit) -> Min<E::Unit, Self> {
|
||||
Min::X(x, self)
|
||||
}
|
||||
fn min_y (self, y: E::Unit) -> Min<E::Unit, Self> {
|
||||
Min::Y(y, self)
|
||||
}
|
||||
fn min_xy (self, x: E::Unit, y: E::Unit) -> Min<E::Unit, Self> {
|
||||
Min::XY(x, y, self)
|
||||
}
|
||||
fn max_x (self, x: E::Unit) -> Max<E::Unit, Self> {
|
||||
Max::X(x, self)
|
||||
}
|
||||
fn max_y (self, y: E::Unit) -> Max<E::Unit, Self> {
|
||||
Max::Y(y, self)
|
||||
}
|
||||
fn max_xy (self, x: E::Unit, y: E::Unit) -> Max<E::Unit, Self> {
|
||||
Max::XY(x, y, self)
|
||||
}
|
||||
fn push_x (self, x: E::Unit) -> Push<E::Unit, Self> {
|
||||
Push::X(x, self)
|
||||
}
|
||||
fn push_y (self, y: E::Unit) -> Push<E::Unit, Self> {
|
||||
Push::Y(y, self)
|
||||
}
|
||||
fn push_xy (self, x: E::Unit, y: E::Unit) -> Push<E::Unit, Self> {
|
||||
Push::XY(x, y, self)
|
||||
}
|
||||
fn pull_x (self, x: E::Unit) -> Pull<E::Unit, Self> {
|
||||
Pull::X(x, self)
|
||||
}
|
||||
fn pull_y (self, y: E::Unit) -> Pull<E::Unit, Self> {
|
||||
Pull::Y(y, self)
|
||||
}
|
||||
fn pull_xy (self, x: E::Unit, y: E::Unit) -> Pull<E::Unit, Self> {
|
||||
Pull::XY(x, y, self)
|
||||
}
|
||||
fn grow_x (self, x: E::Unit) -> Grow<E::Unit, Self> {
|
||||
Grow::X(x, self)
|
||||
}
|
||||
fn grow_y (self, y: E::Unit) -> Grow<E::Unit, Self> {
|
||||
Grow::Y(y, self)
|
||||
}
|
||||
fn grow_xy (self, x: E::Unit, y: E::Unit) -> Grow<E::Unit, Self> {
|
||||
Grow::XY(x, y, self)
|
||||
}
|
||||
fn shrink_x (self, x: E::Unit) -> Shrink<E::Unit, Self> {
|
||||
Shrink::X(x, self)
|
||||
}
|
||||
fn shrink_y (self, y: E::Unit) -> Shrink<E::Unit, Self> {
|
||||
Shrink::Y(y, self)
|
||||
}
|
||||
fn shrink_xy (self, x: E::Unit, y: E::Unit) -> Shrink<E::Unit, Self> {
|
||||
Shrink::XY(x, y, self)
|
||||
}
|
||||
fn inset_x (self, x: E::Unit) -> Inset<E::Unit, Self> {
|
||||
Inset::X(x, self)
|
||||
}
|
||||
fn inset_y (self, y: E::Unit) -> Inset<E::Unit, Self> {
|
||||
Inset::Y(y, self)
|
||||
}
|
||||
fn inset_xy (self, x: E::Unit, y: E::Unit) -> Inset<E::Unit, Self> {
|
||||
Inset::XY(x, y, self)
|
||||
}
|
||||
fn outset_x (self, x: E::Unit) -> Outset<E::Unit, Self> {
|
||||
Outset::X(x, self)
|
||||
}
|
||||
fn outset_y (self, y: E::Unit) -> Outset<E::Unit, Self> {
|
||||
Outset::Y(y, self)
|
||||
}
|
||||
fn outset_xy (self, x: E::Unit, y: E::Unit) -> Outset<E::Unit, Self> {
|
||||
Outset::XY(x, y, self)
|
||||
}
|
||||
fn fill_x (self) -> Fill<E, Self> {
|
||||
Fill::X(self)
|
||||
}
|
||||
fn fill_y (self) -> Fill<E, Self> {
|
||||
Fill::Y(self)
|
||||
}
|
||||
fn fill_xy (self) -> Fill<E, Self> {
|
||||
Fill::XY(self)
|
||||
}
|
||||
fn debug (self) -> DebugOverlay<E, Self> {
|
||||
DebugOverlay(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E: Engine,
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
> Split<E, F> {
|
||||
#[inline]
|
||||
pub fn new (direction: Direction, build: F) -> Self {
|
||||
Self(build, direction, Default::default())
|
||||
impl<E: Engine, W: Widget<Engine = E>> Layout<E> for W {}
|
||||
|
||||
pub struct DebugOverlay<E: Engine, W: Widget<Engine = E>>(pub W);
|
||||
|
||||
pub struct ModalHost<E: Engine, M: Widget<Engine = E>, W: Widget<Engine = E>>(
|
||||
pub bool, pub M, pub W
|
||||
);
|
||||
|
||||
pub enum Fill<E: Engine, W: Widget<Engine = E>> {
|
||||
X(W),
|
||||
Y(W),
|
||||
XY(W)
|
||||
}
|
||||
|
||||
impl<E: Engine, W: Widget<Engine = E>> Fill<E, W> {
|
||||
fn inner (&self) -> &W {
|
||||
match self {
|
||||
Self::X(inner) => &inner,
|
||||
Self::Y(inner) => &inner,
|
||||
Self::XY(inner) => &inner,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn right (build: F) -> Self {
|
||||
Self::new(Direction::Right, build)
|
||||
}
|
||||
|
||||
impl<E: Engine, W: Widget<Engine = E>> Widget for Fill<E, W> {
|
||||
type Engine = E;
|
||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
let area = self.inner().layout(to.into())?;
|
||||
if let Some(area) = area {
|
||||
Ok(Some(match self {
|
||||
Self::X(_) => [to.w().into(), area.h()],
|
||||
Self::Y(_) => [area.w(), to.h().into()],
|
||||
Self::XY(_) => [to.w().into(), to.h().into()],
|
||||
}.into()))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn down (build: F) -> Self {
|
||||
Self::new(Direction::Down, build)
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
self.inner().render(to)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,17 +297,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
//pub fn collect <'a, E: Engine, const N: usize> (
|
||||
//items: &'a [&'a dyn Widget<Engine = E>;N]
|
||||
//) -> impl Send + Sync + Fn(&'a mut dyn FnMut(&'a dyn Widget<Engine = E>)->Usually<()>)->Usually<()> + '_ {
|
||||
//|add: &'a mut dyn FnMut(&'a dyn Widget<Engine = E>)->Usually<()>| {
|
||||
//for item in items.iter() {
|
||||
//add(item)?;
|
||||
//}
|
||||
//Ok(())
|
||||
//}
|
||||
//}
|
||||
|
||||
//`Layers<_, impl (Fn(&mut dyn FnMut(&dyn Widget<Engine = _>) -> Result<(), Box<...>>) -> ... ) + Send + Sync>`
|
||||
//`Layers<Tui, impl (Fn(&mut dyn FnMut(&dyn Widget<Engine = Tui>) -> Result<(), Box<(dyn std::error::Error + 'static)>>) -> Result<(), Box<(dyn std::error::Error + 'static)>>) + Send + Sync + '_>`
|
||||
|
||||
|
|
@ -446,7 +560,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Shrink<E::Unit, T> {
|
|||
],
|
||||
Self::Y(h, _) => [
|
||||
to.w(),
|
||||
if to.h() > h { to.h() - h } else { 0.into() }
|
||||
if to.h() > h { to.h() - h } else { 0.into() }
|
||||
],
|
||||
Self::XY(w, h, _) => [
|
||||
if to.w() > w { to.w() - w } else { 0.into() },
|
||||
|
|
@ -605,6 +719,26 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Pull<E::Unit, T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Split<
|
||||
E: Engine,
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
>(pub F, pub Direction, PhantomData<E>);
|
||||
|
||||
impl<
|
||||
E: Engine,
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
> Split<E, F> {
|
||||
#[inline] pub fn new (direction: Direction, build: F) -> Self {
|
||||
Self(build, direction, Default::default())
|
||||
}
|
||||
#[inline] pub fn right (build: F) -> Self {
|
||||
Self::new(Direction::Right, build)
|
||||
}
|
||||
#[inline] pub fn down (build: F) -> Self {
|
||||
Self::new(Direction::Down, build)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine, F> Widget for Split<E, F>
|
||||
where
|
||||
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()>
|
||||
|
|
@ -693,3 +827,13 @@ where
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! lay {
|
||||
($($expr:expr),* $(,)?) => { Layers::new(move|add|{ $(add(&$expr)?;)* Ok(()) }) }
|
||||
}
|
||||
#[macro_export] macro_rules! col {
|
||||
($($expr:expr),* $(,)?) => { Split::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }
|
||||
}
|
||||
#[macro_export] macro_rules! row {
|
||||
($($expr:expr),* $(,)?) => { Split::right(move|add|{ $(add(&$expr)?;)* Ok(()) }) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue