mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
This commit is contained in:
parent
20517f09b4
commit
a9f2fa2cdd
17 changed files with 655 additions and 491 deletions
47
src/term.rs
47
src/term.rs
|
|
@ -96,14 +96,14 @@ impl Screen for Tui {
|
|||
fn area (&self) -> XYWH<Self::Unit> {
|
||||
self.into()
|
||||
}
|
||||
fn size (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Self>,
|
||||
) -> Perhaps<XYWH<Self::Unit>> {
|
||||
fn size <'a> (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Self>,
|
||||
) -> Drawn<'a, Self::Unit> {
|
||||
Self::Layout(self.area()).clip(area, &|to|draw.draw(to))
|
||||
}
|
||||
fn draw (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<Tui>
|
||||
) -> Perhaps<XYWH<Self::Unit>> {
|
||||
fn draw <'a> (
|
||||
&mut self, area: impl Into<Option<XYWH<u16>>>, draw: impl Draw<'a, Tui>
|
||||
) -> Drawn<'a, Self::Unit> {
|
||||
self.clip(area, &|to|draw.draw(to))
|
||||
}
|
||||
fn clip <T> (
|
||||
|
|
@ -289,7 +289,7 @@ impl Tui {
|
|||
/// let _ = tengri::Tui::catcher(&variant);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn catcher <T: Draw<Tui>> (result: &Usually<T>) -> impl Draw<Tui> {
|
||||
pub fn catcher <'a, T: Draw<'a, Tui>> (result: &Usually<T>) -> impl Draw<'a, Tui> {
|
||||
draw(move|to: &mut Tui|match result {
|
||||
Ok(content) => content.draw(to),
|
||||
Err(e) => {
|
||||
|
|
@ -369,7 +369,7 @@ impl<'a: 'b, 'b> From<&'a mut Tui> for &'b mut XYWH<u16> {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn fill_char (c: char) -> impl Draw<Tui> {
|
||||
pub const fn fill_char <'a> (c: char) -> impl Draw<'a, Tui> {
|
||||
draw(move|to: &mut Tui|Ok(Some(to.update(&|cell,_,_|{
|
||||
cell.set_char(c);
|
||||
}))))
|
||||
|
|
@ -378,8 +378,8 @@ pub const fn fill_char (c: char) -> impl Draw<Tui> {
|
|||
/// FIXME: Don't use `format!` but implement number blitting
|
||||
pub struct ShowSize;
|
||||
|
||||
impl Draw<Tui> for ShowSize {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
impl<'a> Draw<'a, Tui> for ShowSize {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
let area = to.area();
|
||||
let info = format!("{area:?}");
|
||||
to.text(&info, area.0, area.1, info.len() as u16)
|
||||
|
|
@ -388,8 +388,8 @@ impl Draw<Tui> for ShowSize {
|
|||
|
||||
pub struct ShowSizeOf<T>(pub T);
|
||||
|
||||
impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
impl<'a, T: Draw<'a, Tui>> Draw<'a, Tui> for ShowSizeOf<T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
Ok(self.0.draw(to)?.map(|used|{
|
||||
let _ = to.text(&format!("{used:?}"), used.0, used.1, u16::MAX);
|
||||
used
|
||||
|
|
@ -398,13 +398,14 @@ impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "eval")] fn_kw_layout_tui!(kw_tui_text |_state, output, expr| {
|
||||
Ok(matches!(expr.head()?, Some("text")).then(||{
|
||||
if let Some(src) = expr.tail().src()? && src.len() > 0 {
|
||||
(&src[1..]).draw(output)
|
||||
} else {
|
||||
return Ok(None)
|
||||
}
|
||||
}).transpose()?.flatten())
|
||||
Ok(if matches!(expr.head()?, Some("text")) {
|
||||
expr.tail()?
|
||||
.and_then(|src|(src.len() > 0).then(||(&src[1..]).draw(output)))
|
||||
.transpose()?
|
||||
.flatten()
|
||||
} else {
|
||||
None
|
||||
})
|
||||
});
|
||||
|
||||
#[cfg(feature = "text")] pub use self::tui_text::*;
|
||||
|
|
@ -473,8 +474,8 @@ impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
|||
self.as_ref().draw(to)
|
||||
});
|
||||
|
||||
impl Draw<Tui> for &str {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
impl<'a> Draw<'a, Tui> for &str {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, u16> {
|
||||
let XYWH(x, y, w, h) = to.area();
|
||||
let mut max_w = 0u16;
|
||||
let mut max_h = 0u16;
|
||||
|
|
@ -493,8 +494,8 @@ impl<T: Draw<Tui>> Draw<Tui> for ShowSizeOf<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'t, T: AsRef<str>> Draw<Tui> for TrimStr<'_, T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<u16> {
|
||||
impl<'a, T: AsRef<str>> Draw<'a, Tui> for TrimStr<'a, T> {
|
||||
fn draw (&self, to: &mut Tui) -> Drawn<'a, 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