smizzle
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
facile pop culture reference 2026-08-19 18:21:34 +03:00
parent a9f2fa2cdd
commit 291ab63224
11 changed files with 98 additions and 96 deletions

View file

@ -29,12 +29,12 @@ pub enum Pad<'a, S: Screen, I: Draw<'a, S>, X: Into<Option<S::Unit>>> {
}
/// ```
/// # fn test_layout_full () -> Usually<()> {
/// # use ::tengri::*; fn test_layout_full () -> Usually<()> {
/// assert_eq!(check_layout("1")?, Some(XYWH(1u16, 1, 1, 1)));
/// assert_eq!(check_layout("1".full_w())?, Some(XYWH(1u16, 1, 80, 1)));
/// assert_eq!(check_layout("1".full_h())?, Some(XYWH(1u16, 1, 1, 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 {
fn full_w (self) -> Full<'a, S, Self> { Full::W(self) }
@ -43,12 +43,12 @@ pub trait LayoutFull<'a, S: Screen>: Draw<'a, S> + Sized {
}
/// ```
/// # fn test_layout_exact () -> Usually<()> {
/// # use ::tengri::*; fn test_layout_exact () -> Usually<()> {
/// assert_eq!(check_layout("FOOBAR\nKILROY")?, Some(XYWH(1, 1, 6, 2)));
/// assert_eq!(check_layout("FOOBAR\nKILROY".exact_w(3))?, Some(XYWH(1, 1, 3, 2)));
/// assert_eq!(check_layout("FOOBAR\nKILROY".exact_h(1))?, Some(XYWH(1, 1, 6, 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 {
fn exact_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
@ -60,12 +60,12 @@ pub trait LayoutExact<'a, S: Screen>: Draw<'a, S> + Sized {
}
/// ```
/// # fn test_layout_min () -> Usually<()> {
/// # use ::tengri::*; fn test_layout_min () -> Usually<()> {
/// assert_eq!(check_layout("1".min_w(5))?, Some(XYWH(1u16, 1, 5, 1)));
/// assert_eq!(check_layout("1".min_h(5))?, Some(XYWH(1u16, 1, 1, 5)));
/// assert_eq!(check_layout("1".min_wh(5, 5))?, Some(XYWH(1u16, 1, 5, 5)));
/// 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 {
fn min_w <X: Into<Option<S::Unit>> + Copy> (self, w: X)
@ -95,7 +95,7 @@ pub trait LayoutPad<'a, S: Screen>: Draw<'a, S> + Sized {
}
/// ```
/// # fn test_layout_pull () -> Usually<()> {
/// # use ::tengri::*; fn test_layout_pull () -> Usually<()> {
/// assert_eq!(check_layout("1")?, Some(XYWH(1u16, 1, 1, 1)));
/// assert_eq!(check_layout("1".push_x(1))?, Some(XYWH(2u16, 1, 1, 1)));
/// assert_eq!(check_layout("1".push_y(1))?, Some(XYWH(1u16, 2, 1, 1)));
@ -112,7 +112,7 @@ pub trait LayoutPush<'a, S: Screen>: Draw<'a, S> + Sized {
}
/// ```
/// # fn test_layout_push () -> Usually<()> {
/// # use ::tengri::*; fn test_layout_push () -> Usually<()> {
/// assert_eq!(check_layout("1")?, Some(XYWH(1u16, 1, 1, 1)));
/// assert_eq!(check_layout("1".pull_x(1))?, Some(XYWH(0u16, 1, 1, 1)));
/// assert_eq!(check_layout("1".pull_y(1))?, Some(XYWH(1u16, 0, 1, 1)));
@ -160,14 +160,14 @@ where
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("exact/w") => thunk.exact_w(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("exact/h") => thunk.exact_h(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("exact/wh") => thunk.exact_wh(
state.namespace(expr.nth(1)?)?,
state.namespace(expr.nth(2)?)?,
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
@ -186,14 +186,14 @@ where
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("min/w") => thunk.min_w(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("min/h") => thunk.min_h(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("min/wh") => thunk.min_wh(
state.namespace(expr.nth(1)?)?,
state.namespace(expr.nth(2)?)?,
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
@ -212,14 +212,14 @@ where
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("max/w") => thunk.max_w(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("max/h") => thunk.max_h(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("max/wh") => thunk.max_wh(
state.namespace(expr.nth(1)?)?,
state.namespace(expr.nth(2)?)?,
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
@ -237,9 +237,12 @@ where
{
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("push/w") => thunk.push_x(state.namespace(expr.nth(1)?)?).draw(to)?,
Some("push/h") => thunk.push_y(state.namespace(expr.nth(1)?)?).draw(to)?,
Some("push/wh") => thunk.push_xy(state.namespace(expr.nth(1)?)?, state.namespace(expr.nth(2)?)?,).draw(to)?,
Some("push/w") => thunk.push_x(state.namespace(&expr.nth(1)?)?).draw(to)?,
Some("push/h") => thunk.push_y(state.namespace(&expr.nth(1)?)?).draw(to)?,
Some("push/wh") => thunk.push_xy(
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
}
@ -256,9 +259,12 @@ where
{
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("pull/w") => thunk.pull_x(state.namespace(expr.nth(1)?)?).draw(to)?,
Some("pull/h") => thunk.pull_y(state.namespace(expr.nth(1)?)?).draw(to)?,
Some("pull/wh") => thunk.pull_xy(state.namespace(expr.nth(1)?)?, state.namespace(expr.nth(2)?)?,).draw(to)?,
Some("pull/w") => thunk.pull_x(state.namespace(&expr.nth(1)?)?).draw(to)?,
Some("pull/h") => thunk.pull_y(state.namespace(&expr.nth(1)?)?).draw(to)?,
Some("pull/wh") => thunk.pull_xy(
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
}
@ -276,14 +282,14 @@ where
let thunk = draw(move|screen|ok_flat(expr.last()?.map(|x: &'a str|state.interpret(screen, x))));
Ok(match expr.head()? {
Some("pad/w") => thunk.pad_w(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("pad/h") => thunk.pad_h(
state.namespace(expr.nth(1)?)?
state.namespace(&expr.nth(1)?)?
).draw(to)?,
Some("pad/wh") => thunk.pad_wh(
state.namespace(expr.nth(1)?)?,
state.namespace(expr.nth(2)?)?,
state.namespace(&expr.nth(1)?)?,
state.namespace(&expr.nth(2)?)?,
).draw(to)?,
_ => return Err(format!("invalid variant: {:?}", expr.head()?).into())
})
@ -438,6 +444,6 @@ impl<'a, S: Screen, T: Draw<'a, S>> LayoutPull<'a, S> for T {}
impl<'a, S: Screen, T: Draw<'a, S>> LayoutPad<'a, S> for T {}
#[cfg(test)] fn check_layout <'a> (t: impl Draw<'a, Tui>) -> Drawn<'a, u16> {
pub fn check_layout <'a> (t: impl Draw<'a, Tui>) -> Drawn<'a, u16> {
Tui::Layout(XYWH(1u16, 1, 80, 25)).size(None, t)
}