From 4358360d47e61953f6916311dfcffe76424838d1 Mon Sep 17 00:00:00 2001 From: Malik Olivier Boussejra Date: Thu, 29 Mar 2018 13:47:14 +0900 Subject: [PATCH] window_draw_list.rs: Wrap ImDrawList_PushClipRect This commit adds two methods to the drawing APIs: with_clip_rect and with_clip_rect_intersect. Both wrap ImDrawList_PushClipRect and ImDrawList_PopClipRect. However, with_clip_rect_intersect sets the `intersect` argument of ImDrawList_PushClipRect to `true`. --- src/window_draw_list.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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()) } + } } }; }