wip: examples for the edn rendering

This commit is contained in:
🪞👃🪞 2025-01-05 04:25:31 +01:00
parent 433e4df0f2
commit 174a7ee614
9 changed files with 51 additions and 30 deletions

View file

@ -27,6 +27,9 @@ impl<E: Engine, C: Content<E>> Render<E> for C {
fn layout (&self, area: E::Area) -> E::Area { Content::layout(self, area) }
fn render (&self, output: &mut E::Output) { Content::render(self, output) }
}
impl<'a, E: Engine> Content<E> for Box<dyn Render<E> + 'a> {
fn content (&self) -> impl Render<E> { self }
}
impl<'a, E: Engine> Content<E> for Box<dyn Render<E> + Send + Sync + 'a> {
fn content (&self) -> impl Render<E> { self }
}
@ -74,6 +77,7 @@ impl<E: Engine, T: Content<E>> Content<E> for Option<T> {
}
}
#[macro_export] macro_rules! render {
(($self:ident:$Struct:ty) => $content:expr) => {
impl <E: Engine> Content<E> for $Struct {

View file

@ -92,7 +92,7 @@ impl Tui {
}
}
pub trait TuiRun<R: Content<Tui> + Handle<Tui> + Sized + 'static> {
pub trait TuiRun<R: Render<Tui> + Handle<Tui> + Sized + 'static> {
/// Run an app in the main loop.
fn run (&self, state: &Arc<RwLock<R>>) -> Usually<()>;
/// Spawn the input thread.
@ -101,7 +101,7 @@ pub trait TuiRun<R: Content<Tui> + Handle<Tui> + Sized + 'static> {
fn run_output (&self, state: &Arc<RwLock<R>>, sleep: Duration) -> JoinHandle<()>;
}
impl<T: Content<Tui> + Handle<Tui> + Sized + 'static> TuiRun<T> for Arc<RwLock<Tui>> {
impl<T: Render<Tui> + Handle<Tui> + Sized + 'static> TuiRun<T> for Arc<RwLock<Tui>> {
fn run (&self, state: &Arc<RwLock<T>>) -> Usually<()> {
let _input_thread = self.run_input(state, Duration::from_millis(100));
self.write().unwrap().setup()?;

View file

@ -65,7 +65,7 @@ impl TuiOut {
}
}
impl Content<Tui> for &str {
impl Render<Tui> for &str {
fn layout (&self, to: [u16;4]) -> [u16;4] {
to.center_xy([self.chars().count() as u16, 1])
}
@ -74,7 +74,7 @@ impl Content<Tui> for &str {
}
}
impl Content<Tui> for String {
impl Render<Tui> for String {
fn layout (&self, to: [u16;4]) -> [u16;4] {
to.center_xy([self.chars().count() as u16, 1])
}