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:
parent
b00edfe97f
commit
b5c119ef19
4 changed files with 48 additions and 7 deletions
|
@ -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 ⭐
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -790,7 +790,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.16.0"
|
||||
version = "0.16.1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"epaint",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "egui"
|
||||
version = "0.16.0"
|
||||
version = "0.16.1"
|
||||
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||
description = "Simple, portable immediate mode GUI library for Rust"
|
||||
edition = "2021"
|
||||
|
|
|
@ -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<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();
|
||||
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<ClippedShape>) {
|
||||
pub fn end_frame(&self) -> (Output, Vec<ClippedShape>) {
|
||||
if self.input.wants_repaint() {
|
||||
self.request_repaint();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue