mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
layout: remove more superfluous PhantomData usage
This commit is contained in:
parent
2b07e7963e
commit
f81a04dd44
3 changed files with 21 additions and 22 deletions
|
|
@ -65,7 +65,7 @@ impl<E: Engine> Measure<E> {
|
|||
y: Arc::new(0.into()),
|
||||
}
|
||||
}
|
||||
pub fn of <T: Content<E>> (&self, item: T) -> Bsp<Fill<E, &Self>, T> {
|
||||
pub fn of <T: Content<E>> (&self, item: T) -> Bsp<Fill<&Self>, T> {
|
||||
Bsp::b(Fill::xy(&self), item)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,29 +4,29 @@ use crate::*;
|
|||
/// along either the X axis, the Y axis, or both.
|
||||
macro_rules! transform_xy_unit {
|
||||
(|$self:ident : $Enum:ident, $to:ident|$layout:expr) => {
|
||||
pub enum $Enum<E: Engine, T: Content<E>> {
|
||||
X(E::Unit, T), Y(E::Unit, T), XY(E::Unit, E::Unit, T),
|
||||
pub enum $Enum<U, T> { X(U, T), Y(U, T), XY(U, U, T), }
|
||||
impl<U, T> $Enum<U, T> {
|
||||
pub fn x (x: U, item: T) -> Self { Self::X(x, item) }
|
||||
pub fn y (y: U, item: T) -> Self { Self::Y(y, item) }
|
||||
pub fn xy (x: U, y: U, item: T) -> Self { Self::XY(x, y, item) }
|
||||
}
|
||||
impl<E: Engine, T: Content<E>> $Enum<E, T> {
|
||||
pub fn x (x: E::Unit, item: T) -> Self { Self::X(x, item) }
|
||||
pub fn y (y: E::Unit, item: T) -> Self { Self::Y(y, item) }
|
||||
pub fn xy (x: E::Unit, y: E::Unit, item: T) -> Self { Self::XY(x, y, item) }
|
||||
pub fn dx (&self) -> E::Unit {
|
||||
impl<U: Copy + Coordinate, T> $Enum<U, T> {
|
||||
pub fn dx (&self) -> U {
|
||||
match self {
|
||||
Self::X(x, _) => *x,
|
||||
Self::Y(_, _) => E::Unit::zero(),
|
||||
Self::Y(_, _) => 0.into(),
|
||||
Self::XY(x, _, _) => *x,
|
||||
}
|
||||
}
|
||||
pub fn dy (&self) -> E::Unit {
|
||||
pub fn dy (&self) -> U {
|
||||
match self {
|
||||
Self::X(_, _) => E::Unit::zero(),
|
||||
Self::Y(y, _) => *y,
|
||||
Self::X(_, _) => 0.into(),
|
||||
Self::Y(y, _) => *y,
|
||||
Self::XY(_, y, _) => *y,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<E: Engine, T: Content<E>> Content<E> for $Enum<E, T> {
|
||||
impl<E: Engine, T: Content<E>> Content<E> for $Enum<E::Unit, T> {
|
||||
fn content (&self) -> impl Content<E> {
|
||||
Some(match self {
|
||||
Self::X(_, content) => content,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue