mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
EdnViewData has to go?
This commit is contained in:
parent
ddcb967a2c
commit
585bba6666
6 changed files with 25 additions and 25 deletions
|
|
@ -1,6 +1,19 @@
|
|||
use crate::*;
|
||||
use std::marker::PhantomData;
|
||||
use EdnItem::*;
|
||||
/// Implements `EdnProvide` for content components and expressions
|
||||
#[macro_export] macro_rules! edn_provide_content {
|
||||
(|$self:ident:$Stat:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<'a> EdnProvide<'a, Box<dyn Render<TuiOut> + 'a>> for $State {
|
||||
fn get <S: AsRef<str>> (&'a $self, edn: &'a EdnItem<S>) -> Option<Box<dyn Render<TuiOut> + 'a>> {
|
||||
Some(match edn.to_ref() {
|
||||
$(EdnItem::Sym($pat) => $expr),*,
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Renders from EDN source and context.
|
||||
#[derive(Default)]
|
||||
pub enum EdnView<'a, E: Output, T: EdnViewData<'a, E> + std::fmt::Debug> {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
use crate::*;
|
||||
use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}};
|
||||
//use ratatui::prelude::{Style, Color};
|
||||
|
||||
// TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small
|
||||
|
||||
pub trait HasSize<E: Output> {
|
||||
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),*>)? {
|
||||
|
|
@ -15,7 +12,6 @@ pub trait HasSize<E: Output> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A widget that tracks its render width and height
|
||||
#[derive(Default)]
|
||||
pub struct Measure<E: Output> {
|
||||
|
|
@ -23,14 +19,12 @@ pub struct Measure<E: Output> {
|
|||
pub x: Arc<AtomicUsize>,
|
||||
pub y: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
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: Output> Clone for Measure<E> {
|
||||
fn clone (&self) -> Self {
|
||||
Self {
|
||||
|
|
@ -40,7 +34,6 @@ impl<E: Output> Clone 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")
|
||||
|
|
@ -49,7 +42,6 @@ impl<E: Output> std::fmt::Debug for Measure<E> {
|
|||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Output> Measure<E> {
|
||||
pub fn w (&self) -> usize { self.x.load(Relaxed) }
|
||||
pub fn h (&self) -> usize { self.y.load(Relaxed) }
|
||||
|
|
@ -69,7 +61,6 @@ impl<E: Output> Measure<E> {
|
|||
Bsp::b(Fill::xy(self), item)
|
||||
}
|
||||
}
|
||||
|
||||
///// A scrollable area.
|
||||
//pub struct Scroll<E, F>(pub F, pub Direction, pub u64, PhantomData<E>)
|
||||
//where
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue