1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00
This commit is contained in:
Konkitoman
2023-09-01 11:52:00 +03:00
parent 52a63cabf9
commit 661120dc1d
28 changed files with 112 additions and 339 deletions

View File

@@ -9,7 +9,6 @@
#[cfg(not(target_arch = "wasm32"))]
mod icon_data;
use egui::ViewportRender;
#[cfg(not(target_arch = "wasm32"))]
pub use icon_data::IconData;
@@ -113,7 +112,7 @@ pub trait App {
/// The [`egui::Context`] can be cloned and saved if you like.
///
/// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread).
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame, render: Option<&ViewportRender>);
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame);
/// Get a handle to the app.
///
@@ -805,7 +804,7 @@ impl Frame {
/// struct MyApp;
///
/// impl eframe::App for MyApp {
/// fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame, _render: Option<&egui::ViewportRender>) {
/// fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
/// // In real code the app would render something here
/// frame.request_screenshot();
/// // Things that are added to the frame after the call to

View File

@@ -32,7 +32,7 @@
//! }
//!
//! impl eframe::App for MyEguiApp {
//! fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame, _render: Option<&egui::ViewportRender>) {
//! fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
//! egui::CentralPanel::default().show(ctx, |ui| {
//! ui.heading("Hello World!");
//! });
@@ -192,7 +192,7 @@ pub use native::file_storage::storage_dir;
/// }
///
/// impl eframe::App for MyEguiApp {
/// fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame, _render: Option<&egui::ViewportRender>) {
/// fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
/// egui::CentralPanel::default().show(ctx, |ui| {
/// ui.heading("Hello World!");
/// });
@@ -274,24 +274,13 @@ pub fn run_simple_native(
native_options: NativeOptions,
update_fun: impl FnMut(&egui::Context, &mut Frame) + 'static,
) -> Result<()> {
use egui::{ViewportId, ViewportRender};
struct SimpleApp<U> {
update_fun: U,
}
impl<U: FnMut(&egui::Context, &mut Frame)> App for SimpleApp<U> {
fn update(
&mut self,
ctx: &egui::Context,
frame: &mut Frame,
render: Option<&ViewportRender>,
) {
if ctx.get_viewport_id() == ViewportId::MAIN {
(self.update_fun)(ctx, frame);
} else if let Some(render_function) = render {
render_function(ctx);
}
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) {
(self.update_fun)(ctx, frame);
}
}

View File

@@ -502,7 +502,11 @@ impl EpiIntegration {
.egui_ctx
.run(raw_input, viewport_id, parent_id, |egui_ctx| {
crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r));
if let Some(render) = render {
render(egui_ctx);
} else {
app.update(egui_ctx, &mut self.frame);
}
});
self.pending_full_output.append(full_output);

View File

@@ -182,7 +182,7 @@ impl AppRunner {
let full_output =
self.egui_ctx
.run(raw_input, ViewportId::MAIN, ViewportId::MAIN, |egui_ctx| {
self.app.update(egui_ctx, &mut self.frame, None);
self.app.update(egui_ctx, &mut self.frame);
});
let egui::FullOutput {
platform_output,