mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
switchable edn example
This commit is contained in:
parent
4ae31bbba0
commit
ce4574ed78
8 changed files with 105 additions and 21 deletions
|
|
@ -1,6 +0,0 @@
|
|||
#[macro_export] macro_rules! run_tek_edn {
|
||||
($source:expr) => {
|
||||
struct EdnRunner;
|
||||
impl<E: Engine> EdnLayout<E> for EdnRunner;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ pub use ::tek_layout;
|
|||
mod edn_error; pub use self::edn_error::*;
|
||||
mod edn_item; pub use self::edn_item::*;
|
||||
mod edn_iter; pub use self::edn_iter::*;
|
||||
mod edn_main; pub use self::edn_main::*;
|
||||
mod edn_token; pub use self::edn_token::*;
|
||||
mod edn_view; pub use self::edn_view::*;
|
||||
|
||||
|
|
@ -38,6 +37,6 @@ mod edn_view; pub use self::edn_view::*;
|
|||
EdnItem::<String>::read_all(include_str!("../examples/edn01.edn"))?;
|
||||
EdnItem::<String>::read_all(include_str!("../examples/edn02.edn"))?;
|
||||
//panic!("{layout:?}");
|
||||
//let content = <dyn EdnLayout<::tek_engine::tui::Tui>>::from(&layout);
|
||||
//let content = <dyn EdnViewData<::tek_engine::tui::Tui>>::from(&layout);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue