mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 13:26:42 +02:00
This commit is contained in:
parent
41ef62146b
commit
4172fa2577
13 changed files with 250 additions and 248 deletions
|
|
@ -10,11 +10,11 @@ fn_kw_layout!(kw_when |state, output, expr| {
|
|||
/// 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")
|
||||
/// # }
|
||||
/// ```
|
||||
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()) })
|
||||
}
|
||||
|
||||
|
|
@ -29,12 +29,12 @@ fn_kw_layout!(kw_either |state, output, expr| {
|
|||
/// 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")
|
||||
/// # }
|
||||
/// ```
|
||||
pub const fn either <'a, T: Screen> (
|
||||
condition: bool, a: impl Draw<'a, T>, b: impl Draw<'a, T>
|
||||
) -> impl Draw<'a, T> {
|
||||
condition: bool, a: impl Draw<T>, b: impl Draw<T>
|
||||
) -> impl Draw<T> {
|
||||
draw(move|to: &mut T|if condition { a.draw(to) } else { b.draw(to) })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue