mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-28 05:06:56 +02:00
This commit is contained in:
parent
41ef62146b
commit
4172fa2577
13 changed files with 250 additions and 248 deletions
2
dizzle
2
dizzle
|
|
@ -1 +1 @@
|
||||||
Subproject commit c00aed72086f23aa21e6f28f9e722af61faf240e
|
Subproject commit a3d7719bcc955552a5dbcf755115333872e87de4
|
||||||
|
|
@ -1,44 +1,44 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> Layout<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> Layout<'a, S> for T {}
|
||||||
|
|
||||||
pub trait Layout<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait Layout<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn origin (self, azimuth: impl Into<Option<Azimuth>>) -> impl Draw<'a, S> {
|
fn origin (self, azimuth: impl Into<Option<Azimuth>>) -> impl Draw<S> {
|
||||||
Origin(azimuth.into(), self)
|
Origin(azimuth.into(), self)
|
||||||
}
|
}
|
||||||
fn origin_c (self) -> impl Draw<'a, S> {
|
fn origin_c (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::C), self)
|
Origin(Some(Azimuth::C), self)
|
||||||
}
|
}
|
||||||
fn origin_x (self) -> impl Draw<'a, S> {
|
fn origin_x (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::X), self)
|
Origin(Some(Azimuth::X), self)
|
||||||
}
|
}
|
||||||
fn origin_y (self) -> impl Draw<'a, S> {
|
fn origin_y (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::Y), self)
|
Origin(Some(Azimuth::Y), self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn origin_n (self) -> impl Draw<'a, S> {
|
fn origin_n (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::N), self)
|
Origin(Some(Azimuth::N), self)
|
||||||
}
|
}
|
||||||
fn origin_s (self) -> impl Draw<'a, S> {
|
fn origin_s (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::S), self)
|
Origin(Some(Azimuth::S), self)
|
||||||
}
|
}
|
||||||
fn origin_e (self) -> impl Draw<'a, S> {
|
fn origin_e (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::E), self)
|
Origin(Some(Azimuth::E), self)
|
||||||
}
|
}
|
||||||
fn origin_w (self) -> impl Draw<'a, S> {
|
fn origin_w (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::W), self)
|
Origin(Some(Azimuth::W), self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn origin_ne (self) -> impl Draw<'a, S> {
|
fn origin_ne (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::NE), self)
|
Origin(Some(Azimuth::NE), self)
|
||||||
}
|
}
|
||||||
fn origin_se (self) -> impl Draw<'a, S> {
|
fn origin_se (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::SE), self)
|
Origin(Some(Azimuth::SE), self)
|
||||||
}
|
}
|
||||||
fn origin_nw (self) -> impl Draw<'a, S> {
|
fn origin_nw (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::NW), self)
|
Origin(Some(Azimuth::NW), self)
|
||||||
}
|
}
|
||||||
fn origin_sw (self) -> impl Draw<'a, S> {
|
fn origin_sw (self) -> impl Draw<S> {
|
||||||
Origin(Some(Azimuth::SW), self)
|
Origin(Some(Azimuth::SW), self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ impl PartialEq for Sizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sizer {
|
impl Sizer {
|
||||||
pub const fn of <'a, T: Screen> (&self, of: impl Draw<'a, T>) -> impl Draw<'a, T> {
|
pub const fn of <'a, T: Screen> (&self, of: impl Draw<T>) -> impl Draw<T> {
|
||||||
draw(move|to: &mut T|{
|
draw(move|to: &mut T|{
|
||||||
let area = of.draw(to)?;
|
let area = of.draw(to)?;
|
||||||
self.0.store(area.map(|a|a.w()).unwrap_or(T::Unit::zero()).into(), Relaxed);
|
self.0.store(area.map(|a|a.w()).unwrap_or(T::Unit::zero()).into(), Relaxed);
|
||||||
|
|
@ -102,10 +102,10 @@ impl Sizer {
|
||||||
#[macro_export] macro_rules! fn_kw_layout {
|
#[macro_export] macro_rules! fn_kw_layout {
|
||||||
($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => {
|
($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => {
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn $name <'a, O: Screen, S> (
|
pub fn $name <O: Screen, S> (
|
||||||
$state: &'a S, $output: &mut O, $expr: &'a str
|
$state: &S, $output: &mut O, $expr: &str
|
||||||
) -> PerhapsRef<'a, XYWH<O::Unit>> where
|
) -> Perhaps<XYWH<O::Unit>> where
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -116,10 +116,10 @@ impl Sizer {
|
||||||
#[macro_export] macro_rules! fn_kw_layout_tui {
|
#[macro_export] macro_rules! fn_kw_layout_tui {
|
||||||
($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => {
|
($name:ident |$state:ident, $output: ident, $expr:ident| $body:block) => {
|
||||||
#[cfg(all(feature = "draw", feature = "eval", feature = "term"))]
|
#[cfg(all(feature = "draw", feature = "eval", feature = "term"))]
|
||||||
pub fn $name <'a, S> (
|
pub fn $name <S> (
|
||||||
$state: &'a S, $output: &mut Tui, $expr: &'a str
|
$state: &S, $output: &mut Tui, $expr: &str
|
||||||
) -> PerhapsRef<'a, XYWH<u16>> where
|
) -> Perhaps<XYWH<u16>> where
|
||||||
S: Interpret<'a, Tui, Option<XYWH<u16>>>
|
S: Interpret<Tui, Option<XYWH<u16>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<u16>
|
+ Namespace<u16>
|
||||||
+ Namespace<Option<u16>>
|
+ Namespace<Option<u16>>
|
||||||
|
|
@ -134,9 +134,9 @@ impl Sizer {
|
||||||
$Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal
|
$Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal
|
||||||
|$self:ident, $to:ident| $body:block
|
|$self:ident, $to:ident| $body:block
|
||||||
) => {
|
) => {
|
||||||
impl<S: Screen, T: Draw<'a, S>> $Trait<S> for T {}
|
impl<S: Screen, T: Draw<S>> $Trait<S> for T {}
|
||||||
|
|
||||||
pub trait $Trait<S: Screen>: Draw<'a, S> + Sized {
|
pub trait $Trait<S: Screen>: Draw<S> + Sized {
|
||||||
fn $fn_x <N: Into<Option<S::Unit>> + Copy> (self, x: N)
|
fn $fn_x <N: Into<Option<S::Unit>> + Copy> (self, x: N)
|
||||||
-> $Struct<S, Self, N> { $Struct::$X(self, x) }
|
-> $Struct<S, Self, N> { $Struct::$X(self, x) }
|
||||||
fn $fn_y <N: Into<Option<S::Unit>> + Copy> (self, y: N)
|
fn $fn_y <N: Into<Option<S::Unit>> + Copy> (self, y: N)
|
||||||
|
|
@ -145,11 +145,11 @@ impl Sizer {
|
||||||
-> $Struct<S, Self, N> { $Struct::$XY(self, x, y) }
|
-> $Struct<S, Self, N> { $Struct::$XY(self, x, y) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum $Struct<S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum $Struct<S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<S>), $X(I, X), $Y(I, X), $XY(I, X, X),
|
__(PhantomData<S>), $X(I, X), $Y(I, X), $XY(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for $Struct<S, I, X> {
|
impl <S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for $Struct<S, I, X> {
|
||||||
fn draw (&$self, $to: &mut S) -> Perhaps<XYWH<S::Unit>> { $body }
|
fn draw (&$self, $to: &mut S) -> Perhaps<XYWH<S::Unit>> { $body }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,9 +175,9 @@ impl Sizer {
|
||||||
$Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal
|
$Struct:ident { $X:ident $Y:ident $XY:ident } $kw_name:ident $name:literal
|
||||||
|$self:ident, $to:ident| $body:block
|
|$self:ident, $to:ident| $body:block
|
||||||
) => {
|
) => {
|
||||||
impl<S: Screen, T: Draw<'a, S>> $Trait<S> for T {}
|
impl<S: Screen, T: Draw<S>> $Trait<S> for T {}
|
||||||
|
|
||||||
pub trait $Trait<S: Screen>: Draw<'a, S> + Sized {
|
pub trait $Trait<S: Screen>: Draw<S> + Sized {
|
||||||
fn $fn_x (self) -> $Struct<S, Self> { $Struct::$X(self) }
|
fn $fn_x (self) -> $Struct<S, Self> { $Struct::$X(self) }
|
||||||
fn $fn_y (self) -> $Struct<S, Self> { $Struct::$Y(self) }
|
fn $fn_y (self) -> $Struct<S, Self> { $Struct::$Y(self) }
|
||||||
fn $fn_xy (self) -> $Struct<S, Self> { $Struct::$XY(self) }
|
fn $fn_xy (self) -> $Struct<S, Self> { $Struct::$XY(self) }
|
||||||
|
|
@ -187,7 +187,7 @@ impl Sizer {
|
||||||
__(PhantomData<S>), $X(I), $Y(I), $XY(I),
|
__(PhantomData<S>), $X(I), $Y(I), $XY(I),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for $Struct<S, I> {
|
impl <'a, S: Screen, I: Draw<S>> Draw<S> for $Struct<S, I> {
|
||||||
fn draw (&$self, $to: &mut S) -> Perhaps<XYWH<S::Unit>> { $body }
|
fn draw (&$self, $to: &mut S) -> Perhaps<XYWH<S::Unit>> { $body }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::*;
|
||||||
/// let _ = area(XYWH(1, 2, 3, 4), "southeast");
|
/// let _ = area(XYWH(1, 2, 3, 4), "southeast");
|
||||||
/// let _ = area(Some(XYWH(1, 2, 3, 4)), "southeast");
|
/// let _ = area(Some(XYWH(1, 2, 3, 4)), "southeast");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn area <'a, S: Screen, T: Draw<'a, S>, U: Into<Option<XYWH<S::Unit>>>> (
|
pub fn area <'a, S: Screen, T: Draw<S>, U: Into<Option<XYWH<S::Unit>>>> (
|
||||||
origin: U, it: T
|
origin: U, it: T
|
||||||
) -> Area<S, T> {
|
) -> Area<S, T> {
|
||||||
Area(origin.into(), it)
|
Area(origin.into(), it)
|
||||||
|
|
@ -17,8 +17,8 @@ pub struct Area<S: Screen, T>(
|
||||||
pub T,
|
pub T,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Area<S, T> {
|
impl<'a, S: Screen, T: Draw<S>> Draw<S> for Area<S, T> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
to.draw(self.0, &self.1)
|
to.draw(self.0, &self.1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,30 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub enum Full<'a, S: Screen, I: Draw<'a, S>> {
|
pub enum Full<'a, S: Screen, I: Draw<S>> {
|
||||||
__(PhantomData<&'a S>), W(I), H(I), WH(I),
|
__(PhantomData<&'a S>), W(I), H(I), WH(I),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Exact<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Exact<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Push<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Push<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Pull<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Pull<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Min<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Min<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Max<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Max<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
__(PhantomData<&'a S>), W(I, X), H(I, X), WH(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Pad<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
pub enum Pad<'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>>> {
|
||||||
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
__(PhantomData<&'a S>), X(I, X), Y(I, X), XY(I, X, X),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ pub enum Pad<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
|
||||||
/// assert_eq!(check_layout("1".full_wh())?, Some(XYWH(1u16, 1, 80, 25)));
|
/// assert_eq!(check_layout("1".full_wh())?, Some(XYWH(1u16, 1, 80, 25)));
|
||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait LayoutFull<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutFull<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn full_w (self) -> Full<'a, S, Self> { Full::W(self) }
|
fn full_w (self) -> Full<'a, S, Self> { Full::W(self) }
|
||||||
fn full_h (self) -> Full<'a, S, Self> { Full::H(self) }
|
fn full_h (self) -> Full<'a, S, Self> { Full::H(self) }
|
||||||
fn full_wh (self) -> Full<'a, S, Self> { Full::WH(self) }
|
fn full_wh (self) -> Full<'a, S, Self> { Full::WH(self) }
|
||||||
|
|
@ -50,7 +50,7 @@ pub trait LayoutFull<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
/// assert_eq!(check_layout("FOOBAR\nKILROY".exact_wh(2, 1))?, Some(XYWH(1, 1, 2, 1)));
|
/// assert_eq!(check_layout("FOOBAR\nKILROY".exact_wh(2, 1))?, Some(XYWH(1, 1, 2, 1)));
|
||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait LayoutExact<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutExact<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn exact_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn exact_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Exact<'a, S, Self, X> { Exact::W(self, w) }
|
-> Exact<'a, S, Self, X> { Exact::W(self, w) }
|
||||||
fn exact_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn exact_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -67,7 +67,7 @@ pub trait LayoutExact<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
/// assert_eq!(check_layout("123456".min_w(5))?, Some(XYWH(1u16, 1, 6, 1)));
|
/// assert_eq!(check_layout("123456".min_w(5))?, Some(XYWH(1u16, 1, 6, 1)));
|
||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait LayoutMin<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutMin<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn min_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn min_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Min<'a, S, Self, X> { Min::W(self, w) }
|
-> Min<'a, S, Self, X> { Min::W(self, w) }
|
||||||
fn min_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn min_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -76,7 +76,7 @@ pub trait LayoutMin<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
-> Min<'a, S, Self, X> { Min::WH(self, w, h) }
|
-> Min<'a, S, Self, X> { Min::WH(self, w, h) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutMax<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutMax<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn max_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn max_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Max<'a, S, Self, X> { Max::W(self, w) }
|
-> Max<'a, S, Self, X> { Max::W(self, w) }
|
||||||
fn max_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn max_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -85,7 +85,7 @@ pub trait LayoutMax<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
-> Max<'a, S, Self, X> { Max::WH(self, w, h) }
|
-> Max<'a, S, Self, X> { Max::WH(self, w, h) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutPad<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutPad<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn pad_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn pad_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Pad<'a, S, Self, X> { Pad::X(self, w) }
|
-> Pad<'a, S, Self, X> { Pad::X(self, w) }
|
||||||
fn pad_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn pad_h <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -102,7 +102,7 @@ pub trait LayoutPad<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
/// assert_eq!(check_layout("1".push_xy(1, 1))?, Some(XYWH(2u16, 2, 1, 1)));
|
/// assert_eq!(check_layout("1".push_xy(1, 1))?, Some(XYWH(2u16, 2, 1, 1)));
|
||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait LayoutPush<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutPush<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn push_x <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn push_x <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Push<'a, S, Self, X> { Push::X(self, w) }
|
-> Push<'a, S, Self, X> { Push::X(self, w) }
|
||||||
fn push_y <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn push_y <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -119,7 +119,7 @@ pub trait LayoutPush<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
/// assert_eq!(check_layout("1".pull_xy(1, 1))?, Some(XYWH(0u16, 0, 1, 1)));
|
/// assert_eq!(check_layout("1".pull_xy(1, 1))?, Some(XYWH(0u16, 0, 1, 1)));
|
||||||
/// # Ok(()) }
|
/// # Ok(()) }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait LayoutPull<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait LayoutPull<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn pull_x <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
fn pull_x <X: Into<Option<S::Unit>> + Copy> (self, w: X)
|
||||||
-> Pull<'a, S, Self, X> { Pull::X(self, w) }
|
-> Pull<'a, S, Self, X> { Pull::X(self, w) }
|
||||||
fn pull_y <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
fn pull_y <X: Into<Option<S::Unit>> + Copy> (self, h: X)
|
||||||
|
|
@ -129,11 +129,11 @@ pub trait LayoutPull<'a, S: Screen>: Draw<'a, S> + Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_full <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_full <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -143,16 +143,16 @@ where
|
||||||
Some("full/x") | Some("full/w") => Full::W(thunk).draw(to)?,
|
Some("full/x") | Some("full/w") => Full::W(thunk).draw(to)?,
|
||||||
Some("full/y") | Some("full/h") => Full::H(thunk).draw(to)?,
|
Some("full/y") | Some("full/h") => Full::H(thunk).draw(to)?,
|
||||||
Some("full/xy") | Some("full/wh") => Full::WH(thunk).draw(to)?,
|
Some("full/xy") | Some("full/wh") => Full::WH(thunk).draw(to)?,
|
||||||
frag => return Err(format!("invalid variant: {frag:?}").into())
|
frag => return Err(format!("full: invalid variant: {frag:?}").into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_exact <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_exact <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -169,16 +169,16 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("exact: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_min <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_min <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -195,16 +195,16 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("min: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_max <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_max <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -221,16 +221,16 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("max: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_push <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_push <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -243,16 +243,16 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("push: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_pull <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_pull <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -265,16 +265,16 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("pull: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_pad <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_pad <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> PerhapsRef<'a, XYWH<O::Unit>>
|
-> Perhaps<XYWH<O::Unit>>
|
||||||
where
|
where
|
||||||
O: Screen + 'a,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -291,12 +291,12 @@ where
|
||||||
state.namespace(&expr.nth(1)?)?,
|
state.namespace(&expr.nth(1)?)?,
|
||||||
state.namespace(&expr.nth(2)?)?,
|
state.namespace(&expr.nth(2)?)?,
|
||||||
).draw(to)?,
|
).draw(to)?,
|
||||||
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
|
_ => return Err(format!("pad: invalid variant: {:?}", expr.head()?).into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for Full<'a, S, I> {
|
impl <'a, S: Screen, I: Draw<S>> Draw<S> for Full<'a, S, I> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let XYWH(x0, y0, w0, h0) = to.area();
|
let XYWH(x0, y0, w0, h0) = to.area();
|
||||||
let item = match self {
|
let item = match self {
|
||||||
Self::W(i) => i, Self::H(i) => i, Self::WH(i) => i, _ => unreachable!()
|
Self::W(i) => i, Self::H(i) => i, Self::WH(i) => i, _ => unreachable!()
|
||||||
|
|
@ -313,8 +313,8 @@ impl <'a, S: Screen, I: Draw<'a, S>> Draw<'a, S> for Full<'a, S, I> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Exact<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Exact<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let XYWH(x0, y0, w0, h0) = to.area();
|
let XYWH(x0, y0, w0, h0) = to.area();
|
||||||
let (item, w1, h1) = match self {
|
let (item, w1, h1) = match self {
|
||||||
Self::W(item, w1) => (item, (*w1).into(), None),
|
Self::W(item, w1) => (item, (*w1).into(), None),
|
||||||
|
|
@ -335,8 +335,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Min<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Min<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let XYWH(x0, y0, w0, h0) = to.area();
|
let XYWH(x0, y0, w0, h0) = to.area();
|
||||||
let (item, w1, h1) = match self {
|
let (item, w1, h1) = match self {
|
||||||
Self::W(item, w1) => (item, (*w1).into(), None),
|
Self::W(item, w1) => (item, (*w1).into(), None),
|
||||||
|
|
@ -356,8 +356,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Max<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Max<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let XYWH(x, y, w0, h0) = to.area();
|
let XYWH(x, y, w0, h0) = to.area();
|
||||||
let (item, w, h) = match self {
|
let (item, w, h) = match self {
|
||||||
Self::W(item, w) => (item, (*w).into().unwrap_or(w0), h0),
|
Self::W(item, w) => (item, (*w).into().unwrap_or(w0), h0),
|
||||||
|
|
@ -369,8 +369,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Push<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Push<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
match self {
|
match self {
|
||||||
Self::__(_) => unreachable!(),
|
Self::__(_) => unreachable!(),
|
||||||
Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => {
|
Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => {
|
||||||
|
|
@ -387,8 +387,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Pull<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Pull<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
match self {
|
match self {
|
||||||
Self::__(_) => unreachable!(),
|
Self::__(_) => unreachable!(),
|
||||||
Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => {
|
Self::X(item, x1) if let Some(XYWH(x, y, w, h)) = to.size(None, item)? => {
|
||||||
|
|
@ -411,8 +411,8 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S> for Pad<'a, S, I, X> {
|
impl <'a, S: Screen, I: Draw<S>, X: Into<Option<S::Unit>> + Copy> Draw<S> for Pad<'a, S, I, X> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let XYWH(x, y, w0, h0) = to.area();
|
let XYWH(x, y, w0, h0) = to.area();
|
||||||
let (item, w, h) = match self {
|
let (item, w, h) = match self {
|
||||||
Self::X(item, w) => (item, (*w).into().unwrap_or_default(), Default::default()),
|
Self::X(item, w) => (item, (*w).into().unwrap_or_default(), Default::default()),
|
||||||
|
|
@ -430,20 +430,20 @@ impl <'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>> + Copy> Draw<'a, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutFull<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutFull<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutExact<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutExact<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutMin<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutMin<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutMax<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutMax<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutPush<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutPush<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutPull<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutPull<'a, S> for T {}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> LayoutPad<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> LayoutPad<'a, S> for T {}
|
||||||
|
|
||||||
pub fn check_layout <'a> (t: impl Draw<'a, Tui>) -> Drawn<'a, u16> {
|
pub fn check_layout <'a> (t: impl Draw<Tui>) -> Drawn<u16> {
|
||||||
Tui::Layout(XYWH(1u16, 1, 80, 25)).size(None, t)
|
Tui::Layout(XYWH(1u16, 1, 80, 25)).size(None, t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ pub struct Origin<T>(
|
||||||
pub(crate) T
|
pub(crate) T
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Origin<T> {
|
impl<'a, S: Screen, T: Draw<S>> Draw<S> for Origin<T> {
|
||||||
fn draw (&self, _to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, _to: &mut S) -> Drawn<S::Unit> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,11 +36,11 @@ impl<T: AsRef<Azimuth>> HasOrigin for T {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "draw", feature = "eval"))]
|
#[cfg(all(feature = "draw", feature = "eval"))]
|
||||||
pub fn kw_align <'a, O, S> (state: &'a S, to: &mut O, expr: &'a str)
|
pub fn kw_align <O, S> (state: &S, to: &mut O, expr: &str)
|
||||||
-> Drawn<'a, O::Unit>
|
-> Drawn<O::Unit>
|
||||||
where
|
where
|
||||||
O: Screen,
|
O: Screen,
|
||||||
S: Interpret<'a, O, Option<XYWH<O::Unit>>>
|
S: Interpret<O, Option<XYWH<O::Unit>>>
|
||||||
+ Namespace<bool>
|
+ Namespace<bool>
|
||||||
+ Namespace<O::Unit>
|
+ Namespace<O::Unit>
|
||||||
+ Namespace<Option<O::Unit>>
|
+ Namespace<Option<O::Unit>>
|
||||||
|
|
@ -58,7 +58,8 @@ where
|
||||||
Some("align/sw") => Align(Some(Azimuth::SW), thunk).draw(to)?,
|
Some("align/sw") => Align(Some(Azimuth::SW), thunk).draw(to)?,
|
||||||
Some("align/ne") => Align(Some(Azimuth::NE), thunk).draw(to)?,
|
Some("align/ne") => Align(Some(Azimuth::NE), thunk).draw(to)?,
|
||||||
Some("align/se") => Align(Some(Azimuth::SE), thunk).draw(to)?,
|
Some("align/se") => Align(Some(Azimuth::SE), thunk).draw(to)?,
|
||||||
frag => return Err(format!("invalid variant: {frag:?}").into())
|
Some(frag) => return Err(format!("align: invalid variant: {frag}").into()),
|
||||||
|
None => unreachable!()
|
||||||
})
|
})
|
||||||
//Ok(matches!(expr.head().src()?.unwrap_or_default().split("/").next(), Some("align")).then(||{
|
//Ok(matches!(expr.head().src()?.unwrap_or_default().split("/").next(), Some("align")).then(||{
|
||||||
//draw(move|output: &mut O|{state.interpret(output, &expr.nth(1))}).align(
|
//draw(move|output: &mut O|{state.interpret(output, &expr.nth(1))}).align(
|
||||||
|
|
@ -73,9 +74,9 @@ where
|
||||||
//}).transpose()?.flatten())
|
//}).transpose()?.flatten())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> CanAlign<'a, S> for T {}
|
impl<'a, S: Screen, T: Draw<S>> CanAlign<'a, S> for T {}
|
||||||
|
|
||||||
pub trait CanAlign<'a, S: Screen>: Draw<'a, S> + Sized {
|
pub trait CanAlign<'a, S: Screen>: Draw<S> + Sized {
|
||||||
fn align (self, azimuth: impl Into<Option<Azimuth>>) -> Align<Self> {
|
fn align (self, azimuth: impl Into<Option<Azimuth>>) -> Align<Self> {
|
||||||
Align(azimuth.into(), self)
|
Align(azimuth.into(), self)
|
||||||
}
|
}
|
||||||
|
|
@ -119,8 +120,8 @@ pub struct Align<T>(
|
||||||
pub(crate) T,
|
pub(crate) T,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<'a, S: Screen, T: Draw<'a, S>> Draw<'a, S> for Align<T> {
|
impl<'a, S: Screen, T: Draw<S>> Draw<S> for Align<T> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let Self(azimuth, item) = self;
|
let Self(azimuth, item) = self;
|
||||||
let area0 = to.area();
|
let area0 = to.area();
|
||||||
let size = to.size(area0, item)?;
|
let size = to.size(area0, item)?;
|
||||||
|
|
@ -166,7 +167,7 @@ fn_kw_layout!(kw_split |state, output, expr| {
|
||||||
Some("bsp/w") => Split::West.stack(thunk_a, thunk_b).draw(output)?,
|
Some("bsp/w") => Split::West.stack(thunk_a, thunk_b).draw(output)?,
|
||||||
Some("bsp/a") => Split::Above.stack(thunk_a, thunk_b).draw(output)?,
|
Some("bsp/a") => Split::Above.stack(thunk_a, thunk_b).draw(output)?,
|
||||||
Some("bsp/b") => Split::Below.stack(thunk_a, thunk_b).draw(output)?,
|
Some("bsp/b") => Split::Below.stack(thunk_a, thunk_b).draw(output)?,
|
||||||
frag => return Err(format!("invalid variant: {frag:?}").into())
|
frag => return Err(format!("split: invalid variant: {frag:?}").into())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -187,7 +188,7 @@ pub struct Pair<A, B>(Split, A, B);
|
||||||
/// # fn test_split_stack () -> Usually<()> {
|
/// # fn test_split_stack () -> Usually<()> {
|
||||||
/// use ::tengri::*;
|
/// use ::tengri::*;
|
||||||
/// use Split::*;
|
/// use Split::*;
|
||||||
/// fn size_of <'a, A: Draw<'a, Tui>, B: Draw<'a, Tui>> (stack: &Pair<Tui, A, B>) -> Drawn<'a, S::Unit> {
|
/// fn size_of <'a, A: Draw<Tui>, B: Draw<Tui>> (stack: &Pair<Tui, A, B>) -> Drawn<S::Unit> {
|
||||||
/// Tui::Layout(XYWH(0, 0, 80, 25)).size(None, stack)
|
/// Tui::Layout(XYWH(0, 0, 80, 25)).size(None, stack)
|
||||||
/// }
|
/// }
|
||||||
/// assert_eq!(size_of(&split(East, "foo", "bar"))?, Some(XYWH(0, 0, 6, 1)));
|
/// assert_eq!(size_of(&split(East, "foo", "bar"))?, Some(XYWH(0, 0, 6, 1)));
|
||||||
|
|
@ -196,14 +197,14 @@ pub struct Pair<A, B>(Split, A, B);
|
||||||
/// assert_eq!(size_of(&split(East, split(South, "foo", "bar"), "baz"))?, Some(XYWH(0, 0, 6, 2)));
|
/// assert_eq!(size_of(&split(East, split(South, "foo", "bar"), "baz"))?, Some(XYWH(0, 0, 6, 2)));
|
||||||
/// # return Ok(()); }
|
/// # return Ok(()); }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn split <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (
|
pub fn split <'a, S: Screen, A: Draw<S>, B: Draw<S>> (
|
||||||
split: Split, a: A, b: B
|
split: Split, a: A, b: B
|
||||||
) -> Pair<A, B> {
|
) -> Pair<A, B> {
|
||||||
Pair(split, a, b)
|
Pair(split, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> Draw<'a, S> for Pair<A, B> {
|
impl<'a, S: Screen, A: Draw<S>, B: Draw<S>> Draw<S> for Pair<A, B> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
let Self(split, a, b, ..) = self;
|
let Self(split, a, b, ..) = self;
|
||||||
let (area_a, area_b) = stack_areas(split, to, a, b)?;
|
let (area_a, area_b) = stack_areas(split, to, a, b)?;
|
||||||
let (drawn_a, drawn_b) = draw_stacks(split, to, a, area_a, None, b, area_b, None)?;
|
let (drawn_a, drawn_b) = draw_stacks(split, to, a, area_a, None, b, area_b, None)?;
|
||||||
|
|
@ -214,10 +215,10 @@ impl<'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> Draw<'a, S> for Pair<A, B> {
|
||||||
fn draw_stacks <'a, S: Screen> (
|
fn draw_stacks <'a, S: Screen> (
|
||||||
split: &Split,
|
split: &Split,
|
||||||
to: &mut S,
|
to: &mut S,
|
||||||
a: impl Draw<'a, S>,
|
a: impl Draw<S>,
|
||||||
area_a: impl Into<Option<XYWH<S::Unit>>>,
|
area_a: impl Into<Option<XYWH<S::Unit>>>,
|
||||||
origin_a: impl Into<Option<Azimuth>>,
|
origin_a: impl Into<Option<Azimuth>>,
|
||||||
b: impl Draw<'a, S>,
|
b: impl Draw<S>,
|
||||||
area_b: impl Into<Option<XYWH<S::Unit>>>,
|
area_b: impl Into<Option<XYWH<S::Unit>>>,
|
||||||
origin_b: impl Into<Option<Azimuth>>,
|
origin_b: impl Into<Option<Azimuth>>,
|
||||||
) -> UsuallyRef<'a, (Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
) -> UsuallyRef<'a, (Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
||||||
|
|
@ -254,8 +255,8 @@ fn draw_stacks <'a, S: Screen> (
|
||||||
pub fn stack_areas <'a, S: Screen> (
|
pub fn stack_areas <'a, S: Screen> (
|
||||||
split: &Split,
|
split: &Split,
|
||||||
to: &mut S,
|
to: &mut S,
|
||||||
a: impl Draw<'a, S>,
|
a: impl Draw<S>,
|
||||||
b: impl Draw<'a, S>,
|
b: impl Draw<S>,
|
||||||
) -> UsuallyRef<'a, (Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
) -> UsuallyRef<'a, (Option<XYWH<S::Unit>>, Option<XYWH<S::Unit>>)> {
|
||||||
let area_a = to.size(None, a)?;
|
let area_a = to.size(None, a)?;
|
||||||
Ok(match split {
|
Ok(match split {
|
||||||
|
|
@ -331,8 +332,8 @@ impl Split {
|
||||||
/// let _ = Split::East.stack(&"", &"");
|
/// let _ = Split::East.stack(&"", &"");
|
||||||
/// let _ = Split::West.stack(&"", &"");
|
/// let _ = Split::West.stack(&"", &"");
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn stack <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (&self, a: A, b: B)
|
pub const fn stack <'a, S: Screen, A: Draw<S>, B: Draw<S>> (&self, a: A, b: B)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
Pair(*self, a, b)
|
Pair(*self, a, b)
|
||||||
}
|
}
|
||||||
|
|
@ -346,8 +347,8 @@ impl Split {
|
||||||
/// let _ = Split::East.half(&"", &"");
|
/// let _ = Split::East.half(&"", &"");
|
||||||
/// let _ = Split::West.half(&"", &"");
|
/// let _ = Split::West.half(&"", &"");
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn half <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (&self, a: &A, b: &B)
|
pub const fn half <'a, S: Screen, A: Draw<S>, B: Draw<S>> (&self, a: &A, b: &B)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
draw(move|to: &mut S|{
|
draw(move|to: &mut S|{
|
||||||
let (area_a, area_b) = to.xywh().split_half(self);
|
let (area_a, area_b) = to.xywh().split_half(self);
|
||||||
|
|
@ -402,27 +403,27 @@ impl Split {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn east <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn east <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::East, a, b)
|
Pair(Split::East, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn north <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn north <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::North, a, b)
|
Pair(Split::North, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn west <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn west <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::West, a, b)
|
Pair(Split::West, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn south <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn south <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::South, a, b)
|
Pair(Split::South, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn above <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn above <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::Above, a, b)
|
Pair(Split::Above, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn below <'a, S: Screen, A: Draw<'a, S>, B: Draw<'a, S>> (a: A, b: B) -> impl Draw<'a, S> {
|
pub const fn below <'a, S: Screen, A: Draw<S>, B: Draw<S>> (a: A, b: B) -> impl Draw<S> {
|
||||||
Pair(Split::Below, a, b)
|
Pair(Split::Below, a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ fn_kw_layout!(kw_when |state, output, expr| {
|
||||||
/// Only render when condition is true.
|
/// Only render when condition is true.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> {
|
/// # use ::tengri::*; fn test <'a> () -> impl Draw<Tui> {
|
||||||
/// when(true, "Yes")
|
/// when(true, "Yes")
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn when <'a, T: Screen> (condition: bool, item: impl Draw<'a, T>) -> impl Draw<'a, T> {
|
pub const fn when <'a, T: Screen> (condition: bool, item: impl Draw<T>) -> impl Draw<T> {
|
||||||
draw(move|to: &mut T|if condition { item.draw(to) } else { Ok(Default::default()) })
|
draw(move|to: &mut T|if condition { item.draw(to) } else { Ok(Default::default()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,12 +29,12 @@ fn_kw_layout!(kw_either |state, output, expr| {
|
||||||
/// Render one thing if a condition is true and another false.
|
/// Render one thing if a condition is true and another false.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use ::tengri::*; fn test <'a> () -> impl Draw<'a, Tui> {
|
/// # use ::tengri::*; fn test <'a> () -> impl Draw<Tui> {
|
||||||
/// either(true, "Yes", "No")
|
/// either(true, "Yes", "No")
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub const fn either <'a, T: Screen> (
|
pub const fn either <'a, T: Screen> (
|
||||||
condition: bool, a: impl Draw<'a, T>, b: impl Draw<'a, T>
|
condition: bool, a: impl Draw<T>, b: impl Draw<T>
|
||||||
) -> impl Draw<'a, T> {
|
) -> impl Draw<T> {
|
||||||
draw(move|to: &mut T|if condition { a.draw(to) } else { b.draw(to) })
|
draw(move|to: &mut T|if condition { a.draw(to) } else { b.draw(to) })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn iter_south <'a, S: Screen, D: Draw<'a, S>, I: Iterator<Item = D>> (
|
pub fn iter_south <'a, S: Screen, D: Draw<S>, I: Iterator<Item = D>> (
|
||||||
iter: impl Fn()->I
|
iter: impl Fn()->I
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|to: &mut S|{
|
draw(move|to: &mut S|{
|
||||||
let XYWH(x, y, w, h) = to.area();
|
let XYWH(x, y, w, h) = to.area();
|
||||||
let mut y_next = y;
|
let mut y_next = y;
|
||||||
|
|
@ -22,9 +22,9 @@ pub fn iter_south <'a, S: Screen, D: Draw<'a, S>, I: Iterator<Item = D>> (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_east <'a, S: Screen, D: Draw<'a, S>, I: Iterator<Item = D>> (
|
pub fn iter_east <'a, S: Screen, D: Draw<S>, I: Iterator<Item = D>> (
|
||||||
iter: impl Fn()->I
|
iter: impl Fn()->I
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|to: &mut S|{
|
draw(move|to: &mut S|{
|
||||||
let XYWH(x, y, w, h) = to.area();
|
let XYWH(x, y, w, h) = to.area();
|
||||||
let mut x_next = x;
|
let mut x_next = x;
|
||||||
|
|
@ -45,16 +45,16 @@ pub fn iter_east <'a, S: Screen, D: Draw<'a, S>, I: Iterator<Item = D>> (
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over a collection of the same kind of [Draw]able:
|
/// Iterate over a collection of the same kind of [Draw]able:
|
||||||
pub fn iter <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<'a, S>> (
|
pub fn iter <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over a collection of the same kind of [Draw]able:
|
/// Iterate over a collection of the same kind of [Draw]able:
|
||||||
pub fn iter_once <'a, S: Screen, D: 'a, U: Draw<'a, S>> (
|
pub fn iter_once <'a, S: Screen, D: 'a, U: Draw<S>> (
|
||||||
_iter: impl Iterator<Item = D>, _draw: impl Fn(D, usize)->U,
|
_iter: impl Iterator<Item = D>, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,55 +65,55 @@ pub fn iter_dyn <
|
||||||
D, // Input doesn't need to be [Draw]able, output does
|
D, // Input doesn't need to be [Draw]able, output does
|
||||||
V: Fn()->I, // Function that returns the iterator
|
V: Fn()->I, // Function that returns the iterator
|
||||||
I: Iterator<Item = D>, // Type of the iterator
|
I: Iterator<Item = D>, // Type of the iterator
|
||||||
F: Fn(&D, usize)->dyn Draw<'a, S>, // Function that returns [Draw]able from iterator item
|
F: Fn(&D, usize)->dyn Draw<S>, // Function that returns [Draw]able from iterator item
|
||||||
> (_items: V, _cb: F) -> impl Draw<'a, S> {
|
> (_items: V, _cb: F) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<'a, S>> (
|
pub fn iter_north <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<'a, S>> (
|
pub fn iter_east_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<'a, S>> (
|
pub fn iter_south_fixed <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
_height: S::Unit, _iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<'a, S>> (
|
pub fn iter_west <'a, S: Screen, D: 'a, I: Iterator<Item = D>, U: Draw<S>> (
|
||||||
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
_iter: impl Fn()->I, _draw: impl Fn(D, usize)->U,
|
||||||
) -> impl Draw<'a, S> {
|
) -> impl Draw<S> {
|
||||||
draw(move|_to: &mut S|{ todo!() })
|
draw(move|_to: &mut S|{ todo!() })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn row_south <'a, S: Screen + 'a> (south: S::Unit, height: S::Unit, content: impl Draw<'a, S>)
|
pub fn row_south <'a, S: Screen + 'a> (south: S::Unit, height: S::Unit, content: impl Draw<S>)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
content.exact_h(height).push_y(south)
|
content.exact_h(height).push_y(south)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn row_north <'a, S: Screen + 'a> (north: S::Unit, height: S::Unit, content: impl Draw<'a, S>)
|
pub fn row_north <'a, S: Screen + 'a> (north: S::Unit, height: S::Unit, content: impl Draw<S>)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
content.exact_h(height).pull_y(north)
|
content.exact_h(height).pull_y(north)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn col_east <'a, S: Screen + 'a> (east: S::Unit, width: S::Unit, content: impl Draw<'a, S>)
|
pub fn col_east <'a, S: Screen + 'a> (east: S::Unit, width: S::Unit, content: impl Draw<S>)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
content.exact_w(width).push_x(east)
|
content.exact_w(width).push_x(east)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn col_west <'a, S: Screen + 'a> (west: S::Unit, width: S::Unit, content: impl Draw<'a, S>)
|
pub fn col_west <'a, S: Screen + 'a> (west: S::Unit, width: S::Unit, content: impl Draw<S>)
|
||||||
-> impl Draw<'a, S>
|
-> impl Draw<S>
|
||||||
{
|
{
|
||||||
content.exact_w(width).pull_x(west)
|
content.exact_w(width).pull_x(west)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
88
src/lib.rs
88
src/lib.rs
|
|
@ -1268,14 +1268,14 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
fn size <'a> (
|
fn size <'a> (
|
||||||
&mut self,
|
&mut self,
|
||||||
area: impl Into<Option<XYWH<Self::Unit>>>,
|
area: impl Into<Option<XYWH<Self::Unit>>>,
|
||||||
draw: impl Draw<'a, Self>
|
draw: impl Draw<Self>
|
||||||
) -> Drawn<'a, Self::Unit>;
|
) -> Drawn<Self::Unit>;
|
||||||
/// Draw
|
/// Draw
|
||||||
fn draw <'a> (
|
fn draw <'a> (
|
||||||
&mut self,
|
&mut self,
|
||||||
area: impl Into<Option<XYWH<Self::Unit>>>,
|
area: impl Into<Option<XYWH<Self::Unit>>>,
|
||||||
draw: impl Draw<'a, Self>
|
draw: impl Draw<Self>
|
||||||
) -> Drawn<'a, Self::Unit>;
|
) -> Drawn<Self::Unit>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement the [Draw] trait for a particular drawable and [Screen].
|
/// Implement the [Draw] trait for a particular drawable and [Screen].
|
||||||
|
|
@ -1290,7 +1290,7 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
#[macro_export] macro_rules! impl_draw (
|
#[macro_export] macro_rules! impl_draw (
|
||||||
($(<$($T:ident: $Trait:path,)+>)?|
|
($(<$($T:ident: $Trait:path,)+>)?|
|
||||||
$self:ident:$Self:path, $to:ident:$To:ty
|
$self:ident:$Self:path, $to:ident:$To:ty
|
||||||
|$draw:block)=>{ impl$(<$($T:$Trait),+>)? Draw<'_, $To> for $Self {
|
|$draw:block)=>{ impl$(<$($T:$Trait),+>)? Draw<$To> for $Self {
|
||||||
fn draw (&$self, $to: &mut $To) -> Perhaps<XYWH<<$To as Screen>::Unit>> $draw
|
fn draw (&$self, $to: &mut $To) -> Perhaps<XYWH<<$To as Screen>::Unit>> $draw
|
||||||
} };
|
} };
|
||||||
($(<$($T:ident: $Trait:path,)+>)?|
|
($(<$($T:ident: $Trait:path,)+>)?|
|
||||||
|
|
@ -1321,48 +1321,48 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Draw<'a, S: Screen> {
|
pub trait Draw<S: Screen> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit>;
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit a [Draw]able.
|
///// Emit a [Draw]able.
|
||||||
///
|
/////
|
||||||
/// Speculative. How to avoid conflicts with [Draw] proper?
|
///// Speculative. How to avoid conflicts with [Draw] proper?
|
||||||
pub trait View<T: Screen> {
|
//pub trait View<T: Screen> {
|
||||||
fn view (&self) -> impl Draw<T>;
|
//fn view (&self) -> impl Draw<T> ;
|
||||||
}
|
//}
|
||||||
|
|
||||||
impl<T: Screen> View<T> for () {
|
//impl<T: Screen> View<T> for () {
|
||||||
fn view (&self) -> impl Draw<T> {
|
//fn view (&self) -> impl Draw<T> {
|
||||||
()
|
//()
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// Return a [Draw]able.
|
///// Return a [Draw]able.
|
||||||
///
|
/////
|
||||||
/// ```
|
///// ```
|
||||||
/// # use tengri::*;
|
///// # use tengri::*;
|
||||||
/// let _ = view::<Tui, _, _>(||"drawable");
|
///// let _ = view::<Tui, _, _>(||"drawable");
|
||||||
/// let _ = view::<Tui, _, _>(||Some("drawable"));
|
///// let _ = view::<Tui, _, _>(||Some("drawable"));
|
||||||
/// ```
|
///// ```
|
||||||
pub const fn view <S: Screen, T: for<'a> Draw<'a, S>, F: Fn()->T> (view: F) -> impl View<S> {
|
//pub const fn view <S: Screen, T: for<'a> Draw<S>, F: Fn()->T> (view: F) -> impl View<S> {
|
||||||
ViewThunk(view, PhantomData)
|
//ViewThunk(view, PhantomData)
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// Because we can't implement [Draw] for `F: FnOnce...` without conflicts.
|
///// Because we can't implement [Draw] for `F: FnOnce...` without conflicts.
|
||||||
pub struct ViewThunk<S: Screen, F>(pub F, std::marker::PhantomData<S>);
|
//pub struct ViewThunk<S: Screen, F>(pub F, std::marker::PhantomData<S>);
|
||||||
|
|
||||||
impl<S: Screen, T: for<'a> Draw<'a, S>, F: Fn()->T> View<S> for ViewThunk<S, F> {
|
//impl<S: Screen, T: for<'a> Draw<S>, F: Fn()->T> View<S> for ViewThunk<S, F> {
|
||||||
fn view (&self) -> impl Draw<S> {
|
//fn view (&self) -> impl Draw<S> {
|
||||||
self.0()
|
//self.0()
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
|
|
||||||
/// Because we can't implement [Draw] for `F: FnOnce...` without conflicts.
|
/// Because we can't implement [Draw] for `F: FnOnce...` without conflicts.
|
||||||
pub struct DrawThunk<S: Screen, F>(pub F, std::marker::PhantomData<S>);
|
pub struct DrawThunk<S: Screen, F>(pub F, std::marker::PhantomData<S>);
|
||||||
|
|
||||||
impl<'a, T: Screen, F: Fn(&mut T)->PerhapsRef<'a, XYWH<T::Unit>>> Draw<'a, T> for DrawThunk<T, F> {
|
impl<T: Screen, F: Fn(&mut T)->Drawn<T::Unit>> Draw<T> for DrawThunk<T, F> {
|
||||||
fn draw (&self, to: &mut T) -> PerhapsRef<'a, XYWH<T::Unit>> {
|
fn draw (&self, to: &mut T) -> Drawn<T::Unit> {
|
||||||
to.clip(None, &self.0)
|
to.clip(None, &self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1379,16 +1379,16 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
DrawThunk(item, std::marker::PhantomData)
|
DrawThunk(item, std::marker::PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Drawn<'a, U> = PerhapsRef<'a, XYWH<U>>;
|
pub type Drawn<U> = Perhaps<XYWH<U>>;
|
||||||
|
|
||||||
impl<'a, S: Screen> Draw<'a, S> for () {
|
impl<'a, S: Screen> Draw<S> for () {
|
||||||
fn draw (&self, _: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, _: &mut S) -> Drawn<S::Unit> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: Screen, D: Draw<'a, S>> Draw<'a, S> for Option<D> {
|
impl<'a, S: Screen, D: Draw<S>> Draw<S> for Option<D> {
|
||||||
fn draw (&self, to: &mut S) -> Drawn<'a, S::Unit> {
|
fn draw (&self, to: &mut S) -> Drawn<S::Unit> {
|
||||||
self.as_ref().map(|it|it.draw(to)).transpose().map(Option::unwrap_or_default)
|
self.as_ref().map(|it|it.draw(to)).transpose().map(Option::unwrap_or_default)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1405,8 +1405,8 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
impl<'a, T: Screen, V: Draw<'a, T>> Draw<'a, T> for &V {
|
impl<'a, T: Screen, V: Draw<T>> Draw<T> for &V {
|
||||||
fn draw (&self, to: &mut T) -> Drawn<'a, T::Unit> {
|
fn draw (&self, to: &mut T) -> Drawn<T::Unit> {
|
||||||
(*self).draw(to)
|
(*self).draw(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
src/term.rs
37
src/term.rs
|
|
@ -97,13 +97,13 @@ impl Screen for Tui {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
fn size <'a> (
|
fn size <'a> (
|
||||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Self>,
|
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Self>,
|
||||||
) -> Drawn<'a, Self::Unit> {
|
) -> Drawn<Self::Unit> {
|
||||||
Self::Layout(self.area()).clip(area, &|to|draw.draw(to))
|
Self::Layout(self.area()).clip(area, &|to|draw.draw(to))
|
||||||
}
|
}
|
||||||
fn draw <'a> (
|
fn draw <'a> (
|
||||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Tui>
|
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Tui>
|
||||||
) -> Drawn<'a, Self::Unit> {
|
) -> Drawn<Self::Unit> {
|
||||||
self.clip(area, &|to|draw.draw(to))
|
self.clip(area, &|to|draw.draw(to))
|
||||||
}
|
}
|
||||||
fn clip <T> (
|
fn clip <T> (
|
||||||
|
|
@ -132,7 +132,7 @@ impl Tui {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
pub fn run_main <T> (exit: Exit, state: Arc<RwLock<T>>) -> Usually<()> where
|
pub fn run_main <T> (exit: Exit, state: Arc<RwLock<T>>) -> Usually<()> where
|
||||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
T: Draw<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
||||||
{
|
{
|
||||||
let scan = Duration::from_millis(100);
|
let scan = Duration::from_millis(100);
|
||||||
let frame = Duration::from_millis(10);
|
let frame = Duration::from_millis(10);
|
||||||
|
|
@ -142,7 +142,7 @@ impl Tui {
|
||||||
}
|
}
|
||||||
/// Spawn the TUI input and output threadsl.
|
/// Spawn the TUI input and output threadsl.
|
||||||
pub fn io <
|
pub fn io <
|
||||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static,
|
T: Draw<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static,
|
||||||
W: Write + Send + Sync + 'static,
|
W: Write + Send + Sync + 'static,
|
||||||
> (
|
> (
|
||||||
exited: &Arc<AtomicBool>,
|
exited: &Arc<AtomicBool>,
|
||||||
|
|
@ -252,7 +252,8 @@ impl Tui {
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
pub fn output <
|
pub fn output <
|
||||||
W: Write + Send + Sync + 'static, T: View<Tui> + Send + Sync + 'static
|
W: Write + Send + Sync + 'static,
|
||||||
|
T: Draw<Tui> + Send + Sync + 'static
|
||||||
> (
|
> (
|
||||||
exited: &Arc<AtomicBool>,
|
exited: &Arc<AtomicBool>,
|
||||||
state: &Arc<RwLock<T>>,
|
state: &Arc<RwLock<T>>,
|
||||||
|
|
@ -271,7 +272,7 @@ impl Tui {
|
||||||
let Size { width, height } = backend.size().expect("get size failed");
|
let Size { width, height } = backend.size().expect("get size failed");
|
||||||
if let Ok(state) = state.try_read() {
|
if let Ok(state) = state.try_read() {
|
||||||
prev.resize(&mut backend, width, height);
|
prev.resize(&mut backend, width, height);
|
||||||
state.view().draw(&mut next).expect("draw failed"); // TODO draw error
|
state.draw(&mut next).expect("draw failed"); // TODO draw error
|
||||||
prev.redraw(&mut backend, &mut next);
|
prev.redraw(&mut backend, &mut next);
|
||||||
}
|
}
|
||||||
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
|
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
|
||||||
|
|
@ -289,7 +290,7 @@ impl Tui {
|
||||||
/// let _ = tengri::Tui::catcher(&variant);
|
/// let _ = tengri::Tui::catcher(&variant);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn catcher <'a, T: Draw<'a, Tui>> (result: &Usually<T>) -> impl Draw<'a, Tui> {
|
pub fn catcher <'a, T: Draw<Tui>> (result: &Usually<T>) -> impl Draw<Tui> {
|
||||||
draw(move|to: &mut Tui|match result {
|
draw(move|to: &mut Tui|match result {
|
||||||
Ok(content) => content.draw(to),
|
Ok(content) => content.draw(to),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -369,7 +370,7 @@ impl<'a: 'b, 'b> From<&'a mut Tui> for &'b mut XYWH<u16> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> {
|
pub const fn fill_char <'a> (c: char) -> impl Draw<Tui> {
|
||||||
draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{
|
draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{
|
||||||
cell.set_char(c);
|
cell.set_char(c);
|
||||||
}))))
|
}))))
|
||||||
|
|
@ -378,8 +379,8 @@ pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> {
|
||||||
/// FIXME: Don't use `format!` but implement number blitting
|
/// FIXME: Don't use `format!` but implement number blitting
|
||||||
pub struct ShowSize;
|
pub struct ShowSize;
|
||||||
|
|
||||||
impl<'a> Draw<'a, Tui> for ShowSize {
|
impl<'a> Draw<Tui> for ShowSize {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let info = format!("{area:?}");
|
let info = format!("{area:?}");
|
||||||
to.text(&info, area.0, area.1, info.len() as u16)
|
to.text(&info, area.0, area.1, info.len() as u16)
|
||||||
|
|
@ -388,8 +389,8 @@ impl<'a> Draw<'a, Tui> for ShowSize {
|
||||||
|
|
||||||
pub struct ShowSizeOf<T>(pub T);
|
pub struct ShowSizeOf<T>(pub T);
|
||||||
|
|
||||||
impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
impl<'a, T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
Ok(self.0.draw(to)?.map(|used|{
|
Ok(self.0.draw(to)?.map(|used|{
|
||||||
let _ = to.text(&format!("{used:?}"), used.0, used.1, u16::MAX);
|
let _ = to.text(&format!("{used:?}"), used.0, used.1, u16::MAX);
|
||||||
used
|
used
|
||||||
|
|
@ -474,8 +475,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
||||||
self.as_ref().draw(to)
|
self.as_ref().draw(to)
|
||||||
});
|
});
|
||||||
|
|
||||||
impl<'a> Draw<'a, Tui> for &str {
|
impl<'a> Draw<Tui> for &str {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
let XYWH(x, y, w, h) = to.area();
|
let XYWH(x, y, w, h) = to.area();
|
||||||
let mut max_w = 0u16;
|
let mut max_w = 0u16;
|
||||||
let mut max_h = 0u16;
|
let mut max_h = 0u16;
|
||||||
|
|
@ -494,8 +495,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: AsRef<str>> Draw<'a, Tui> for TrimStr<'a, T> {
|
impl<'a, T: AsRef<str>> Draw<Tui> for TrimStr<'a, T> {
|
||||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||||
let text = self.1.as_ref();
|
let text = self.1.as_ref();
|
||||||
let area = layout_text_u16(text, to.area())?.unwrap();
|
let area = layout_text_u16(text, to.area())?.unwrap();
|
||||||
let XYWH(x, y, w, ..) = to.area();
|
let XYWH(x, y, w, ..) = to.area();
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use crate::*;
|
||||||
/// /// TODO
|
/// /// TODO
|
||||||
/// ```
|
/// ```
|
||||||
pub fn border <'a> (
|
pub fn border <'a> (
|
||||||
on: bool, style: impl BorderStyle<'a>, item: impl Draw<'a, Tui>
|
on: bool, style: impl BorderStyle<'a>, item: impl Draw<Tui>
|
||||||
) -> impl Draw<'a, Tui> {
|
) -> impl Draw<Tui> {
|
||||||
let content = item.pad_wh(1, 1);
|
let content = item.pad_wh(1, 1);
|
||||||
let outline = when(on, draw(move|to: &mut Tui|{
|
let outline = when(on, draw(move|to: &mut Tui|{
|
||||||
let XYWH(x, y, w, h) = to.area();
|
let XYWH(x, y, w, h) = to.area();
|
||||||
|
|
@ -49,7 +49,7 @@ macro_rules! border {
|
||||||
}
|
}
|
||||||
#[derive(Copy, Clone)] pub struct $T(pub bool, pub Style);
|
#[derive(Copy, Clone)] pub struct $T(pub bool, pub Style);
|
||||||
//impl Layout<Tui> for $T {}
|
//impl Layout<Tui> for $T {}
|
||||||
impl<'a> Draw<'a, Tui> for $T {
|
impl<'a> Draw<Tui> for $T {
|
||||||
fn draw (&self, to: &mut Tui) -> Perhaps<XYWH<u16>> {
|
fn draw (&self, to: &mut Tui) -> Perhaps<XYWH<u16>> {
|
||||||
when(self.enabled(), draw(|to: &mut Tui|BorderStyle::draw(*self, to).map(Some))).draw(to)
|
when(self.enabled(), draw(|to: &mut Tui|BorderStyle::draw(*self, to).map(Some))).draw(to)
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ border! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BorderStyle<'a>: Draw<'a, Tui> + Copy {
|
pub trait BorderStyle<'a>: Draw<Tui> + Copy {
|
||||||
fn enabled (&self) -> bool;
|
fn enabled (&self) -> bool;
|
||||||
fn border_n (&self) -> &str { Self::N }
|
fn border_n (&self) -> &str { Self::N }
|
||||||
fn border_s (&self) -> &str { Self::S }
|
fn border_s (&self) -> &str { Self::S }
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ impl Tui {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply foreground color.
|
/// Apply foreground color.
|
||||||
pub const fn fg <'a> (fg: Color, item: impl Draw<'a, Tui>)
|
pub const fn fg <'a> (fg: Color, item: impl Draw<Tui>)
|
||||||
-> impl Draw<'a, Tui>
|
-> impl Draw<Tui>
|
||||||
{
|
{
|
||||||
draw(move|to: &mut Tui|{
|
draw(move|to: &mut Tui|{
|
||||||
if let Some(size) = to.size(None, &item)? {
|
if let Some(size) = to.size(None, &item)? {
|
||||||
|
|
@ -72,8 +72,8 @@ pub const fn fg <'a> (fg: Color, item: impl Draw<'a, Tui>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply background color.
|
/// Apply background color.
|
||||||
pub const fn bg <'a> (bg: Color, item: impl Draw<'a, Tui>)
|
pub const fn bg <'a> (bg: Color, item: impl Draw<Tui>)
|
||||||
-> impl Draw<'a, Tui>
|
-> impl Draw<Tui>
|
||||||
{
|
{
|
||||||
draw(move|to: &mut Tui|{
|
draw(move|to: &mut Tui|{
|
||||||
if let Some(size) = to.size(None, &item)? {
|
if let Some(size) = to.size(None, &item)? {
|
||||||
|
|
@ -87,8 +87,8 @@ pub const fn bg <'a> (bg: Color, item: impl Draw<'a, Tui>)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw<'a, Tui>)
|
pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw<Tui>)
|
||||||
-> impl Draw<'a, Tui>
|
-> impl Draw<Tui>
|
||||||
{
|
{
|
||||||
draw(move|to: &mut Tui|{
|
draw(move|to: &mut Tui|{
|
||||||
if let Some(size) = to.size(None, &item)? {
|
if let Some(size) = to.size(None, &item)? {
|
||||||
|
|
@ -103,8 +103,8 @@ pub const fn fg_bg <'a> (fg: Color, bg: Color, item: impl Draw<'a, Tui>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw contents with modifier applied.
|
/// Draw contents with modifier applied.
|
||||||
pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw<'a, Tui>)
|
pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw<Tui>)
|
||||||
-> impl Draw<'a, Tui>
|
-> impl Draw<Tui>
|
||||||
{
|
{
|
||||||
draw(move|to: &mut Tui|{
|
draw(move|to: &mut Tui|{
|
||||||
fill_mod(on, modifier).draw(to)?;
|
fill_mod(on, modifier).draw(to)?;
|
||||||
|
|
@ -112,7 +112,7 @@ pub const fn modify <'a> (on: bool, modifier: Modifier, item: impl Draw<'a, Tui>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw<'a, Tui> {
|
pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw<Tui> {
|
||||||
draw(move|to: &mut Tui|Ok(Some({
|
draw(move|to: &mut Tui|Ok(Some({
|
||||||
if on {
|
if on {
|
||||||
to.update(&|cell,_,_|cell.modifier.insert(modifier))
|
to.update(&|cell,_,_|cell.modifier.insert(modifier))
|
||||||
|
|
@ -123,11 +123,11 @@ pub const fn fill_mod <'a> (on: bool, modifier: Modifier) -> impl Draw<'a, Tui>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw contents with bold modifier applied.
|
/// Draw contents with bold modifier applied.
|
||||||
pub const fn bold <'a> (on: bool, item: impl Draw<'a, Tui>) -> impl Draw<'a, Tui> {
|
pub const fn bold <'a> (on: bool, item: impl Draw<Tui>) -> impl Draw<Tui> {
|
||||||
modify(on, Modifier::BOLD, item)
|
modify(on, Modifier::BOLD, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn fill_ul <'a> (color: Option<Color>) -> impl Draw<'a, Tui> {
|
pub const fn fill_ul <'a> (color: Option<Color>) -> impl Draw<Tui> {
|
||||||
draw(move|to: &mut Tui|Ok(Some(if let Some(color) = color {
|
draw(move|to: &mut Tui|Ok(Some(if let Some(color) = color {
|
||||||
to.update(&|cell,_,_|{
|
to.update(&|cell,_,_|{
|
||||||
cell.modifier.insert(Modifier::UNDERLINED);
|
cell.modifier.insert(Modifier::UNDERLINED);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use crate::*;
|
||||||
/// /// TODO
|
/// /// TODO
|
||||||
/// ```
|
/// ```
|
||||||
pub fn phat <'a> (
|
pub fn phat <'a> (
|
||||||
w: u16, h: u16, [fg, bg, hi, lo]: [Color;4], draw: impl Draw<'a, Tui>
|
w: u16, h: u16, [fg, bg, hi, lo]: [Color;4], draw: impl Draw<Tui>
|
||||||
) -> impl Draw<'a, Tui> {
|
) -> impl Draw<Tui> {
|
||||||
let top = phat_lo(bg, hi).exact_h(1);
|
let top = phat_lo(bg, hi).exact_h(1);
|
||||||
let low = phat_hi(bg, lo).exact_h(1);
|
let low = phat_hi(bg, lo).exact_h(1);
|
||||||
let draw = fg_bg(fg, bg, draw);
|
let draw = fg_bg(fg, bg, draw);
|
||||||
|
|
@ -19,11 +19,11 @@ pub const LO: &'static str = "▄";
|
||||||
pub const HI: &'static str = "▀";
|
pub const HI: &'static str = "▀";
|
||||||
|
|
||||||
/// A phat line
|
/// A phat line
|
||||||
fn phat_lo <'a> (fg: Color, bg: Color) -> impl Draw<'a, Tui> {
|
fn phat_lo <'a> (fg: Color, bg: Color) -> impl Draw<Tui> {
|
||||||
fg_bg(fg, bg, x_repeat(LO)).exact_h(1)
|
fg_bg(fg, bg, x_repeat(LO)).exact_h(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A phat line
|
/// A phat line
|
||||||
fn phat_hi <'a> (fg: Color, bg: Color) -> impl Draw<'a, Tui> {
|
fn phat_hi <'a> (fg: Color, bg: Color) -> impl Draw<Tui> {
|
||||||
fg_bg(fg, bg, x_repeat(HI)).exact_h(1)
|
fg_bg(fg, bg, x_repeat(HI)).exact_h(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ pub const ICON_INC_V: &[char] = &['▼'];
|
||||||
pub const ICON_DEC_H: &[char] = &[' ', '🞀', ' '];
|
pub const ICON_DEC_H: &[char] = &[' ', '🞀', ' '];
|
||||||
pub const ICON_INC_H: &[char] = &[' ', '🞂', ' '];
|
pub const ICON_INC_H: &[char] = &[' ', '🞂', ' '];
|
||||||
|
|
||||||
pub fn x_scroll <'a> () -> impl Draw<'a, Tui> {
|
pub fn x_scroll <'a> () -> impl Draw<Tui> {
|
||||||
draw(|to: &mut Tui|{
|
draw(|to: &mut Tui|{
|
||||||
let XYWH(x1, y1, w, _h) = to.area();
|
let XYWH(x1, y1, w, _h) = to.area();
|
||||||
let x2 = x1 + w;
|
let x2 = x1 + w;
|
||||||
|
|
@ -37,7 +37,7 @@ pub fn x_scroll <'a> () -> impl Draw<'a, Tui> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn y_scroll <'a> () -> impl Draw<'a, Tui> {
|
pub fn y_scroll <'a> () -> impl Draw<Tui> {
|
||||||
draw(|to: &mut Tui|{
|
draw(|to: &mut Tui|{
|
||||||
let XYWH(x1, y1, _w, h) = to.area();
|
let XYWH(x1, y1, _w, h) = to.area();
|
||||||
let y2 = y1 + h;
|
let y2 = y1 + h;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue