refactors and cleanups

This commit is contained in:
🪞👃🪞 2024-07-10 21:53:38 +03:00
parent 78afaf9693
commit 6979fd67ec
8 changed files with 126 additions and 173 deletions

View file

@ -20,14 +20,15 @@ pub fn fill_bg (buf: &mut Buffer, area: Rect, color: Color) {
pub trait Blit {
// Render something to X, Y coordinates in a buffer, ignoring width/height.
fn blit (&self, buf: &mut Buffer, x: u16, y: u16, style: Option<Style>);
fn blit (&self, buf: &mut Buffer, x: u16, y: u16, style: Option<Style>) -> Usually<Rect>;
}
impl<T: AsRef<str>> Blit for T {
fn blit (&self, buf: &mut Buffer, x: u16, y: u16, style: Option<Style>) {
fn blit (&self, buf: &mut Buffer, x: u16, y: u16, style: Option<Style>) -> Usually<Rect> {
if x < buf.area.width && y < buf.area.height {
buf.set_string(x, y, self.as_ref(), style.unwrap_or(Style::default()))
buf.set_string(x, y, self.as_ref(), style.unwrap_or(Style::default()));
}
Ok(Rect { x, y, width: self.as_ref().len() as u16, height: 1 })
}
}