0.16.1 patch release: Add back CtxRef::begin_frame/end_frame (#1019)

`begin_frame`, `end_frame` is more convenient when using egui in a game engine. In particular, 0.16.0 was incompatible with https://github.com/mvlabat/bevy_egui>.
This commit is contained in:
Emil Ernerfeldt 2021-12-31 11:45:57 +01:00 committed by GitHub
parent b00edfe97f
commit b5c119ef19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 7 deletions

View file

@ -14,6 +14,12 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* Renamed `Ui::visible` to `Ui::is_visible`. * 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 ## 0.16.0 - 2021-12-29 - Context menus and rich text
### Added ⭐ ### Added ⭐

2
Cargo.lock generated
View file

@ -790,7 +790,7 @@ dependencies = [
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.16.0" version = "0.16.1"
dependencies = [ dependencies = [
"ahash", "ahash",
"epaint", "epaint",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "egui" name = "egui"
version = "0.16.0" version = "0.16.1"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"] authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Simple, portable immediate mode GUI library for Rust" description = "Simple, portable immediate mode GUI library for Rust"
edition = "2021" edition = "2021"

View file

@ -99,19 +99,54 @@ impl CtxRef {
/// ///
/// This will modify the internal reference to point to a new generation of [`Context`]. /// 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. /// 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] #[must_use]
pub fn run( pub fn run(
&mut self, &mut self,
new_input: RawInput, new_input: RawInput,
run_ui: impl FnOnce(&CtxRef), run_ui: impl FnOnce(&CtxRef),
) -> (Output, Vec<ClippedShape>) { ) -> (Output, Vec<ClippedShape>) {
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(); let mut self_: Context = (*self.0).clone();
self_.begin_frame_mut(new_input); self_.begin_frame_mut(new_input);
*self = Self(Arc::new(self_)); *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. /// 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`]. /// You can transform the returned shapes into triangles with a call to [`Context::tessellate`].
#[must_use] #[must_use]
fn end_frame(&self) -> (Output, Vec<ClippedShape>) { pub fn end_frame(&self) -> (Output, Vec<ClippedShape>) {
if self.input.wants_repaint() { if self.input.wants_repaint() {
self.request_repaint(); self.request_repaint();
} }