mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 22:17:07 +02:00
big flat
This commit is contained in:
parent
94c26f06cc
commit
fc01fd6ad3
40 changed files with 2075 additions and 1807 deletions
41
src/layout/full.rs
Normal file
41
src/layout/full.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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!(),
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue