mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
This commit is contained in:
parent
41ef62146b
commit
4172fa2577
13 changed files with 250 additions and 248 deletions
37
src/term.rs
37
src/term.rs
|
|
@ -97,13 +97,13 @@ impl Screen for Tui {
|
|||
self.into()
|
||||
}
|
||||
fn size <'a> (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Self>,
|
||||
) -> Drawn<'a, Self::Unit> {
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Self>,
|
||||
) -> Drawn<Self::Unit> {
|
||||
Self::Layout(self.area()).clip(area, &|to|draw.draw(to))
|
||||
}
|
||||
fn draw <'a> (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Tui>
|
||||
) -> Drawn<'a, Self::Unit> {
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Tui>
|
||||
) -> Drawn<Self::Unit> {
|
||||
self.clip(area, &|to|draw.draw(to))
|
||||
}
|
||||
fn clip <T> (
|
||||
|
|
@ -132,7 +132,7 @@ impl Tui {
|
|||
}));
|
||||
}
|
||||
pub fn run_main <T> (exit: Exit, state: Arc<RwLock<T>>) -> Usually<()> where
|
||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
||||
T: Draw<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static
|
||||
{
|
||||
let scan = Duration::from_millis(100);
|
||||
let frame = Duration::from_millis(10);
|
||||
|
|
@ -142,7 +142,7 @@ impl Tui {
|
|||
}
|
||||
/// Spawn the TUI input and output threadsl.
|
||||
pub fn io <
|
||||
T: View<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static,
|
||||
T: Draw<Tui> + Apply<TuiEvent, Usually<()>> + Send + Sync + 'static,
|
||||
W: Write + Send + Sync + 'static,
|
||||
> (
|
||||
exited: &Arc<AtomicBool>,
|
||||
|
|
@ -252,7 +252,8 @@ impl Tui {
|
|||
/// });
|
||||
/// ```
|
||||
pub fn output <
|
||||
W: Write + Send + Sync + 'static, T: View<Tui> + Send + Sync + 'static
|
||||
W: Write + Send + Sync + 'static,
|
||||
T: Draw<Tui> + Send + Sync + 'static
|
||||
> (
|
||||
exited: &Arc<AtomicBool>,
|
||||
state: &Arc<RwLock<T>>,
|
||||
|
|
@ -271,7 +272,7 @@ impl Tui {
|
|||
let Size { width, height } = backend.size().expect("get size failed");
|
||||
if let Ok(state) = state.try_read() {
|
||||
prev.resize(&mut backend, width, height);
|
||||
state.view().draw(&mut next).expect("draw failed"); // TODO draw error
|
||||
state.draw(&mut next).expect("draw failed"); // TODO draw error
|
||||
prev.redraw(&mut backend, &mut next);
|
||||
}
|
||||
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
|
||||
|
|
@ -289,7 +290,7 @@ impl Tui {
|
|||
/// let _ = tengri::Tui::catcher(&variant);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn catcher <'a, T: Draw<'a, Tui>> (result: &Usually<T>) -> impl Draw<'a, Tui> {
|
||||
pub fn catcher <'a, T: Draw<Tui>> (result: &Usually<T>) -> impl Draw<Tui> {
|
||||
draw(move|to: &mut Tui|match result {
|
||||
Ok(content) => content.draw(to),
|
||||
Err(e) => {
|
||||
|
|
@ -369,7 +370,7 @@ impl<'a: 'b, 'b> From<&'a mut Tui> for &'b mut XYWH<u16> {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> {
|
||||
pub const fn fill_char <'a> (c: char) -> impl Draw<Tui> {
|
||||
draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{
|
||||
cell.set_char(c);
|
||||
}))))
|
||||
|
|
@ -378,8 +379,8 @@ pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> {
|
|||
/// FIXME: Don't use `format!` but implement number blitting
|
||||
pub struct ShowSize;
|
||||
|
||||
impl<'a> Draw<'a, Tui> for ShowSize {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
impl<'a> Draw<Tui> for ShowSize {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
let area = to.area();
|
||||
let info = format!("{area:?}");
|
||||
to.text(&info, area.0, area.1, info.len() as u16)
|
||||
|
|
@ -388,8 +389,8 @@ impl<'a> Draw<'a, Tui> for ShowSize {
|
|||
|
||||
pub struct ShowSizeOf<T>(pub T);
|
||||
|
||||
impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
impl<'a, T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
Ok(self.0.draw(to)?.map(|used|{
|
||||
let _ = to.text(&format!("{used:?}"), used.0, used.1, u16::MAX);
|
||||
used
|
||||
|
|
@ -474,8 +475,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
|||
self.as_ref().draw(to)
|
||||
});
|
||||
|
||||
impl<'a> Draw<'a, Tui> for &str {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
impl<'a> Draw<Tui> for &str {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
let XYWH(x, y, w, h) = to.area();
|
||||
let mut max_w = 0u16;
|
||||
let mut max_h = 0u16;
|
||||
|
|
@ -494,8 +495,8 @@ impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: AsRef<str>> Draw<'a, Tui> for TrimStr<'a, T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
impl<'a, T: AsRef<str>> Draw<Tui> for TrimStr<'a, T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
let text = self.1.as_ref();
|
||||
let area = layout_text_u16(text, to.area())?.unwrap();
|
||||
let XYWH(x, y, w, ..) = to.area();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue