separate Input and Output impls

This commit is contained in:
🪞👃🪞 2025-01-05 22:01:54 +01:00
parent a6efde40f8
commit 0e821e098f
77 changed files with 465 additions and 454 deletions

View file

@ -5,10 +5,13 @@ pub struct TuiOut {
pub area: [u16;4]
}
impl Output<Tui> for TuiOut {
impl Output for TuiOut {
type Unit = u16;
type Size = [Self::Unit;2];
type Area = [Self::Unit;4];
#[inline] fn area (&self) -> [u16;4] { self.area }
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
#[inline] fn place (&mut self, area: [u16;4], content: &impl Render<Tui>) {
#[inline] fn place (&mut self, area: [u16;4], content: &impl Render<TuiOut>) {
let last = self.area();
*self.area_mut() = area;
content.render(self);
@ -65,24 +68,6 @@ impl TuiOut {
}
}
impl Content<Tui> for &str {
fn layout (&self, to: [u16;4]) -> [u16;4] {
to.center_xy([self.chars().count() as u16, 1])
}
fn render (&self, to: &mut TuiOut) {
to.blit(self, to.area.x(), to.area.y(), None)
}
}
impl Content<Tui> for String {
fn layout (&self, to: [u16;4]) -> [u16;4] {
to.center_xy([self.chars().count() as u16, 1])
}
fn render (&self, to: &mut TuiOut) {
to.blit(self, to.area.x(), to.area.y(), None)
}
}
pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) {
for row in 0..area.h() {
let y = area.y() + row;
@ -113,4 +98,4 @@ pub fn half_block (lower: bool, upper: bool) -> Option<char> {
}
}
//impl<T: Content<Tui>> Render<Tui> for T {}
//impl<T: Content<TuiOut>> Render<TuiOut> for T {}