mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +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()),
|
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)
|
Bsp::b(Fill::xy(&self), item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,22 @@ use crate::*;
|
||||||
/// using `PhantomData` to permit the double generic.
|
/// using `PhantomData` to permit the double generic.
|
||||||
macro_rules! transform_xy {
|
macro_rules! transform_xy {
|
||||||
($self:ident : $Enum:ident |$to:ident|$area:expr) => {
|
($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) }
|
pub enum $Enum<T> { X(T), Y(T), XY(T) }
|
||||||
impl<E: Engine, T: Content<E>> $Enum<E, T> {
|
impl<T> $Enum<T> {
|
||||||
pub fn x (item: T) -> Self { Self::X(item) }
|
pub fn x (item: T) -> Self { Self::X(item) }
|
||||||
pub fn y (item: T) -> Self { Self::Y(item) }
|
pub fn y (item: T) -> Self { Self::Y(item) }
|
||||||
pub fn xy (item: T) -> Self { Self::XY(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> {
|
fn content (&self) -> impl Content<E> {
|
||||||
match self {
|
match self {
|
||||||
Self::X(item) => item,
|
Self::X(item) => item,
|
||||||
Self::Y(item) => item,
|
Self::Y(item) => item,
|
||||||
Self::XY(item) => item,
|
Self::XY(item) => item,
|
||||||
_ => unreachable!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn layout (&$self, $to: <E as Engine>::Area) -> <E as Engine>::Area {
|
fn layout (&$self, $to: <E as Engine>::Area) -> <E as Engine>::Area {
|
||||||
|
use $Enum::*;
|
||||||
$area
|
$area
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -32,10 +32,9 @@ macro_rules! transform_xy {
|
||||||
transform_xy!(self: Fill |to|{
|
transform_xy!(self: Fill |to|{
|
||||||
let [x0, y0, wmax, hmax] = to.xywh();
|
let [x0, y0, wmax, hmax] = to.xywh();
|
||||||
let [x, y, w, h] = Content::layout(&self.content(), to).xywh();
|
let [x, y, w, h] = Content::layout(&self.content(), to).xywh();
|
||||||
return match self {
|
match self {
|
||||||
Self::X(_) => [x0, y, wmax, h],
|
X(_) => [x0, y, wmax, h],
|
||||||
Self::Y(_) => [x, y0, w, hmax],
|
Y(_) => [x, y0, w, hmax],
|
||||||
Self::XY(_) => [x0, y0, wmax, hmax],
|
XY(_) => [x0, y0, wmax, hmax],
|
||||||
_ => unreachable!()
|
|
||||||
}.into()
|
}.into()
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,29 +4,29 @@ use crate::*;
|
||||||
/// along either the X axis, the Y axis, or both.
|
/// along either the X axis, the Y axis, or both.
|
||||||
macro_rules! transform_xy_unit {
|
macro_rules! transform_xy_unit {
|
||||||
(|$self:ident : $Enum:ident, $to:ident|$layout:expr) => {
|
(|$self:ident : $Enum:ident, $to:ident|$layout:expr) => {
|
||||||
pub enum $Enum<E: Engine, T: Content<E>> {
|
pub enum $Enum<U, T> { X(U, T), Y(U, T), XY(U, U, T), }
|
||||||
X(E::Unit, T), Y(E::Unit, T), XY(E::Unit, E::Unit, 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> {
|
impl<U: Copy + Coordinate, T> $Enum<U, T> {
|
||||||
pub fn x (x: E::Unit, item: T) -> Self { Self::X(x, item) }
|
pub fn dx (&self) -> U {
|
||||||
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 {
|
|
||||||
match self {
|
match self {
|
||||||
Self::X(x, _) => *x,
|
Self::X(x, _) => *x,
|
||||||
Self::Y(_, _) => E::Unit::zero(),
|
Self::Y(_, _) => 0.into(),
|
||||||
Self::XY(x, _, _) => *x,
|
Self::XY(x, _, _) => *x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn dy (&self) -> E::Unit {
|
pub fn dy (&self) -> U {
|
||||||
match self {
|
match self {
|
||||||
Self::X(_, _) => E::Unit::zero(),
|
Self::X(_, _) => 0.into(),
|
||||||
Self::Y(y, _) => *y,
|
Self::Y(y, _) => *y,
|
||||||
Self::XY(_, 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> {
|
fn content (&self) -> impl Content<E> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
Self::X(_, content) => content,
|
Self::X(_, content) => content,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue