make Draw::clip take drawable instead of fn

This commit is contained in:
facile pop culture reference 2026-08-03 11:40:43 +03:00
parent cc4a428143
commit 4c25dcc702
9 changed files with 35 additions and 33 deletions

View file

@ -1366,12 +1366,12 @@ macro_rules! eval_xy (
/// fn area (&self) -> XYWH<Self::Unit> {
/// Default::default()
/// }
/// fn clip <T> (
/// fn clip (
/// &mut self,
/// area: impl Into<Option<XYWH<u16>>>,
/// draw: impl FnOnce(&mut Self)->T
/// ) -> T {
/// draw(self)
/// draw: impl Draw<Self>
/// ) -> Perhaps<XYWH<Self::Unit>> {
/// draw.to(self)
/// }
/// }
///
@ -1387,11 +1387,11 @@ macro_rules! eval_xy (
/// Get current clipping area
fn area (&self) -> XYWH<Self::Unit>;
/// Set clipping area
fn clip <T> (
fn clip (
&mut self,
area: impl Into<Option<XYWH<Self::Unit>>>,
draw: impl FnOnce(&mut Self)->T
) -> T;
draw: impl Draw<Self>
) -> Perhaps<XYWH<Self::Unit>>;
}
/// Implement the [Draw] trait for a particular drawable and [Screen].
@ -2645,16 +2645,16 @@ macro_rules! eval_xy (
}
}
fn clip <T> (
fn clip (
&mut self,
area: impl Into<Option<XYWH<u16>>>,
draw: impl FnOnce(&mut Self)->T
) -> T {
draw: impl Draw<Self>
) -> Perhaps<XYWH<Self::Unit>> {
let prev = self.area();
if let Some(area) = area.into() {
*self.area_mut() = area.into();
}
let result = draw(self);
let result = draw.draw(self);
*self.area_mut() = prev;
result
}
@ -2815,10 +2815,10 @@ macro_rules! eval_xy (
self.1.layout(area)
}
fn draw (self, to: &mut Tui) -> Drawn<u16> {
self.layout(to.area()).map(|area|to.clip(area, |to|{
self.layout(to.area()).map(|area|to.clip(area, draw(|to: &mut Tui|{
to.update(&|cell,_,_|{ cell.set_bg(self.0); });
self.1.draw(to)
}))?
})))?
}
}