detach all layout constructors from engine

This commit is contained in:
🪞👃🪞 2024-12-30 13:48:51 +01:00
parent 61b447403b
commit e0e680eb7c
19 changed files with 487 additions and 520 deletions

View file

@ -1,35 +1,8 @@
use crate::*;
pub trait HasSize<E: Engine> {
fn size (&self) -> &Measure<E>;
}
#[macro_export] macro_rules! has_size {
(<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? {
fn size (&$self) -> &Measure<$E> { $cb }
}
}
}
use super::*;
impl<E: Engine> LayoutDebug<E> for E {}
pub trait LayoutDebug<E: Engine> {
fn debug <W: Render<E>> (other: W) -> DebugOverlay<E, W> {
DebugOverlay(Default::default(), other)
}
}
pub struct DebugOverlay<E: Engine, W: Render<E>>(PhantomData<E>, pub W);
/// A widget that tracks its render width and height
#[derive(Default)]
pub struct Measure<E: Engine> {
_engine: PhantomData<E>,
pub x: Arc<AtomicUsize>,
pub y: Arc<AtomicUsize>,
}
impl<E: Engine> Clone for Measure<E> {
fn clone (&self) -> Self {
Self {
@ -83,7 +56,6 @@ impl Measure<Tui> {
}
}
pub struct ShowMeasure<'a>(&'a Measure<Tui>);
render!(<Tui>|self: ShowMeasure<'a>|render(|to|Ok({
let w = self.0.w();
let h = self.0.h();