diff --git a/CHANGELOG.md b/CHANGELOG.md index 5efc7208..ab5175d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * Renamed `Ui::visible` to `Ui::is_visible`. +## 0.16.1 - 2021-12-31 - Add back `CtxRef::begin_frame,end_frame` + +### Added ⭐ +* Add back `CtxRef::begin_frame,end_frame` as an alternative to `CtxRef::run`. + + ## 0.16.0 - 2021-12-29 - Context menus and rich text ### Added ⭐ diff --git a/Cargo.lock b/Cargo.lock index aabc330b..b120706b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -790,7 +790,7 @@ dependencies = [ [[package]] name = "egui" -version = "0.16.0" +version = "0.16.1" dependencies = [ "ahash", "epaint", diff --git a/egui/Cargo.toml b/egui/Cargo.toml index bdc368ca..6f9ed8b2 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui" -version = "0.16.0" +version = "0.16.1" authors = ["Emil Ernerfeldt "] description = "Simple, portable immediate mode GUI library for Rust" edition = "2021" diff --git a/egui/src/context.rs b/egui/src/context.rs index f61f63f1..27a454f8 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -99,19 +99,54 @@ impl CtxRef { /// /// This will modify the internal reference to point to a new generation of [`Context`]. /// Any old clones of this [`CtxRef`] will refer to the old [`Context`], which will not get new input. + /// + /// You can alternatively run [`Self::begin_single_pass_frame`] and [`Self::end_single_pass_frame`]. + /// + /// ``` rust + /// // One egui context that you keep reusing: + /// let mut ctx = egui::CtxRef::default(); + /// + /// // Each frame: + /// let input = egui::RawInput::default(); + /// let (output, shapes) = ctx.run(input, |ctx| { + /// egui::CentralPanel::default().show(&ctx, |ui| { + /// ui.label("Hello egui!"); + /// }); + /// }); + /// // handle output, paint shapes + /// ``` #[must_use] pub fn run( &mut self, new_input: RawInput, run_ui: impl FnOnce(&CtxRef), ) -> (Output, Vec) { + self.begin_frame(new_input); + run_ui(self); + self.end_frame() + } + + /// An alternative to calling [`Self::run`]. + /// + /// ``` rust + /// // One egui context that you keep reusing: + /// let mut ctx = egui::CtxRef::default(); + /// + /// // Each frame: + /// let input = egui::RawInput::default(); + /// ctx.begin_frame(input); + /// + /// egui::CentralPanel::default().show(&ctx, |ui| { + /// ui.label("Hello egui!"); + /// }); + /// + /// let (output, shapes) = ctx.end_frame(); + /// // handle output, paint shapes + /// ``` + pub fn begin_frame(&mut self, new_input: RawInput) { let mut self_: Context = (*self.0).clone(); self_.begin_frame_mut(new_input); *self = Self(Arc::new(self_)); - - run_ui(self); - - self.end_frame() } // --------------------------------------------------------------------- @@ -625,7 +660,7 @@ impl Context { /// Returns what has happened this frame [`crate::Output`] as well as what you need to paint. /// You can transform the returned shapes into triangles with a call to [`Context::tessellate`]. #[must_use] - fn end_frame(&self) -> (Output, Vec) { + pub fn end_frame(&self) -> (Output, Vec) { if self.input.wants_repaint() { self.request_repaint(); }