mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
use crate::{*, draw::*};
|
|
|
|
/// Use whole drawing area along one or both axes.
|
|
///
|
|
/// ```
|
|
/// # fn doctest_layout_full () -> Result<(), Box<dyn std::error::Error>> {
|
|
/// use tengri::{Layout, Draw, XYWH};
|
|
/// let area = XYWH(0u16, 0, 80, 25);
|
|
/// assert_eq!("1".layout(area)?, Some(XYWH(0u16, 0, 1, 1)));
|
|
/// assert_eq!("1".full_w().layout(area)?, Some(XYWH(0u16, 0, 80, 1)));
|
|
/// assert_eq!("1".full_h().layout(area)?, Some(XYWH(0u16, 0, 1, 25)));
|
|
/// assert_eq!("1".full_wh().layout(area)?, Some(XYWH(0u16, 0, 80, 25)));
|
|
/// # Ok(()) }
|
|
/// ```
|
|
pub enum Full<T: Screen, I: Draw<T>> {
|
|
__(PhantomData<T>),
|
|
W(I),
|
|
H(I),
|
|
WH(I),
|
|
}
|
|
impl_draw!(<T: Screen, I: Draw<T>,>|self: Full<T, I>, to: T|{
|
|
let XYWH(x0, y0, w0, h0) = to.area();
|
|
match self {
|
|
Self::W(item) => if let Some(XYWH(_, y, _, h)) = item.layout(to.area())? {
|
|
to.clip(XYWH(x0, y, w0, h), |to|item.draw(to))
|
|
} else {
|
|
Ok(None)
|
|
},
|
|
Self::H(item) => if let Some(XYWH(x, _, w, _)) = item.layout(to.area())? {
|
|
to.clip(XYWH(x, y0, w, h0), |to|item.draw(to))
|
|
} else {
|
|
Ok(None)
|
|
},
|
|
Self::WH(item) => if let Some(XYWH(..)) = item.layout(to.area())? {
|
|
to.clip(XYWH(x0, y0, w0, h0), |to|item.draw(to))
|
|
} else {
|
|
Ok(None)
|
|
},
|
|
_ => unreachable!(),
|
|
}
|
|
});
|