mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-13 15:16:41 +01:00
rename Widget to Render and CustomWidget to Widget
This commit is contained in:
parent
f018988567
commit
bf3c7630a4
20 changed files with 144 additions and 144 deletions
|
|
@ -165,7 +165,7 @@ impl Output<Tui> for TuiOutput {
|
|||
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
|
||||
#[inline] fn render_in (&mut self,
|
||||
area: [u16;4],
|
||||
widget: &dyn Widget<Engine = Tui>
|
||||
widget: &dyn Render<Engine = Tui>
|
||||
) -> Usually<()> {
|
||||
let last = self.area();
|
||||
*self.area_mut() = area;
|
||||
|
|
@ -287,7 +287,7 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C
|
|||
}
|
||||
}
|
||||
}
|
||||
impl Widget for &str {
|
||||
impl Render for &str {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
// TODO: line breaks
|
||||
|
|
@ -299,7 +299,7 @@ impl Widget for &str {
|
|||
Ok(to.blit(&self, x, y, None))
|
||||
}
|
||||
}
|
||||
impl Widget for String {
|
||||
impl Render for String {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
// TODO: line breaks
|
||||
|
|
@ -311,7 +311,7 @@ impl Widget for String {
|
|||
Ok(to.blit(&self, x, y, None))
|
||||
}
|
||||
}
|
||||
impl<T: Widget<Engine = Tui>> Widget for DebugOverlay<Tui, T> {
|
||||
impl<T: Render<Engine = Tui>> Render for DebugOverlay<Tui, T> {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
self.0.min_size(to)
|
||||
|
|
@ -322,8 +322,8 @@ impl<T: Widget<Engine = Tui>> Widget for DebugOverlay<Tui, T> {
|
|||
Ok(to.blit(&format!("{w}x{h}+{x}+{y}"), x, y, Some(Style::default().green())))
|
||||
}
|
||||
}
|
||||
pub struct Styled<T: Widget<Engine = Tui>>(pub Option<Style>, pub T);
|
||||
impl Widget for Styled<&str> {
|
||||
pub struct Styled<T: Render<Engine = Tui>>(pub Option<Style>, pub T);
|
||||
impl Render for Styled<&str> {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
Ok(Some([self.1.chars().count() as u16, 1]))
|
||||
|
|
@ -335,41 +335,41 @@ impl Widget for Styled<&str> {
|
|||
Ok(to.blit(&self.1, x, y, None))
|
||||
}
|
||||
}
|
||||
pub trait TuiStyle: Widget<Engine = Tui> + Sized {
|
||||
fn fg (self, color: Color) -> impl Widget<Engine = Tui> {
|
||||
pub trait TuiStyle: Render<Engine = Tui> + Sized {
|
||||
fn fg (self, color: Color) -> impl Render<Engine = Tui> {
|
||||
Layers::new(move |add|{ add(&Foreground(color))?; add(&self) })
|
||||
}
|
||||
fn bg (self, color: Color) -> impl Widget<Engine = Tui> {
|
||||
fn bg (self, color: Color) -> impl Render<Engine = Tui> {
|
||||
Layers::new(move |add|{ add(&Background(color))?; add(&self) })
|
||||
}
|
||||
fn bold (self, on: bool) -> impl Widget<Engine = Tui> {
|
||||
fn bold (self, on: bool) -> impl Render<Engine = Tui> {
|
||||
Layers::new(move |add|{ add(&Bold(on))?; add(&self) })
|
||||
}
|
||||
fn border (self, style: impl BorderStyle) -> impl Widget<Engine = Tui> {
|
||||
fn border (self, style: impl BorderStyle) -> impl Render<Engine = Tui> {
|
||||
Bordered(style, self)
|
||||
}
|
||||
}
|
||||
impl<W: Widget<Engine = Tui>> TuiStyle for W {}
|
||||
impl<W: Render<Engine = Tui>> TuiStyle for W {}
|
||||
pub struct Bold(pub bool);
|
||||
impl Widget for Bold {
|
||||
impl Render for Bold {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
|
||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bold(to.area(), self.0)) }
|
||||
}
|
||||
pub struct Foreground(pub Color);
|
||||
impl Widget for Foreground {
|
||||
impl Render for Foreground {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
|
||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_fg(to.area(), self.0)) }
|
||||
}
|
||||
pub struct Background(pub Color);
|
||||
impl Widget for Background {
|
||||
impl Render for Background {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
|
||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bg(to.area(), self.0)) }
|
||||
}
|
||||
pub struct Border<S: BorderStyle>(pub S);
|
||||
impl<S: BorderStyle> Widget for Border<S> {
|
||||
impl<S: BorderStyle> Render for Border<S> {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
Ok(Some([0, 0]))
|
||||
|
|
@ -393,11 +393,11 @@ impl<S: BorderStyle> Widget for Border<S> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct Bordered<S: BorderStyle, W: Widget<Engine = Tui>>(pub S, pub W);
|
||||
impl<S: BorderStyle, W: Widget<Engine = Tui>> Content for Bordered<S, W> {
|
||||
pub struct Bordered<S: BorderStyle, W: Render<Engine = Tui>>(pub S, pub W);
|
||||
impl<S: BorderStyle, W: Render<Engine = Tui>> Content for Bordered<S, W> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let content: &dyn Widget<Engine = Tui> = &self.1;
|
||||
fn content (&self) -> impl Render<Engine = Tui> {
|
||||
let content: &dyn Render<Engine = Tui> = &self.1;
|
||||
lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy()
|
||||
}
|
||||
}
|
||||
|
|
@ -497,7 +497,7 @@ macro_rules! border {
|
|||
}
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct $T(pub Style);
|
||||
impl Widget for $T {
|
||||
impl Render for $T {
|
||||
type Engine = Tui;
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
|
||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> { self.draw(to) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue