mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
edn -> dsl
This commit is contained in:
parent
d30eda33d1
commit
877b344765
35 changed files with 197 additions and 225 deletions
|
|
@ -1,10 +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),*>)? {
|
||||
|
|
@ -12,6 +12,7 @@ pub trait HasSize<E: Output> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A widget that tracks its render width and height
|
||||
#[derive(Default)]
|
||||
pub struct Measure<E: Output> {
|
||||
|
|
@ -19,12 +20,15 @@ pub struct Measure<E: Output> {
|
|||
pub x: Arc<AtomicUsize>,
|
||||
pub y: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
// TODO: 🡘 🡙 ←🡙→ indicator to expand window when too small
|
||||
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 {
|
||||
|
|
@ -34,6 +38,7 @@ 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")
|
||||
|
|
@ -42,6 +47,7 @@ impl<E: Output> std::fmt::Debug for Measure<E> {
|
|||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Output> Measure<E> {
|
||||
pub fn new () -> Self {
|
||||
Self {
|
||||
|
|
@ -79,66 +85,3 @@ impl<E: Output> Measure<E> {
|
|||
Bsp::b(Fill::xy(self), item)
|
||||
}
|
||||
}
|
||||
//#[cfg(test)] #[test] fn test_measure () {
|
||||
//use tek_tui::*;
|
||||
//let size: Measure<TuiOut> = Measure::default().set_w(1usize).set_h(1usize).clone();
|
||||
//let size: Measure<TuiOut> = (&Measure::new().set_wh(2usize, 1usize)).clone();
|
||||
//let _ = format!("{:?}", &size);
|
||||
//let _ = size.wh();
|
||||
//let _ = size.format();
|
||||
//let _ = size.of(());
|
||||
//}
|
||||
|
||||
///// A scrollable area.
|
||||
//pub struct Scroll<E, F>(pub F, pub Direction, pub u64, PhantomData<E>)
|
||||
//where
|
||||
//E: Output,
|
||||
//F: Send + Sync + Fn(&mut dyn FnMut(&dyn Content<E>)->Usually<()>)->Usually<()>;
|
||||
|
||||
//pub trait ContentDebug<E: Output> {
|
||||
//fn debug <W: Content<E>> (other: W) -> DebugOverlay<E, W> {
|
||||
//DebugOverlay(Default::default(), other)
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl<E: Output> ContentDebug<E> for E {}
|
||||
|
||||
//impl Render<TuiOut> for Measure<TuiOut> {
|
||||
//fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
//Ok(Some([0u16.into(), 0u16.into()].into()))
|
||||
//}
|
||||
//fn render (&self, to: &mut TuiOut) -> Usually<()> {
|
||||
//self.set_w(to.area().w());
|
||||
//self.set_h(to.area().h());
|
||||
//Ok(())
|
||||
//}
|
||||
//}
|
||||
|
||||
//impl Measure<TuiOut> {
|
||||
//pub fn debug (&self) -> ShowMeasure {
|
||||
//ShowMeasure(&self)
|
||||
//}
|
||||
//}
|
||||
|
||||
//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(
|
||||
//Style::default().bold().italic().bg(Color::Rgb(255, 0, 255)).fg(Color::Rgb(0,0,0))
|
||||
//))
|
||||
//})));
|
||||
|
||||
//pub struct ShowMeasure<'a>(&'a Measure<TuiOut>);
|
||||
|
||||
//pub struct DebugOverlay<E: Output, W: Render<E>>(PhantomData<E>, pub W);
|
||||
|
||||
//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)
|
||||
//}
|
||||
//fn render (&self, to: &mut TuiOut) -> Usually<()> {
|
||||
//let [x, y, w, h] = to.area();
|
||||
//self.1.render(to)?;
|
||||
//Ok(to.blit(&format!("{w}x{h}+{x}+{y}"), x, y, Some(Style::default().green())))
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue