mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
103 lines
2.6 KiB
Rust
103 lines
2.6 KiB
Rust
use crate::*;
|
|
|
|
impl<S: Screen, T: Draw<S>> Layout<S> for T {}
|
|
|
|
pub trait Layout<S: Screen>: Draw<S> + Sized {
|
|
fn full_w (self) -> impl Draw<S> {
|
|
Full::W(self)
|
|
}
|
|
fn full_h (self) -> impl Draw<S> {
|
|
Full::H(self)
|
|
}
|
|
fn full_wh (self) -> impl Draw<S> {
|
|
Full::WH(self)
|
|
}
|
|
|
|
fn origin (self, azimuth: impl Into<Option<Azimuth>>) -> impl Draw<S> {
|
|
Origin(azimuth.into(), self)
|
|
}
|
|
fn origin_c (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::C), self)
|
|
}
|
|
fn origin_x (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::X), self)
|
|
}
|
|
fn origin_y (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::Y), self)
|
|
}
|
|
|
|
fn origin_n (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::N), self)
|
|
}
|
|
fn origin_s (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::S), self)
|
|
}
|
|
fn origin_e (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::E), self)
|
|
}
|
|
fn origin_w (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::W), self)
|
|
}
|
|
|
|
fn origin_ne (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::NE), self)
|
|
}
|
|
fn origin_se (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::SE), self)
|
|
}
|
|
fn origin_nw (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::NW), self)
|
|
}
|
|
fn origin_sw (self) -> impl Draw<S> {
|
|
Origin(Some(Azimuth::SW), self)
|
|
}
|
|
}
|
|
|
|
/// Uses [AtomicUsize] to measure size during\
|
|
/// rendering (which is normally read-only).
|
|
#[derive(Default, Debug, Clone)]
|
|
pub struct Sizer(
|
|
/// Width
|
|
pub Arc<AtomicUsize>,
|
|
/// Height
|
|
pub Arc<AtomicUsize>,
|
|
);
|
|
|
|
impl Xy<u16> for Sizer {
|
|
fn x (&self) -> u16 {
|
|
self.0.load(Relaxed) as u16
|
|
}
|
|
fn y (&self) -> u16 {
|
|
self.1.load(Relaxed) as u16
|
|
}
|
|
}
|
|
impl Wide<u16> for Sizer {
|
|
fn w (&self) -> u16 {
|
|
self.0.load(Relaxed) as u16
|
|
}
|
|
}
|
|
impl Tall<u16> for Sizer {
|
|
fn h (&self) -> u16 {
|
|
self.1.load(Relaxed) as u16
|
|
}
|
|
}
|
|
impl PartialEq for Sizer {
|
|
fn eq (&self, _: &Self) -> bool { todo!() }
|
|
}
|
|
|
|
impl Sizer {
|
|
pub const fn of <T: Screen> (&self, of: impl Draw<T>) -> impl Draw<T> {
|
|
draw(move|to: &mut T|{
|
|
let area = of.draw(to)?;
|
|
self.0.store(area.map(|a|a.w()).unwrap_or(T::Unit::zero()).into(), Relaxed);
|
|
self.1.store(area.map(|a|a.h()).unwrap_or(T::Unit::zero()).into(), Relaxed);
|
|
Ok(area)
|
|
})
|
|
}
|
|
}
|
|
|
|
mod area; pub use self::area::*;
|
|
mod axis; pub use self::axis::*;
|
|
mod azimuth; pub use self::azimuth::*;
|
|
mod cond; pub use self::cond::*;
|
|
mod iter; pub use self::iter::*;
|