mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
7c1cddc759
commit
455d6d00d5
14 changed files with 252 additions and 286 deletions
|
|
@ -36,39 +36,33 @@ pub enum Alignment { #[default] Center, X, Y, NW, N, NE, E, SE, S, SW, W }
|
|||
pub struct Align<A>(Alignment, A);
|
||||
|
||||
#[cfg(feature = "dsl")]
|
||||
impl<State: Dsl<A>, A> FromDsl<State> for Align<A> {
|
||||
fn take_from <'state, 'source: 'state> (state: &'state State, iter: &mut TokenIter<'source>)
|
||||
-> Perhaps<Self>
|
||||
{
|
||||
if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
match key {
|
||||
"align/c"|"align/x"|"align/y"|
|
||||
"align/n"|"align/s"|"align/e"|"align/w"|
|
||||
"align/nw"|"align/sw"|"align/ne"|"align/se" => {
|
||||
let _ = iter.next().unwrap();
|
||||
let content = state.take_or_fail(&mut iter.clone(), "expected content")?;
|
||||
return Ok(Some(match key {
|
||||
"align/c" => Self::c(content),
|
||||
"align/x" => Self::x(content),
|
||||
"align/y" => Self::y(content),
|
||||
"align/n" => Self::n(content),
|
||||
"align/s" => Self::s(content),
|
||||
"align/e" => Self::e(content),
|
||||
"align/w" => Self::w(content),
|
||||
"align/nw" => Self::nw(content),
|
||||
"align/ne" => Self::ne(content),
|
||||
"align/sw" => Self::sw(content),
|
||||
"align/se" => Self::se(content),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
},
|
||||
_ => return Ok(None)
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
from_dsl!(@a: Align<A>: |state, iter|if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
|
||||
match key {
|
||||
"align/c"|"align/x"|"align/y"|
|
||||
"align/n"|"align/s"|"align/e"|"align/w"|
|
||||
"align/nw"|"align/sw"|"align/ne"|"align/se" => {
|
||||
let _ = iter.next().unwrap();
|
||||
let content = state.take_or_fail(&mut iter.clone(), "expected content")?;
|
||||
return Ok(Some(match key {
|
||||
"align/c" => Self::c(content),
|
||||
"align/x" => Self::x(content),
|
||||
"align/y" => Self::y(content),
|
||||
"align/n" => Self::n(content),
|
||||
"align/s" => Self::s(content),
|
||||
"align/e" => Self::e(content),
|
||||
"align/w" => Self::w(content),
|
||||
"align/nw" => Self::nw(content),
|
||||
"align/ne" => Self::ne(content),
|
||||
"align/sw" => Self::sw(content),
|
||||
"align/se" => Self::se(content),
|
||||
_ => unreachable!()
|
||||
}))
|
||||
},
|
||||
_ => return Ok(None)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Ok(None)
|
||||
});
|
||||
|
||||
impl<A> Align<A> {
|
||||
#[inline] pub const fn c (a: A) -> Self { Self(Alignment::Center, a) }
|
||||
|
|
@ -85,7 +79,7 @@ impl<A> Align<A> {
|
|||
}
|
||||
|
||||
impl<E: Output, A: Content<E>> Content<E> for Align<A> {
|
||||
fn content (&self) -> impl Render<E> {
|
||||
fn content (&self) -> impl Render<E> + '_ {
|
||||
&self.1
|
||||
}
|
||||
fn layout (&self, on: E::Area) -> E::Area {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue