mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: big flat pt.5: implement transforms with macro
This commit is contained in:
parent
34e731f111
commit
18b2d8c48b
8 changed files with 387 additions and 558 deletions
|
|
@ -102,6 +102,33 @@ pub trait Area<N: Coordinate>: Copy {
|
|||
#[inline] fn clip (&self, wh: impl Size<N>) -> [N;4] {
|
||||
[self.x(), self.y(), wh.w(), wh.h()]
|
||||
}
|
||||
#[inline] fn set_w (&self, w: N) -> [N;4] {
|
||||
[self.x(), self.y(), w, self.h()]
|
||||
}
|
||||
#[inline] fn set_h (&self, h: N) -> [N;4] {
|
||||
[self.x(), self.y(), self.w(), h]
|
||||
}
|
||||
fn x2 (&self) -> N {
|
||||
self.x() + self.w()
|
||||
}
|
||||
fn y2 (&self) -> N {
|
||||
self.y() + self.h()
|
||||
}
|
||||
#[inline] fn lrtb (&self) -> [N;4] {
|
||||
[self.x(), self.x2(), self.y(), self.y2()]
|
||||
}
|
||||
#[inline] fn push_x (&self, x: N) -> [N;4] {
|
||||
[self.x() + x, self.y(), self.w(), self.h()]
|
||||
}
|
||||
#[inline] fn push_y (&self, y: N) -> [N;4] {
|
||||
[self.x(), self.y() + y, self.w(), self.h()]
|
||||
}
|
||||
#[inline] fn shrink_x (&self, x: N) -> [N;4] {
|
||||
[self.x(), self.y(), self.w().minus(x), self.h()]
|
||||
}
|
||||
#[inline] fn shrink_y (&self, y: N) -> [N;4] {
|
||||
[self.x(), self.y(), self.w(), self.h().minus(y)]
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate> Area<N> for (N, N, N, N) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
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: &impl Render<E>) -> Usually<()>;
|
||||
}
|
||||
|
||||
/// Define custom content for a struct.
|
||||
#[macro_export] macro_rules! render {
|
||||
|
||||
|
|
@ -45,11 +55,37 @@ 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>: Send + Sync {
|
||||
fn content (&self) -> Option<impl Render<E>>;
|
||||
}
|
||||
|
||||
//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 {
|
||||
fn content (&self) -> Option<impl Render<E>> {
|
||||
(*self).content()
|
||||
}
|
||||
}
|
||||
//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 {}
|
||||
|
||||
//impl<E: Engine, C: Content<E>> Render<E> for C {
|
||||
///// Minimum size to use
|
||||
//fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||
|
|
@ -63,38 +99,6 @@ pub trait Content<E: Engine>: Send + Sync {
|
|||
//}
|
||||
//}
|
||||
|
||||
/// 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 {}
|
||||
|
||||
/****
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ pub struct TuiOutput {
|
|||
impl Output<Tui> for TuiOutput {
|
||||
#[inline] fn area (&self) -> [u16;4] { self.area }
|
||||
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
|
||||
#[inline] fn render_in (&mut self, area: [u16;4], widget: &dyn Render<Tui>) -> Usually<()> {
|
||||
#[inline] fn render_in (&mut self, area: [u16;4], widget: &impl Render<Tui>) -> Usually<()> {
|
||||
let last = self.area();
|
||||
*self.area_mut() = area;
|
||||
widget.render(self)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue