layout: remove more superfluous PhantomData usage

This commit is contained in:
🪞👃🪞 2025-01-03 23:00:26 +01:00
parent 2b07e7963e
commit f81a04dd44
3 changed files with 21 additions and 22 deletions

View file

@ -7,22 +7,22 @@ use crate::*;
/// using `PhantomData` to permit the double generic.
macro_rules! transform_xy {
($self:ident : $Enum:ident |$to:ident|$area:expr) => {
pub enum $Enum<E: Engine, T: Content<E>> { _Unused(PhantomData<E>), X(T), Y(T), XY(T) }
impl<E: Engine, T: Content<E>> $Enum<E, T> {
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: Engine, T: Content<E>> Content<E> for $Enum<E, T> {
impl<E: Engine, T: Content<E>> Content<E> for $Enum<T> {
fn content (&self) -> impl Content<E> {
match self {
Self::X(item) => item,
Self::Y(item) => item,
Self::XY(item) => item,
_ => unreachable!()
}
}
fn layout (&$self, $to: <E as Engine>::Area) -> <E as Engine>::Area {
use $Enum::*;
$area
}
}
@ -32,10 +32,9 @@ macro_rules! transform_xy {
transform_xy!(self: Fill |to|{
let [x0, y0, wmax, hmax] = to.xywh();
let [x, y, w, h] = Content::layout(&self.content(), to).xywh();
return match self {
Self::X(_) => [x0, y, wmax, h],
Self::Y(_) => [x, y0, w, hmax],
Self::XY(_) => [x0, y0, wmax, hmax],
_ => unreachable!()
match self {
X(_) => [x0, y, wmax, h],
Y(_) => [x, y0, w, hmax],
XY(_) => [x0, y0, wmax, hmax],
}.into()
});