mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Simplify
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user