mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
wip: compiles and runs (not enabled yet)
This commit is contained in:
parent
ac3827b8f3
commit
98d2107e4e
15 changed files with 440 additions and 357 deletions
|
|
@ -1,7 +1,5 @@
|
|||
use crate::*;
|
||||
use std::marker::PhantomData;
|
||||
//use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
/// Rendering target
|
||||
pub trait Output<E: Engine> {
|
||||
/// Current output area
|
||||
|
|
@ -10,31 +8,37 @@ pub trait Output<E: Engine> {
|
|||
fn area_mut (&mut self) -> &mut E::Area;
|
||||
/// Render widget in area
|
||||
fn place (&mut self, area: E::Area, content: &impl Render<E>);
|
||||
|
||||
#[inline] fn x (&self) -> E::Unit { self.area().x() }
|
||||
#[inline] fn y (&self) -> E::Unit { self.area().y() }
|
||||
#[inline] fn w (&self) -> E::Unit { self.area().w() }
|
||||
#[inline] fn h (&self) -> E::Unit { self.area().h() }
|
||||
#[inline] fn wh (&self) -> E::Size { self.area().wh().into() }
|
||||
}
|
||||
pub struct Thunk<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync>(F, PhantomData<E>);
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Thunk<E, T, F> {
|
||||
pub fn new (thunk: F) -> Self { Self(thunk, Default::default()) }
|
||||
}
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Content<E> for Thunk<E, T, F> {
|
||||
fn content (&self) -> impl Content<E> { (self.0)() }
|
||||
}
|
||||
pub trait Render<E: Engine>: Send + Sync {
|
||||
fn layout (&self, area: E::Area) -> E::Area { area }
|
||||
fn render (&self, output: &mut E::Output) {}
|
||||
fn layout (&self, area: E::Area) -> E::Area;
|
||||
fn render (&self, output: &mut E::Output);
|
||||
}
|
||||
pub trait Content<E: Engine>: Send + Sync + Sized {
|
||||
fn content (&self) -> impl Render<E> { () }
|
||||
fn layout (&self, area: E::Area) -> E::Area { self.content().layout(area) }
|
||||
fn render (&self, output: &mut E::Output) { self.content().render(output) }
|
||||
}
|
||||
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<E: Engine> Content<E> for Box<dyn Render<E>> {
|
||||
fn content (&self) -> impl Content<E> { self }
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
impl<E: Engine> Content<E> for &dyn Render<E> {
|
||||
fn content (&self) -> impl Content<E> { self }
|
||||
}
|
||||
pub trait Content<E: Engine>: Send + Sync + Sized {
|
||||
fn content (&self) -> impl Content<E> { () }
|
||||
fn layout (&self, area: E::Area) -> E::Area { area }
|
||||
fn render (&self, output: &mut E::Output) {}
|
||||
fn content (&self) -> impl Render<E> { self }
|
||||
}
|
||||
/// The platonic ideal unit of [Content]: total emptiness at dead center.
|
||||
impl<E: Engine> Content<E> for () {
|
||||
|
|
@ -46,7 +50,7 @@ impl<E: Engine> Content<E> for () {
|
|||
}
|
||||
|
||||
impl<E: Engine, T: Content<E>> Content<E> for &T {
|
||||
fn content (&self) -> impl Content<E> {
|
||||
fn content (&self) -> impl Render<E> {
|
||||
(*self).content()
|
||||
}
|
||||
fn layout (&self, area: E::Area) -> E::Area {
|
||||
|
|
@ -58,9 +62,8 @@ impl<E: Engine, T: Content<E>> Content<E> for &T {
|
|||
}
|
||||
|
||||
impl<E: Engine, T: Content<E>> Content<E> for Option<T> {
|
||||
fn content (&self) -> impl Content<E> {
|
||||
fn content (&self) -> impl Render<E> {
|
||||
self.as_ref()
|
||||
.map(|content|content.content())
|
||||
}
|
||||
fn layout (&self, area: E::Area) -> E::Area {
|
||||
self.as_ref()
|
||||
|
|
@ -73,18 +76,6 @@ impl<E: Engine, T: Content<E>> Content<E> for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Thunk<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync>(F, PhantomData<E>);
|
||||
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Thunk<E, T, F> {
|
||||
pub fn new (thunk: F) -> Self {
|
||||
Self(thunk, Default::default())
|
||||
}
|
||||
}
|
||||
impl<E: Engine, T: Content<E>, F: Fn()->T + Send + Sync> Content<E> for Thunk<E, T, F> {
|
||||
fn content (&self) -> impl Content<E> {
|
||||
(self.0)()
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export] macro_rules! render {
|
||||
(($self:ident:$Struct:ty) => $content:expr) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue