mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
make Draw::clip take drawable instead of fn
This commit is contained in:
parent
cc4a428143
commit
4c25dcc702
9 changed files with 35 additions and 33 deletions
26
src/lib.rs
26
src/lib.rs
|
|
@ -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)
|
||||
}))?
|
||||
})))?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue