mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor engine and layout into input and output
This commit is contained in:
parent
f052891473
commit
4d0f98acd2
40 changed files with 104 additions and 109 deletions
40
output/src/transform_xy.rs
Normal file
40
output/src/transform_xy.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::*;
|
||||
|
||||
/// Defines an enum that transforms its content
|
||||
/// along either the X axis, the Y axis, or both.
|
||||
///
|
||||
/// The `_Unused` variant wraps the `Output` type
|
||||
/// using `PhantomData` to permit the double generic.
|
||||
macro_rules! transform_xy {
|
||||
($self:ident : $Enum:ident |$to:ident|$area:expr) => {
|
||||
pub enum $Enum<T> { X(T), Y(T), XY(T) }
|
||||
impl<T> $Enum<T> {
|
||||
pub fn x (item: T) -> Self { Self::X(item) }
|
||||
pub fn y (item: T) -> Self { Self::Y(item) }
|
||||
pub fn xy (item: T) -> Self { Self::XY(item) }
|
||||
}
|
||||
impl<E: Output, T: Content<E>> Content<E> for $Enum<T> {
|
||||
fn content (&self) -> impl Render<E> {
|
||||
match self {
|
||||
Self::X(item) => item,
|
||||
Self::Y(item) => item,
|
||||
Self::XY(item) => item
|
||||
}
|
||||
}
|
||||
fn layout (&$self, $to: <E as Output>::Area) -> <E as Output>::Area {
|
||||
use $Enum::*;
|
||||
$area
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transform_xy!(self: Fill |to|{
|
||||
let [x0, y0, wmax, hmax] = to.xywh();
|
||||
let [x, y, w, h] = self.content().layout(to).xywh();
|
||||
match self {
|
||||
X(_) => [x0, y, wmax, h],
|
||||
Y(_) => [x, y0, w, hmax],
|
||||
XY(_) => [x0, y0, wmax, hmax],
|
||||
}.into()
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue