mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
40 lines
1.5 KiB
Rust
40 lines
1.5 KiB
Rust
use crate::*;
|
|
|
|
/// 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), item)
|
|
},
|
|
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), item)
|
|
},
|
|
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), item)
|
|
},
|
|
_ => Ok(None)
|
|
}
|
|
});
|