diff --git a/src/window_draw_list.rs b/src/window_draw_list.rs index 7cd3e25..271df1e 100644 --- a/src/window_draw_list.rs +++ b/src/window_draw_list.rs @@ -218,6 +218,41 @@ macro_rules! impl_draw_list_methods { { BezierCurve::new(self, pos0, cp0, cp1, pos1, color) } + + /// Push a clipping rectangle on the stack, run `f` and pop it. + /// + /// Clip all drawings done within the closure `f` in the given + /// rectangle. + pub fn with_clip_rect(&self, min: P1, max: P2, f: F) + where + P1: Into, + P2: Into, + F: FnOnce(), + { + unsafe { + sys::ImDrawList_PushClipRect(self.draw_list(), min.into(), max.into(), false) + } + f(); + unsafe { sys::ImDrawList_PopClipRect(self.draw_list()) } + } + + /// Push a clipping rectangle on the stack, run `f` and pop it. + /// + /// Clip all drawings done within the closure `f` in the given + /// rectangle. Intersect with all clipping rectangle previously on + /// the stack. + pub fn with_clip_rect_intersect(&self, min: P1, max: P2, f: F) + where + P1: Into, + P2: Into, + F: FnOnce(), + { + unsafe { + sys::ImDrawList_PushClipRect(self.draw_list(), min.into(), max.into(), true) + } + f(); + unsafe { sys::ImDrawList_PopClipRect(self.draw_list()) } + } } }; }