mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-19 01:18:27 +00:00
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`.
This commit is contained in:
parent
35db5fca72
commit
4358360d47
@ -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<P1, P2, F>(&self, min: P1, max: P2, f: F)
|
||||
where
|
||||
P1: Into<ImVec2>,
|
||||
P2: Into<ImVec2>,
|
||||
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<P1, P2, F>(&self, min: P1, max: P2, f: F)
|
||||
where
|
||||
P1: Into<ImVec2>,
|
||||
P2: Into<ImVec2>,
|
||||
F: FnOnce(),
|
||||
{
|
||||
unsafe {
|
||||
sys::ImDrawList_PushClipRect(self.draw_list(), min.into(), max.into(), true)
|
||||
}
|
||||
f();
|
||||
unsafe { sys::ImDrawList_PopClipRect(self.draw_list()) }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user