fokken wip

This commit is contained in:
facile pop culture reference 2026-06-16 14:23:03 +03:00
parent be14173126
commit 2dc501c184
11 changed files with 129 additions and 136 deletions

View file

@ -119,25 +119,12 @@ pub fn tui_output <
prev.resize(&mut backend, width, height);
state.view().draw(&mut next).expect("draw failed"); // TODO draw error
prev.redraw(&mut backend, &mut next);
//tui_redraw(&mut backend, &mut prev, &mut next);
}
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
prev.set_string(0, 0, &timer, Style::default());
})?)
}
pub fn tui_redraw <'b, W: Write> (
back: &mut CrosstermBackend<W>,
mut prev: &'b mut Buffer,
mut next: &'b mut Buffer
) {
let updates = prev.diff(&next);
back.draw(updates.into_iter()).expect("failed to render");
Backend::flush(back).expect("failed to flush output new");
std::mem::swap(&mut prev, &mut next);
next.reset();
}
/// Terminal output.
pub struct Tui(
/// Ratatui buffer; area is screen size
@ -147,10 +134,10 @@ pub struct Tui(
);
impl Tui {
fn new (width: u16, height: u16) -> Self {
pub fn new (width: u16, height: u16) -> Self {
Self(Buffer::empty(Rect { x: 0, y: 0, width, height }), XYWH(0, 0, width, height))
}
fn resize <W: Write> (&mut self, back: &mut CrosstermBackend<W>, width: u16, height: u16) {
pub fn resize <W: Write> (&mut self, back: &mut CrosstermBackend<W>, width: u16, height: u16) {
let size = Rect { x: 0, y: 0, width, height };
if self.0.area != size {
back.clear_region(ClearType::All).unwrap();
@ -158,7 +145,7 @@ impl Tui {
self.0.reset();
}
}
fn redraw <'b, W: Write> (&'b mut self, back: &mut CrosstermBackend<W>, mut next: &'b mut Self) {
pub fn redraw <'b, W: Write> (&'b mut self, back: &mut CrosstermBackend<W>, mut next: &'b mut Self) {
let updates = self.0.diff(&next.0);
back.draw(updates.into_iter()).expect("failed to render");
Backend::flush(back).expect("failed to flush output new");
@ -167,7 +154,18 @@ impl Tui {
}
}
impl Screen for Tui { type Unit = u16; }
impl Screen for Tui {
type Unit = u16;
/// Render drawable in subarea specified by `area`
fn show <'t, T: Draw<Self>> (
&mut self, area: XYWH<u16>, content: T
) {
let previous_area = self.1;
self.1 = area;
let _result_area = content.draw(self);
self.1 = previous_area;
}
}
impl Deref for Tui { type Target = Buffer; fn deref (&self) -> &Buffer { &self.0 } }