This commit is contained in:
facile pop culture reference 2026-07-31 06:47:30 +03:00
parent 94c26f06cc
commit fc01fd6ad3
40 changed files with 2075 additions and 1807 deletions

40
src/layout/min.rs Normal file
View file

@ -0,0 +1,40 @@
use crate::{*, draw::*};
/// Only draw content if area is above a certain size.
///
/// ```
/// # fn doctest_layout_min () -> Result<(), Box<dyn std::error::Error>> {
/// use tengri::{Layout, Draw, XYWH};
/// let area = XYWH(1u16, 1, 80, 25);
/// assert_eq!("1".min_w(5).layout(area)?, Some(XYWH(1u16, 1, 5, 1)));
/// assert_eq!("1".min_h(5).layout(area)?, Some(XYWH(1u16, 1, 1, 5)));
/// assert_eq!("1".min_wh(5, 5).layout(area)?, Some(XYWH(1u16, 1, 5, 5)));
/// assert_eq!("123456".min_w(5).layout(area)?, Some(XYWH(1u16, 1, 6, 1)));
/// # Ok(()) }
/// ```
pub enum Min<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>> {
__(PhantomData<T>),
W(I, X),
H(I, X),
WH(I, X, X),
}
impl_draw!(<T: Screen, I: Draw<T>, X: Into<Option<T::Unit>>,>|self: Min<T, I, X>, to: T|{
match self {
Self::__(_) => unreachable!(),
Self::W(item, w1) if let Some(XYWH(x, y, w, h)) = item.layout(to.area())? => {
let w = w1.into().map(|w1|w.max(w1)).unwrap_or(w);
to.clip(XYWH(x, y, w, h), |to|item.draw(to))
},
Self::H(item, h1) if let Some(XYWH(x, y, w, h)) = item.layout(to.area())? => {
let h = h1.into().map(|h1|h.max(h1)).unwrap_or(h);
to.clip(XYWH(x, y, w, h), |to|item.draw(to))
},
Self::WH(item, w1, h1) if let Some(XYWH(x, y, w, h)) = item.layout(to.area())? => {
let w = w1.into().map(|w1|w.max(w1)).unwrap_or(w);
let h = h1.into().map(|h1|h.max(h1)).unwrap_or(h);
to.clip(XYWH(x, y, w, h), |to|item.draw(to))
},
_ => Ok(None)
}
});