big ass refactor (rip client)

This commit is contained in:
🪞👃🪞 2024-07-03 14:51:48 +03:00
parent 94c1f83ef2
commit 8c3cf53c67
56 changed files with 2232 additions and 1891 deletions

View file

@ -2,34 +2,38 @@ use crate::core::*;
use ratatui::widgets::WidgetRef;
/// Trait for things that render to the display.
pub trait Render {
pub trait Render: Send {
// Render something to an area of the buffer.
// Returns area used by component.
// This is insufficient but for the most basic dynamic layout algorithms.
fn render (&self, _b: &mut Buffer, _a: Rect) -> Usually<Rect> {
Ok(Rect { x: 0, y: 0, width: 0, height: 0 })
}
fn min_width (&self) -> u16 {
0
}
fn max_width (&self) -> u16 {
u16::MAX
}
fn min_height (&self) -> u16 {
0
}
fn max_height (&self) -> u16 {
u16::MAX
}
//fn boxed (self) -> Box<dyn Render> where Self: Sized + 'static {
//Box::new(self)
//}
}
impl<T: Fn(&mut Buffer, Rect) -> Usually<Rect>> Render for T {
#[macro_export] macro_rules! render {
($T:ty) => {
impl Render for $T {}
};
($T:ty |$self:ident, $buf:ident, $area:ident|$block:tt) => {
impl Render for $T {
fn render (&$self, $buf: &mut Buffer, $area: Rect) -> Usually<Rect> {
$block
}
}
};
($T:ty = $render:path) => {
impl Render for $T {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
$render(self, buf, area)
}
}
}
}
impl<T: Fn(&mut Buffer, Rect) -> Usually<Rect> + Send> Render for T {
fn render (&self, b: &mut Buffer, a: Rect) -> Usually<Rect> {
(*self).render(b, a)
(*self)(b, a)
}
}