wip: return () from render method, pt.2

This commit is contained in:
🪞👃🪞 2024-09-15 17:14:15 +03:00
parent e3fa292a3c
commit bb7d215ba1

View file

@ -453,12 +453,11 @@ where
Ok(Some([w, h]))
}
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
self.layout(to.area().wh())?
.map(|size|(self.0)(&mut |layer|{
to.render_in(to.area().clip(size), &layer).map(|_|())
})
.map(|_|to.area()))
.transpose()
if let Some(size) = self.layout(to.area().wh())? {
(self.0)(&mut |layer|to.render_in(to.area().clip(size), &layer))
} else {
Ok(())
}
}
}
@ -472,20 +471,20 @@ impl<S: BorderStyle> Widget for Border<S> {
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let area = to.area();
if area.w() > 2 && area.y() > 2 {
to.blit(&self.0.nw(), area.x(), area.y(), self.0.style())?;
to.blit(&self.0.ne(), area.x() + area.w() - 1, area.y(), self.0.style())?;
to.blit(&self.0.sw(), area.x(), area.y() + area.h() - 1, self.0.style())?;
to.blit(&self.0.se(), area.x() + area.w() - 1, area.y() + area.h() - 1, self.0.style())?;
to.blit(&self.0.nw(), area.x(), area.y(), self.0.style());
to.blit(&self.0.ne(), area.x() + area.w() - 1, area.y(), self.0.style());
to.blit(&self.0.sw(), area.x(), area.y() + area.h() - 1, self.0.style());
to.blit(&self.0.se(), area.x() + area.w() - 1, area.y() + area.h() - 1, self.0.style());
for x in area.x()+1..area.x()+area.w()-1 {
to.blit(&self.0.n(), x, area.y(), self.0.style())?;
to.blit(&self.0.s(), x, area.y() + area.h() - 1, self.0.style())?;
to.blit(&self.0.n(), x, area.y(), self.0.style());
to.blit(&self.0.s(), x, area.y() + area.h() - 1, self.0.style());
}
for y in area.y()+1..area.y()+area.h()-1 {
to.blit(&self.0.w(), area.x(), y, self.0.style())?;
to.blit(&self.0.e(), area.x() + area.w() - 1, y, self.0.style())?;
to.blit(&self.0.w(), area.x(), y, self.0.style());
to.blit(&self.0.e(), area.x() + area.w() - 1, y, self.0.style());
}
}
Ok(Some(area))
Ok(())
}
}
@ -529,7 +528,7 @@ pub trait BorderStyle: Send + Sync {
self.draw_horizontal(to, None)?;
self.draw_vertical(to, None)?;
self.draw_corners(to, None)?;
Ok(Some(to.area))
Ok(())
}
#[inline]
@ -538,17 +537,17 @@ pub trait BorderStyle: Send + Sync {
let style = style.or_else(||self.style_horizontal());
let [x, x2, y, y2] = area.lrtb();
for x in x..x2.saturating_sub(1) {
self.draw_north(to, x, y, style)?;
self.draw_south(to, x, y2.saturating_sub(1), style)?;
self.draw_north(to, x, y, style);
self.draw_south(to, x, y2.saturating_sub(1), style);
}
Ok(area)
}
#[inline]
fn draw_north (&self, to: &mut TuiOutput, x: u16, y: u16, style: Option<Style>) -> Usually<()> {
fn draw_north (&self, to: &mut TuiOutput, x: u16, y: u16, style: Option<Style>) -> () {
to.blit(&Self::N, x, y, style)
}
#[inline]
fn draw_south (&self, to: &mut TuiOutput, x: u16, y: u16, style: Option<Style>) -> Usually<()> {
fn draw_south (&self, to: &mut TuiOutput, x: u16, y: u16, style: Option<Style>) -> () {
to.blit(&Self::S, x, y, style)
}
@ -558,8 +557,8 @@ pub trait BorderStyle: Send + Sync {
let style = style.or_else(||self.style_vertical());
let [x, x2, y, y2] = area.lrtb();
for y in y..y2.saturating_sub(1) {
to.blit(&Self::W, x, y, style)?;
to.blit(&Self::E, x2.saturating_sub(1), y, style)?;
to.blit(&Self::W, x, y, style);
to.blit(&Self::E, x2.saturating_sub(1), y, style);
}
Ok(area)
}
@ -570,10 +569,10 @@ pub trait BorderStyle: Send + Sync {
let style = style.or_else(||self.style_corners());
let [x, y, width, height] = area.xywh();
if width > 0 && height > 0 {
to.blit(&Self::NW, x, y, style)?;
to.blit(&Self::NE, x + width - 1, y, style)?;
to.blit(&Self::SW, x, y + height - 1, style)?;
to.blit(&Self::SE, x + width - 1, y + height - 1, style)?;
to.blit(&Self::NW, x, y, style);
to.blit(&Self::NE, x + width - 1, y, style);
to.blit(&Self::SW, x, y + height - 1, style);
to.blit(&Self::SE, x + width - 1, y + height - 1, style);
}
Ok(area)
}