mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
removing engine generic from transforms
This commit is contained in:
parent
452bdf9598
commit
a949117017
8 changed files with 184 additions and 184 deletions
|
|
@ -74,7 +74,7 @@ impl<'a, E: Output, T> ViewContext<'a, E> for T where T:
|
|||
{}
|
||||
impl<'a, E: Output, T: ViewContext<'a, E> + std::fmt::Debug> AtomView<'a, E, T> {
|
||||
pub fn from_source (state: T, source: &'a str) -> Self {
|
||||
match Atom::read_one(&source) {
|
||||
match RefAtom::read_one(&source) {
|
||||
Ok((layout, _)) => Self::Ok(state, layout),
|
||||
Err(error) => Self::Err(format!("{error} in {source}"))
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ pub trait ViewContext<'a, E: Output>:
|
|||
Context<'a, E::Unit> +
|
||||
Context<'a, Box<dyn Render<E> + 'a>>
|
||||
{
|
||||
fn get_bool (&'a self, atom: &'a impl Atom) -> Option<bool> {
|
||||
fn get_bool (&'a self, atom: RefAtom<'a>) -> Option<bool> {
|
||||
Some(match atom.kind() {
|
||||
Sym => match atom.text().as_ref() {
|
||||
":false" | ":f" => false,
|
||||
|
|
@ -116,19 +116,19 @@ pub trait ViewContext<'a, E: Output>:
|
|||
_ => return Context::get(self, atom)
|
||||
})
|
||||
}
|
||||
fn get_usize (&'a self, atom: &'a impl Atom) -> Option<usize> {
|
||||
fn get_usize (&'a self, atom: RefAtom<'a>) -> Option<usize> {
|
||||
Some(match atom.kind() {
|
||||
Num => atom.num(),
|
||||
_ => return Context::get(self, atom)
|
||||
})
|
||||
}
|
||||
fn get_unit (&'a self, atom: &'a impl Atom) -> Option<E::Unit> {
|
||||
fn get_unit (&'a self, atom: RefAtom<'a>) -> Option<E::Unit> {
|
||||
Some(match atom.kind() {
|
||||
Num => E::Unit::from(atom.num() as u16),
|
||||
_ => return Context::get(self, atom)
|
||||
})
|
||||
}
|
||||
fn get_content (&'a self, atom: &'a impl Atom) -> Option<Box<dyn Render<E> + 'a>> where E: 'a {
|
||||
fn get_content (&'a self, atom: RefAtom<'a>) -> Option<Box<dyn Render<E> + 'a>> where E: 'a {
|
||||
try_delegate!(self, atom, When::<_, RenderBox<'a, E>>);
|
||||
try_delegate!(self, atom, Either::<_, RenderBox<'a, E>, RenderBox<'a, E>>);
|
||||
try_delegate!(self, atom, Align::<_, RenderBox<'a, E>>);
|
||||
|
|
@ -152,3 +152,20 @@ pub type AtomCallback<'a, O, State> =
|
|||
// A box containing a function that returns a `RenderBox.
|
||||
pub type AtomRenderCallback<'a, O, State> =
|
||||
Box<AtomCallback<'a, O, State>>;
|
||||
|
||||
pub trait TryFromAtom<'a, T>: Sized {
|
||||
fn try_from_atoms (state: &'a T, atoms: impl Iterator<Item = RefAtom<'a>> + 'a) -> Option<Self>;
|
||||
}
|
||||
pub trait TryIntoAtom<'a, T>: Sized {
|
||||
fn try_into_atoms (&self) -> Option<RefAtomsIterator<'a>>;
|
||||
}
|
||||
#[macro_export] macro_rules! try_from_atoms {
|
||||
(<$l:lifetime, $E:ident>: $Struct:ty: |$state:ident,$atoms:ident|$body:expr) => {
|
||||
impl<$l, $E: Output + $l, T: ViewContext<$l, $E>> TryFromAtom<$l, T> for $Struct {
|
||||
fn try_from_atoms ($state: &$l T, mut $atoms: impl Iterator<Item = RefAtom<$l>> + $l) -> Option<Self> {
|
||||
$body;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue