mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: big flat pt.3, testing standalone tui
This commit is contained in:
parent
a5628fb663
commit
cb680ab096
4 changed files with 189 additions and 139 deletions
|
|
@ -1,16 +1,6 @@
|
|||
use crate::*;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
/// Rendering target
|
||||
pub trait Output<E: Engine> {
|
||||
/// Current output area
|
||||
fn area (&self) -> E::Area;
|
||||
/// Mutable pointer to area
|
||||
fn area_mut (&mut self) -> &mut E::Area;
|
||||
/// Render widget in area
|
||||
fn render_in (&mut self, area: E::Area, widget: &dyn Render<E>) -> Usually<()>;
|
||||
}
|
||||
|
||||
/// Write content to output buffer.
|
||||
pub trait Render<E: Engine>: Send + Sync {
|
||||
/// Minimum size to use
|
||||
|
|
@ -23,32 +13,55 @@ pub trait Render<E: Engine>: Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> Render<E> for &dyn Render<E> {}
|
||||
impl<E: Engine> Render<E> for &mut dyn Render<E> {}
|
||||
impl<E: Engine> Render<E> for Box<dyn Render<E>> {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for &R {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for &mut R {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for Option<R> {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for Arc<R> {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for Mutex<R> {}
|
||||
impl<E: Engine, R: Render<E>> Render<E> for RwLock<R> {}
|
||||
|
||||
/// Something that can be represented by a renderable component.
|
||||
pub trait Content<E: Engine>: Render<E> + Send + Sync {
|
||||
fn content (&self) -> Option<impl Render<E>> where (): Render<E> {
|
||||
None::<()>
|
||||
pub trait Content<E: Engine>: Send + Sync {
|
||||
fn content (&self) -> Option<impl Render<E>>;
|
||||
}
|
||||
|
||||
impl<E: Engine, C: Content<E>> Render<E> for C {
|
||||
/// Minimum size to use
|
||||
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
self.content().map(|content|content.min_size(to))
|
||||
.unwrap_or(Ok(None))
|
||||
}
|
||||
/// Draw to output render target
|
||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||
self.content().map(|content|content.render(to))
|
||||
.unwrap_or(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> Content<E> for &dyn Render<E> {}
|
||||
impl<E: Engine> Content<E> for &mut dyn Render<E> {}
|
||||
impl<E: Engine> Content<E> for Box<dyn Render<E>> {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for &C {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for &mut C {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for Option<C> {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for Arc<C> {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for Mutex<C> {}
|
||||
impl<E: Engine, C: Content<E>> Content<E> for RwLock<C> {}
|
||||
/// Rendering target
|
||||
pub trait Output<E: Engine> {
|
||||
/// Current output area
|
||||
fn area (&self) -> E::Area;
|
||||
/// Mutable pointer to area
|
||||
fn area_mut (&mut self) -> &mut E::Area;
|
||||
/// Render widget in area
|
||||
fn render_in (&mut self, area: E::Area, widget: &dyn Render<E>) -> Usually<()>;
|
||||
}
|
||||
|
||||
//impl<E: Engine> Render<E> for &dyn Render<E> {}
|
||||
//impl<E: Engine> Render<E> for &mut dyn Render<E> {}
|
||||
//impl<E: Engine> Render<E> for Box<dyn Render<E>> {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for &R {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for &mut R {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for Option<R> {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for Arc<R> {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for Mutex<R> {}
|
||||
//impl<E: Engine, R: Render<E>> Render<E> for RwLock<R> {}
|
||||
|
||||
//impl<E: Engine> Content<E> for &dyn Render<E> {}
|
||||
//impl<E: Engine> Content<E> for &mut dyn Render<E> {}
|
||||
//impl<E: Engine> Content<E> for Box<dyn Render<E>> {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for &C {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for &mut C {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for Option<C> {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for Arc<C> {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for Mutex<C> {}
|
||||
//impl<E: Engine, C: Content<E>> Content<E> for RwLock<C> {}
|
||||
|
||||
//impl<E: Engine, C: Content<E>> Render<E> for C {}
|
||||
|
||||
/****
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue