mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
output: more big refactors
This commit is contained in:
parent
194f2f9874
commit
5e6338fad8
68 changed files with 1604 additions and 1016 deletions
39
output/src/layout/layout_expand.rs
Normal file
39
output/src/layout/layout_expand.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use crate::*;
|
||||
|
||||
pub enum Expand<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
|
||||
|
||||
impl<U, A> Expand<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) }
|
||||
}
|
||||
|
||||
impl<O: Out, T: Draw<O> + Layout<O>> Content<O> for Expand<O::Unit, T> {
|
||||
fn content (&self) -> impl Draw<O> + Layout<O> + '_ {
|
||||
use Expand::*;
|
||||
match self { X(_, c) => c, Y(_, c) => c, XY(_, _, c) => c, }
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: Out, T: Draw<O> + Layout<O>> Draw<O> for Expand<O::Unit, T> {
|
||||
fn draw (&self, to: &mut O) {
|
||||
to.place_at(self.layout(to.area()), &self.content())
|
||||
}
|
||||
}
|
||||
|
||||
impl<U: Coordinate, T> Expand<U, T> {
|
||||
#[inline] pub fn dx (&self) -> U {
|
||||
use Expand::*;
|
||||
match self { X(x, _) => *x, Y(_, _) => 0.into(), XY(x, _, _) => *x, }
|
||||
}
|
||||
#[inline] pub fn dy (&self) -> U {
|
||||
use Expand::*;
|
||||
match self { X(_, _) => 0.into(), Y(y, _) => *y, XY(_, y, _) => *y, }
|
||||
}
|
||||
}
|
||||
|
||||
impl<O: Out, T: Layout<O>> Layout<O> for Expand<O::Unit, T> {
|
||||
fn layout (&self, to: O::Area) -> O::Area {
|
||||
[to.x(), to.y(), to.w().plus(self.dx()), to.h().plus(self.dy())].into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue