mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
A lot of changes:
Now the Viewport render function is passed to the backend I was needed to update the demo because now Window::show() needs a Fn before was a FnOnce I changed from FnOnce to Fn because we want the window to be rendered separately from the main window That means now the variabiles that we are moving to window need to be Rc or Arc! This is making harder to use `Window`! I'am waiting for more ideas! In eframe now any Window has a property render that stores the current window render function, if has not function App::update will be called insted! New problems in any other window excluding the main window we have no mouse input, i don't know why! Now every window has embedded to false by default, for testing purposes!
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::time::Instant;
|
||||
use std::{sync::Arc, time::Instant};
|
||||
|
||||
use winit::event_loop::EventLoopWindowTarget;
|
||||
|
||||
@@ -9,7 +9,7 @@ use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
use egui::accesskit;
|
||||
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, NumExt as _};
|
||||
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, Context, NumExt as _};
|
||||
#[cfg(feature = "accesskit")]
|
||||
use egui_winit::accesskit_winit;
|
||||
use egui_winit::{native_pixels_per_point, EventResponse, WindowSettings};
|
||||
@@ -432,7 +432,7 @@ impl EpiIntegration {
|
||||
let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone());
|
||||
self.egui_ctx
|
||||
.memory_mut(|mem| mem.set_everything_is_visible(true));
|
||||
let full_output = self.update(app, window, egui_winit);
|
||||
let full_output = self.update(app, window, egui_winit, None);
|
||||
self.pending_full_output.append(full_output); // Handle it next frame
|
||||
self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge.
|
||||
self.egui_ctx.clear_animations();
|
||||
@@ -496,6 +496,7 @@ impl EpiIntegration {
|
||||
app: &mut dyn epi::App,
|
||||
window: &winit::window::Window,
|
||||
egui_winit: &mut egui_winit::State,
|
||||
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
|
||||
) -> egui::FullOutput {
|
||||
let frame_start = std::time::Instant::now();
|
||||
|
||||
@@ -509,7 +510,11 @@ impl EpiIntegration {
|
||||
// Run user code:
|
||||
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||
crate::profile_scope!("App::update");
|
||||
app.update(egui_ctx, &mut self.frame);
|
||||
if let Some(render) = render {
|
||||
(render.as_ref())(egui_ctx)
|
||||
} else {
|
||||
app.update(egui_ctx, &mut self.frame);
|
||||
}
|
||||
});
|
||||
|
||||
self.pending_full_output.append(full_output);
|
||||
|
||||
@@ -411,7 +411,7 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
|
||||
mod glow_integration {
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, NumExt as _};
|
||||
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, Context, NumExt as _};
|
||||
use egui_winit::EventResponse;
|
||||
use glow::HasContext;
|
||||
use glutin::{
|
||||
@@ -454,6 +454,7 @@ mod glow_integration {
|
||||
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
|
||||
window: Option<winit::window::Window>,
|
||||
window_id: u64,
|
||||
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
|
||||
pub egui_winit: Option<egui_winit::State>,
|
||||
}
|
||||
/// This struct will contain both persistent and temporary glutin state.
|
||||
@@ -601,6 +602,7 @@ mod glow_integration {
|
||||
window,
|
||||
window_id: 0,
|
||||
egui_winit: None,
|
||||
render: None,
|
||||
}],
|
||||
window_maps,
|
||||
})
|
||||
@@ -1049,6 +1051,7 @@ mod glow_integration {
|
||||
app.as_mut(),
|
||||
win.window.as_ref().unwrap(),
|
||||
win.egui_winit.as_mut().unwrap(),
|
||||
win.render.clone(),
|
||||
);
|
||||
|
||||
integration.handle_platform_output(
|
||||
@@ -1153,7 +1156,7 @@ mod glow_integration {
|
||||
// 0 is the main viewport/window that will not be known by the egui_ctx
|
||||
let mut active_viewports_ids = vec![0];
|
||||
|
||||
viewports.retain_mut(|(id, builder)| {
|
||||
viewports.retain_mut(|(id, builder, render)| {
|
||||
for w in gl_window.windows.iter_mut() {
|
||||
if w.window_id == *id {
|
||||
if w.builder != *builder {
|
||||
@@ -1164,7 +1167,7 @@ mod glow_integration {
|
||||
}
|
||||
w.window = None;
|
||||
w.gl_surface = None;
|
||||
|
||||
w.render = Some(render.clone());
|
||||
w.builder = builder.clone();
|
||||
}
|
||||
active_viewports_ids.push(*id);
|
||||
@@ -1174,13 +1177,14 @@ mod glow_integration {
|
||||
true
|
||||
});
|
||||
|
||||
for (id, builder) in viewports {
|
||||
for (id, builder, render) in viewports {
|
||||
gl_window.windows.push(Window {
|
||||
builder,
|
||||
gl_surface: None,
|
||||
window: None,
|
||||
window_id: id,
|
||||
egui_winit: None,
|
||||
render: Some(render.clone()),
|
||||
});
|
||||
active_viewports_ids.push(id);
|
||||
}
|
||||
@@ -1234,7 +1238,7 @@ mod glow_integration {
|
||||
|
||||
winit::event::Event::MainEventsCleared => {
|
||||
if let Some(running) = self.running.as_mut() {
|
||||
running.gl_window.on_resume(event_loop);
|
||||
let _ = running.gl_window.on_resume(event_loop);
|
||||
}
|
||||
EventResult::Wait
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user