mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
output: more big refactors
This commit is contained in:
parent
194f2f9874
commit
5e6338fad8
68 changed files with 1604 additions and 1016 deletions
|
|
@ -2,12 +2,14 @@ use crate::*;
|
|||
use std::time::Duration;
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
use unicode_width::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TuiOut {
|
||||
pub buffer: Buffer,
|
||||
pub area: [u16;4]
|
||||
}
|
||||
impl Output for TuiOut {
|
||||
|
||||
impl Out for TuiOut {
|
||||
type Unit = u16;
|
||||
type Size = [Self::Unit;2];
|
||||
type Area = [Self::Unit;4];
|
||||
|
|
@ -17,16 +19,20 @@ impl Output for TuiOut {
|
|||
#[inline] fn area_mut (&mut self) -> &mut [u16;4] {
|
||||
&mut self.area
|
||||
}
|
||||
#[inline] fn place <'t, T: Render<Self> + ?Sized> (&mut self, area: [u16;4], content: &'t T) {
|
||||
#[inline] fn place_at <'t, T: Draw<Self> + ?Sized> (&mut self, area: [u16;4], content: &'t T) {
|
||||
let last = self.area();
|
||||
*self.area_mut() = area;
|
||||
content.render(self);
|
||||
content.draw(self);
|
||||
*self.area_mut() = last;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Layout<TuiOut> for fn(&mut TuiOut) {}
|
||||
|
||||
impl TuiOut {
|
||||
/// Spawn the output thread.
|
||||
pub fn run_output <T: Render<TuiOut> + Send + Sync + 'static> (
|
||||
pub fn run_output <T: Draw<TuiOut> + Send + Sync + 'static> (
|
||||
engine: &Arc<RwLock<Tui>>,
|
||||
state: &Arc<RwLock<T>>,
|
||||
timer: Duration
|
||||
|
|
@ -52,7 +58,7 @@ impl TuiOut {
|
|||
buffer.reset();
|
||||
}
|
||||
let mut output = TuiOut { buffer, area: [0, 0, width, height] };
|
||||
state.render(&mut output);
|
||||
state.draw(&mut output);
|
||||
buffer = engine.write().unwrap().flip(output.buffer, size);
|
||||
}
|
||||
//let t1 = engine.read().unwrap().perf.get_t1(t0).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue