From 5bdd4f819cfff86e714c1909f42f05e1f11df0e9 Mon Sep 17 00:00:00 2001 From: Jack Mac Date: Tue, 28 Sep 2021 11:27:14 -0400 Subject: [PATCH] added end frame handle --- imgui/src/context.rs | 9 +++------ imgui/src/lib.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/imgui/src/context.rs b/imgui/src/context.rs index 3acda71..c1a891e 100644 --- a/imgui/src/context.rs +++ b/imgui/src/context.rs @@ -505,17 +505,14 @@ impl Context { unsafe { &mut *(self.io_mut().fonts as *mut FontAtlas) } } - /// Starts a new frame. + /// Starts a new frame. Use [`new_frame`] instead. + /// + /// [`new_frame`]: Self::new_frame pub fn frame(&mut self) -> &mut Ui { self.new_frame() } /// Starts a new frame and returns an `Ui` instance for constructing a user interface. - /// - /// # Panics - /// - /// Panics if the context uses a shared font atlas that is already borrowed. - /// Do not attempt to borrow the context afterwards, if you are using a shared font atlas. #[doc(alias = "NewFame")] pub fn new_frame(&mut self) -> &mut Ui { // Clear default font if it no longer exists. This could be an error in the future diff --git a/imgui/src/lib.rs b/imgui/src/lib.rs index ef2cb3b..dc126d5 100644 --- a/imgui/src/lib.rs +++ b/imgui/src/lib.rs @@ -119,7 +119,7 @@ impl Context { /// A reference for building the user interface for one frame #[derive(Debug)] pub struct Ui { - // our scratch sheet + /// our scratch sheet buffer: cell::UnsafeCell, } @@ -189,10 +189,36 @@ impl Ui { pub fn fonts(&self) -> &FontAtlas { unsafe { &*(self.io().fonts as *const FontAtlas) } } + /// Returns a clone of the user interface style pub fn clone_style(&self) -> Style { unsafe { *self.style() } } + + /// This function, and the library's api, has been changed as of `0.9`! + /// Do not use this function! Instead, use [`Context::render`], + /// which does what this function in `0.8` used to do. + /// + /// This function right now simply **ends** the current frame, but does not + /// return draw data. If you want to end the frame without generated draw data, + /// and thus save some CPU time, use [`end_frame_early`]. + #[deprecated( + since = "0.9.0", + note = "use `Context::render` to render frames, or `end_frame_early` to not render at all" + )] + pub fn render(&mut self) { + self.end_frame_early(); + } + + /// Use this function to end the frame early. + /// After this call, you should **stop using the `Ui` object till `new_frame` has been called.** + /// + /// You probably *don't want this function.* If you want to render your data, use `Context::render` now. + pub fn end_frame_early(&mut self) { + unsafe { + sys::igEndFrame(); + } + } } /// # Demo, debug, information