mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 20:26: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
|
|
@ -36,20 +36,17 @@ 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, E: Output + 'state, T: ViewContext<'state, E>>
|
||||
Dsl<T> for Align<RenderBox<'state, E>> {
|
||||
fn take_from <'source: 'state> (state: &'state T, iter: &mut TokenIter<'source>) -> Perhaps<Self> {
|
||||
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 = if let Some(content) = state.get_content(&mut iter.clone())? {
|
||||
content
|
||||
} else {
|
||||
panic!("no content corresponding to {:?}", &iter);
|
||||
};
|
||||
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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue