mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
wip: examples for the edn rendering
This commit is contained in:
parent
433e4df0f2
commit
174a7ee614
9 changed files with 51 additions and 30 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()?;
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue