switchable edn example

This commit is contained in:
🪞👃🪞 2025-01-05 16:51:26 +01:00
parent 4ae31bbba0
commit ce4574ed78
8 changed files with 105 additions and 21 deletions

View file

@ -9,7 +9,7 @@ pub type EdnCallback<'a, Engine, State> =
pub type EdnRenderCallback<'a, Engine, State> =
Box<EdnCallback<'a, Engine, State>>;
pub trait EdnLayout<E: Engine> {
pub trait EdnViewData<E: Engine> {
fn get_bool (&self, _sym: &str) -> bool { false }
fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() }
fn get_usize (&self, _sym: &str) -> usize { 0 }
@ -17,21 +17,21 @@ pub trait EdnLayout<E: Engine> {
}
/// Renders from EDN source and context.
pub struct EdnView<E: Engine, T: EdnLayout<E>> {
pub struct EdnView<E: Engine, T: EdnViewData<E>> {
_engine: PhantomData<E>,
context: T,
layout: EdnItem<String>
//render: Box<dyn Fn(&'a T)->Box<dyn Render<E> + Send + Sync + 'a> + Send + Sync + 'a>
}
impl<E: Engine, T: EdnLayout<E>> EdnView<E, T> {
impl<E: Engine, T: EdnViewData<E>> EdnView<E, T> {
pub fn new (context: T, source: &str) -> Usually<Self> {
let layout = EdnItem::read_one(&source)?.0;
Ok(Self { _engine: Default::default(), context, layout, })
}
}
impl<E: Engine, T: EdnLayout<E> + Send + Sync> Content<E> for EdnView<E, T> {
impl<E: Engine, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {
fn content (&self) -> impl Render<E> {
use EdnItem::*;
match &self.layout {