mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use crate::*;
|
|
|
|
pub enum Fixed<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
|
|
|
|
impl<U, A> Fixed<U, A> {
|
|
#[inline] pub const fn x (x: U, item: A) -> Self {
|
|
Self::X(x, item)
|
|
}
|
|
#[inline] pub const fn y (y: U, item: A) -> Self {
|
|
Self::Y(y, item)
|
|
}
|
|
#[inline] pub const fn xy (x: U, y: U, item: A) -> Self {
|
|
Self::XY(x, y, item)
|
|
}
|
|
#[inline] pub const fn content (&self) -> &A {
|
|
use Fixed::*;
|
|
match self { X(_, c) => c, Y(_, c) => c, XY(_, _, c) => c, }
|
|
}
|
|
}
|
|
|
|
impl<U: Coordinate, T> Fixed<U, T> {
|
|
#[inline] pub fn dx (&self) -> U {
|
|
use Fixed::*;
|
|
match self { X(x, _) => *x, Y(_, _) => 0.into(), XY(x, _, _) => *x, }
|
|
}
|
|
#[inline] pub fn dy (&self) -> U {
|
|
use Fixed::*;
|
|
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
|
|
}
|
|
}
|
|
|
|
impl<O: Out, T: Draw<O>> Draw<O> for Fixed<O::Unit, T> {
|
|
fn draw (&self, to: &mut O) {
|
|
let area = Layout::<O>::layout(&self, to.area());
|
|
to.place_at(area, &self.content())
|
|
}
|
|
}
|
|
|
|
impl<O: Out, T> Layout<O> for Fixed<O::Unit, T> {
|
|
fn layout (&self, area: O::Area) -> O::Area {
|
|
[area.x(), area.y(), match self {
|
|
Fixed::X(w, _) | Fixed::XY(w, _, _) => *w, _ => area.w()
|
|
}, match self {
|
|
Fixed::Y(h, _) | Fixed::XY(_, h, _) => *h, _ => area.h()
|
|
}].into()
|
|
}
|
|
}
|