mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 12:16:44 +01:00
wip: directionalize!
can't fit all into 1 trait because of directionality of trait implementation rules and constraints :(
This commit is contained in:
parent
f797a7143d
commit
7c1cddc759
10 changed files with 221 additions and 222 deletions
|
|
@ -26,31 +26,24 @@ use crate::*;
|
|||
/// along either the X axis, the Y axis, or both.
|
||||
macro_rules! transform_xy {
|
||||
($x:literal $y:literal $xy:literal |$self:ident : $Enum:ident, $to:ident|$area:expr) => {
|
||||
pub enum $Enum<T> { X(T), Y(T), XY(T) }
|
||||
impl<T> $Enum<T> {
|
||||
#[inline] pub const fn x (item: T) -> Self {
|
||||
Self::X(item)
|
||||
}
|
||||
#[inline] pub const fn y (item: T) -> Self {
|
||||
Self::Y(item)
|
||||
}
|
||||
#[inline] pub const fn xy (item: T) -> Self {
|
||||
Self::XY(item)
|
||||
}
|
||||
pub enum $Enum<A> { X(A), Y(A), XY(A) }
|
||||
impl<A> $Enum<A> {
|
||||
#[inline] pub const fn x (item: A) -> Self { Self::X(item) }
|
||||
#[inline] pub const fn y (item: A) -> Self { Self::Y(item) }
|
||||
#[inline] pub const fn xy (item: A) -> Self { Self::XY(item) }
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<'state, E: Output + 'state, T: ViewContext<'state, E>>
|
||||
Dsl<T> for $Enum<RenderBox<'state, E>> {
|
||||
fn take_from <'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
impl<A, T: Dsl<A>> FromDsl<T> for $Enum<A> {
|
||||
fn take_from <'state, 'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
if let Some(Token { value: Value::Key(k), .. }) = iter.peek() {
|
||||
let mut base = iter.clone();
|
||||
return Ok(Some(match iter.next() {
|
||||
Some(Token{value:Value::Key($x),..}) =>
|
||||
Self::x(state.get_content_or_fail(iter)?),
|
||||
Self::x(state.take_or_fail(iter, "x: no content")?),
|
||||
Some(Token{value:Value::Key($y),..}) =>
|
||||
Self::y(state.get_content_or_fail(iter)?),
|
||||
Self::y(state.take_or_fail(iter, "y: no content")?),
|
||||
Some(Token{value:Value::Key($xy),..}) =>
|
||||
Self::xy(state.get_content_or_fail(iter)?),
|
||||
Self::xy(state.take_or_fail(iter, "xy: no content")?),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
}
|
||||
|
|
@ -77,31 +70,30 @@ macro_rules! transform_xy {
|
|||
/// along either the X axis, the Y axis, or both.
|
||||
macro_rules! transform_xy_unit {
|
||||
($x:literal $y:literal $xy:literal |$self:ident : $Enum:ident, $to:ident|$layout:expr) => {
|
||||
pub enum $Enum<U, T> { X(U, T), Y(U, T), XY(U, U, T), }
|
||||
impl<U, T> $Enum<U, T> {
|
||||
#[inline] pub const fn x (x: U, item: T) -> Self { Self::X(x, item) }
|
||||
#[inline] pub const fn y (y: U, item: T) -> Self { Self::Y(y, item) }
|
||||
#[inline] pub const fn xy (x: U, y: U, item: T) -> Self { Self::XY(x, y, item) }
|
||||
pub enum $Enum<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
|
||||
impl<U, A> $Enum<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) }
|
||||
}
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<'state, E: Output + 'state, T: ViewContext<'state, E>>
|
||||
Dsl<T> for $Enum<E::Unit, RenderBox<'state, E>> {
|
||||
fn take_from <'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
impl<A, U: Coordinate, T: Dsl<A> + Dsl<U>> FromDsl<T> for $Enum<U, A> {
|
||||
fn take_from <'state, 'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
Ok(if let Some(Token { value: Value::Key($x|$y|$xy), .. }) = iter.peek() {
|
||||
let mut base = iter.clone();
|
||||
Some(match iter.next() {
|
||||
Some(Token { value: Value::Key($x), .. }) => Self::x(
|
||||
state.take_or_fail(iter, "no unit specified")?,
|
||||
state.get_content_or_fail(iter)?,
|
||||
state.take_or_fail(iter, "x: no unit")?,
|
||||
state.take_or_fail(iter, "x: no content")?,
|
||||
),
|
||||
Some(Token { value: Value::Key($y), .. }) => Self::y(
|
||||
state.take_or_fail(iter, "no unit specified")?,
|
||||
state.get_content_or_fail(iter)?,
|
||||
state.take_or_fail(iter, "y: no unit")?,
|
||||
state.take_or_fail(iter, "y: no content")?,
|
||||
),
|
||||
Some(Token { value: Value::Key($x), .. }) => Self::xy(
|
||||
state.take_or_fail(iter, "no unit specified")?,
|
||||
state.take_or_fail(iter, "no unit specified")?,
|
||||
state.get_content_or_fail(iter)?
|
||||
state.take_or_fail(iter, "xy: no unit x")?,
|
||||
state.take_or_fail(iter, "xy: no unit y")?,
|
||||
state.take_or_fail(iter, "xy: no content")?
|
||||
),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue