mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
separate Input and Output impls
This commit is contained in:
parent
a6efde40f8
commit
0e821e098f
77 changed files with 465 additions and 454 deletions
|
|
@ -4,7 +4,7 @@ use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}};
|
|||
|
||||
// TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small
|
||||
|
||||
pub trait HasSize<E: Engine> {
|
||||
pub trait HasSize<E: Output> {
|
||||
fn size (&self) -> &Measure<E>;
|
||||
}
|
||||
|
||||
|
|
@ -18,20 +18,20 @@ pub trait HasSize<E: Engine> {
|
|||
|
||||
/// A widget that tracks its render width and height
|
||||
#[derive(Default)]
|
||||
pub struct Measure<E: Engine> {
|
||||
pub struct Measure<E: Output> {
|
||||
_engine: PhantomData<E>,
|
||||
pub x: Arc<AtomicUsize>,
|
||||
pub y: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl<E: Engine> Content<E> for Measure<E> {
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
impl<E: Output> Content<E> for Measure<E> {
|
||||
fn render (&self, to: &mut E) {
|
||||
self.x.store(to.area().w().into(), Relaxed);
|
||||
self.y.store(to.area().h().into(), Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> Clone for Measure<E> {
|
||||
impl<E: Output> Clone for Measure<E> {
|
||||
fn clone (&self) -> Self {
|
||||
Self {
|
||||
_engine: Default::default(),
|
||||
|
|
@ -41,7 +41,7 @@ impl<E: Engine> Clone for Measure<E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> std::fmt::Debug for Measure<E> {
|
||||
impl<E: Output> std::fmt::Debug for Measure<E> {
|
||||
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
f.debug_struct("Measure")
|
||||
.field("width", &self.x)
|
||||
|
|
@ -50,7 +50,7 @@ impl<E: Engine> std::fmt::Debug for Measure<E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> Measure<E> {
|
||||
impl<E: Output> Measure<E> {
|
||||
pub fn w (&self) -> usize { self.x.load(Relaxed) }
|
||||
pub fn h (&self) -> usize { self.y.load(Relaxed) }
|
||||
pub fn wh (&self) -> [usize;2] { [self.w(), self.h()] }
|
||||
|
|
@ -73,18 +73,18 @@ impl<E: Engine> Measure<E> {
|
|||
///// A scrollable area.
|
||||
//pub struct Scroll<E, F>(pub F, pub Direction, pub u64, PhantomData<E>)
|
||||
//where
|
||||
//E: Engine,
|
||||
//E: Output,
|
||||
//F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)->Usually<()>)->Usually<()>;
|
||||
|
||||
//pub trait ContentDebug<E: Engine> {
|
||||
//pub trait ContentDebug<E: Output> {
|
||||
//fn debug <W: Content<E>> (other: W) -> DebugOverlay<E, W> {
|
||||
//DebugOverlay(Default::default(), other)
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl<E: Engine> ContentDebug<E> for E {}
|
||||
//impl<E: Output> ContentDebug<E> for E {}
|
||||
|
||||
//impl Render<Tui> for Measure<Tui> {
|
||||
//impl Render<TuiOut> for Measure<TuiOut> {
|
||||
//fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
//Ok(Some([0u16.into(), 0u16.into()].into()))
|
||||
//}
|
||||
|
|
@ -95,13 +95,13 @@ impl<E: Engine> Measure<E> {
|
|||
//}
|
||||
//}
|
||||
|
||||
//impl Measure<Tui> {
|
||||
//impl Measure<TuiOut> {
|
||||
//pub fn debug (&self) -> ShowMeasure {
|
||||
//ShowMeasure(&self)
|
||||
//}
|
||||
//}
|
||||
|
||||
//render!(<Tui>|self: ShowMeasure<'a>|render(|to: &mut TuiOut|Ok({
|
||||
//render!(Tui: |self: ShowMeasure<'a>|render(|to: &mut TuiOut|Ok({
|
||||
//let w = self.0.w();
|
||||
//let h = self.0.h();
|
||||
//to.blit(&format!(" {w} x {h} "), to.area.x(), to.area.y(), Some(
|
||||
|
|
@ -109,11 +109,11 @@ impl<E: Engine> Measure<E> {
|
|||
//))
|
||||
//})));
|
||||
|
||||
//pub struct ShowMeasure<'a>(&'a Measure<Tui>);
|
||||
//pub struct ShowMeasure<'a>(&'a Measure<TuiOut>);
|
||||
|
||||
//pub struct DebugOverlay<E: Engine, W: Render<E>>(PhantomData<E>, pub W);
|
||||
//pub struct DebugOverlay<E: Output, W: Render<E>>(PhantomData<E>, pub W);
|
||||
|
||||
//impl<T: Render<Tui>> Render<Tui> for DebugOverlay<Tui, T> {
|
||||
//impl<T: Render<TuiOut>> Render<TuiOut> for DebugOverlay<Tui, T> {
|
||||
//fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
//self.1.min_size(to)
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue