2021-01-04 00:44:02 +00:00
|
|
|
use crate::{window_settings::WindowSettings, *};
|
|
|
|
use egui::Color32;
|
2021-04-19 20:49:28 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
use glium::glutin::platform::windows::WindowBuilderExtWindows;
|
2020-07-22 16:46:12 +00:00
|
|
|
use std::time::Instant;
|
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
2020-07-22 16:46:12 +00:00
|
|
|
const EGUI_MEMORY_KEY: &str = "egui";
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
2020-07-22 16:46:12 +00:00
|
|
|
const WINDOW_KEY: &str = "window";
|
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
|
|
|
fn deserialize_window_settings(storage: &Option<Box<dyn epi::Storage>>) -> Option<WindowSettings> {
|
|
|
|
epi::get_value(&**storage.as_ref()?, WINDOW_KEY)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "persistence"))]
|
|
|
|
fn deserialize_window_settings(_: &Option<Box<dyn epi::Storage>>) -> Option<WindowSettings> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "persistence")]
|
|
|
|
fn deserialize_memory(storage: &Option<Box<dyn epi::Storage>>) -> Option<egui::Memory> {
|
|
|
|
epi::get_value(&**storage.as_ref()?, EGUI_MEMORY_KEY)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "persistence"))]
|
|
|
|
fn deserialize_memory(_: &Option<Box<dyn epi::Storage>>) -> Option<egui::Memory> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2020-12-29 13:15:46 +00:00
|
|
|
impl epi::TextureAllocator for Painter {
|
2021-01-07 15:29:58 +00:00
|
|
|
fn alloc_srgba_premultiplied(
|
2020-09-11 06:56:47 +00:00
|
|
|
&mut self,
|
|
|
|
size: (usize, usize),
|
2021-01-02 16:02:18 +00:00
|
|
|
srgba_pixels: &[Color32],
|
2021-01-07 15:29:58 +00:00
|
|
|
) -> egui::TextureId {
|
|
|
|
let id = self.alloc_user_texture();
|
2020-11-18 20:38:29 +00:00
|
|
|
self.set_user_texture(id, size, srgba_pixels);
|
2021-01-07 15:29:58 +00:00
|
|
|
id
|
2020-11-18 20:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn free(&mut self, id: egui::TextureId) {
|
|
|
|
self.free_user_texture(id)
|
2020-09-11 06:56:47 +00:00
|
|
|
}
|
2020-07-22 16:46:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:35:16 +00:00
|
|
|
struct RequestRepaintEvent;
|
|
|
|
|
2020-12-27 09:49:26 +00:00
|
|
|
struct GliumRepaintSignal(
|
|
|
|
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
|
|
|
);
|
2020-11-20 19:35:16 +00:00
|
|
|
|
2020-12-29 13:15:46 +00:00
|
|
|
impl epi::RepaintSignal for GliumRepaintSignal {
|
2020-11-20 19:35:16 +00:00
|
|
|
fn request_repaint(&self) {
|
2020-12-27 09:49:26 +00:00
|
|
|
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
|
2020-11-20 19:35:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-19 20:49:28 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
fn window_builder_drag_and_drop(
|
|
|
|
window_builder: glutin::window::WindowBuilder,
|
|
|
|
enable: bool,
|
|
|
|
) -> glutin::window::WindowBuilder {
|
|
|
|
window_builder.with_drag_and_drop(enable)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
fn window_builder_drag_and_drop(
|
|
|
|
window_builder: glutin::window::WindowBuilder,
|
|
|
|
_enable: bool,
|
|
|
|
) -> glutin::window::WindowBuilder {
|
|
|
|
// drag and drop can only be disabled on windows
|
|
|
|
window_builder
|
|
|
|
}
|
|
|
|
|
2020-10-24 16:49:44 +00:00
|
|
|
fn create_display(
|
2021-03-31 18:53:13 +00:00
|
|
|
app: &dyn epi::App,
|
2021-05-08 08:14:56 +00:00
|
|
|
native_options: &epi::NativeOptions,
|
2020-10-24 16:49:44 +00:00
|
|
|
window_settings: Option<WindowSettings>,
|
2021-02-26 14:59:30 +00:00
|
|
|
window_icon: Option<glutin::window::Icon>,
|
2020-11-20 19:35:16 +00:00
|
|
|
event_loop: &glutin::event_loop::EventLoop<RequestRepaintEvent>,
|
2020-10-24 16:49:44 +00:00
|
|
|
) -> glium::Display {
|
|
|
|
let mut window_builder = glutin::window::WindowBuilder::new()
|
2021-05-08 08:19:47 +00:00
|
|
|
.with_always_on_top(native_options.always_on_top)
|
2021-08-25 16:20:53 +00:00
|
|
|
.with_maximized(native_options.maximized)
|
2021-05-08 08:14:56 +00:00
|
|
|
.with_decorations(native_options.decorated)
|
|
|
|
.with_resizable(native_options.resizable)
|
2021-03-31 18:53:13 +00:00
|
|
|
.with_title(app.name())
|
2021-05-08 08:19:47 +00:00
|
|
|
.with_transparent(native_options.transparent)
|
|
|
|
.with_window_icon(window_icon);
|
2021-03-31 18:53:13 +00:00
|
|
|
|
2021-05-08 08:14:56 +00:00
|
|
|
window_builder =
|
|
|
|
window_builder_drag_and_drop(window_builder, native_options.drag_and_drop_support);
|
2021-04-19 20:49:28 +00:00
|
|
|
|
2021-05-08 08:14:56 +00:00
|
|
|
let initial_size_points = native_options.initial_window_size;
|
2020-07-22 16:46:12 +00:00
|
|
|
|
|
|
|
if let Some(window_settings) = &window_settings {
|
2020-10-24 16:49:44 +00:00
|
|
|
window_builder = window_settings.initialize_size(window_builder);
|
2021-02-23 19:28:55 +00:00
|
|
|
} else if let Some(initial_size_points) = initial_size_points {
|
|
|
|
window_builder = window_builder.with_inner_size(glutin::dpi::LogicalSize {
|
|
|
|
width: initial_size_points.x as f64,
|
|
|
|
height: initial_size_points.y as f64,
|
|
|
|
});
|
2020-07-22 16:46:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 16:49:44 +00:00
|
|
|
let context_builder = glutin::ContextBuilder::new()
|
2020-07-22 16:46:12 +00:00
|
|
|
.with_depth_buffer(0)
|
|
|
|
.with_srgb(true)
|
|
|
|
.with_stencil_buffer(0)
|
|
|
|
.with_vsync(true);
|
|
|
|
|
2021-06-22 21:25:54 +00:00
|
|
|
let display = glium::Display::new(window_builder, context_builder, event_loop).unwrap();
|
2020-12-21 21:10:31 +00:00
|
|
|
|
2021-08-18 17:54:13 +00:00
|
|
|
if !cfg!(target_os = "windows") {
|
|
|
|
// If the app last ran on two monitors and only one is now connected, then
|
|
|
|
// the given position is invalid.
|
|
|
|
// If this happens on Mac, the window is clamped into valid area.
|
|
|
|
// If this happens on Windows, the window is hidden and impossible to bring to get at.
|
|
|
|
// So we don't restore window positions on Windows.
|
|
|
|
if let Some(window_settings) = &window_settings {
|
|
|
|
window_settings.restore_positions(&display);
|
|
|
|
}
|
2020-12-21 21:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
display
|
2020-10-24 16:49:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(not(feature = "persistence"))]
|
|
|
|
fn create_storage(_app_name: &str) -> Option<Box<dyn epi::Storage>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "persistence")]
|
2020-12-29 13:15:46 +00:00
|
|
|
fn create_storage(app_name: &str) -> Option<Box<dyn epi::Storage>> {
|
2020-12-19 20:06:59 +00:00
|
|
|
if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", app_name) {
|
|
|
|
let data_dir = proj_dirs.data_dir().to_path_buf();
|
|
|
|
if let Err(err) = std::fs::create_dir_all(&data_dir) {
|
|
|
|
eprintln!(
|
|
|
|
"Saving disabled: Failed to create app path at {:?}: {}",
|
|
|
|
data_dir, err
|
|
|
|
);
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let mut config_dir = data_dir;
|
2021-04-05 10:09:01 +00:00
|
|
|
config_dir.push("app.ron");
|
2021-01-04 00:44:02 +00:00
|
|
|
let storage = crate::persistence::FileStorage::from_path(config_dir);
|
2020-12-19 20:06:59 +00:00
|
|
|
Some(Box::new(storage))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eprintln!("Saving disabled: Failed to find path to data_dir.");
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:42:43 +00:00
|
|
|
fn integration_info(
|
|
|
|
display: &glium::Display,
|
|
|
|
previous_frame_time: Option<f32>,
|
|
|
|
) -> epi::IntegrationInfo {
|
|
|
|
epi::IntegrationInfo {
|
|
|
|
web_info: None,
|
2021-06-07 18:56:18 +00:00
|
|
|
prefer_dark_mode: None, // TODO: figure out system default
|
2021-01-02 13:42:43 +00:00
|
|
|
cpu_usage: previous_frame_time,
|
2021-01-04 00:44:02 +00:00
|
|
|
seconds_since_midnight: seconds_since_midnight(),
|
2021-06-22 21:25:54 +00:00
|
|
|
native_pixels_per_point: Some(native_pixels_per_point(display)),
|
2021-01-02 13:42:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 08:14:56 +00:00
|
|
|
fn load_icon(icon_data: epi::IconData) -> Option<glutin::window::Icon> {
|
2021-02-26 14:59:30 +00:00
|
|
|
glutin::window::Icon::from_rgba(icon_data.rgba, icon_data.width, icon_data.height).ok()
|
|
|
|
}
|
|
|
|
|
2021-05-08 08:14:56 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-10-24 16:49:44 +00:00
|
|
|
/// Run an egui app
|
2021-08-20 16:59:32 +00:00
|
|
|
pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
|
2021-08-15 14:39:26 +00:00
|
|
|
#[allow(unused_mut)]
|
2020-12-19 20:06:59 +00:00
|
|
|
let mut storage = create_storage(app.name());
|
|
|
|
|
2021-06-07 18:53:33 +00:00
|
|
|
#[cfg(feature = "http")]
|
|
|
|
let http = std::sync::Arc::new(crate::http::GliumHttp {});
|
2020-12-19 20:06:59 +00:00
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
let window_settings = deserialize_window_settings(&storage);
|
2021-08-20 16:59:32 +00:00
|
|
|
let mut event_loop = glutin::event_loop::EventLoop::with_user_event();
|
2021-08-18 17:54:13 +00:00
|
|
|
let icon = native_options.icon_data.clone().and_then(load_icon);
|
|
|
|
let display = create_display(&*app, &native_options, window_settings, icon, &event_loop);
|
2020-07-22 16:46:12 +00:00
|
|
|
|
2020-12-27 09:49:26 +00:00
|
|
|
let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new(
|
|
|
|
event_loop.create_proxy(),
|
|
|
|
)));
|
2020-11-20 19:35:16 +00:00
|
|
|
|
2021-04-25 15:02:27 +00:00
|
|
|
let mut egui = EguiGlium::new(&display);
|
|
|
|
*egui.ctx().memory() = deserialize_memory(&storage).unwrap_or_default();
|
2021-01-02 13:42:43 +00:00
|
|
|
|
2021-06-07 18:53:33 +00:00
|
|
|
{
|
|
|
|
let (ctx, painter) = egui.ctx_and_painter_mut();
|
|
|
|
let mut app_output = epi::backend::AppOutput::default();
|
|
|
|
let mut frame = epi::backend::FrameBuilder {
|
|
|
|
info: integration_info(&display, None),
|
|
|
|
tex_allocator: painter,
|
|
|
|
#[cfg(feature = "http")]
|
|
|
|
http: http.clone(),
|
|
|
|
output: &mut app_output,
|
|
|
|
repaint_signal: repaint_signal.clone(),
|
|
|
|
}
|
|
|
|
.build();
|
2021-06-22 21:25:54 +00:00
|
|
|
app.setup(ctx, &mut frame, storage.as_deref());
|
2021-06-07 18:53:33 +00:00
|
|
|
}
|
2020-07-22 16:46:12 +00:00
|
|
|
|
2020-10-17 10:33:30 +00:00
|
|
|
let mut previous_frame_time = None;
|
2020-07-22 16:46:12 +00:00
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
2020-12-19 20:06:59 +00:00
|
|
|
let mut last_auto_save = Instant::now();
|
|
|
|
|
2021-01-02 13:42:43 +00:00
|
|
|
if app.warm_up_enabled() {
|
2021-04-25 15:02:27 +00:00
|
|
|
let saved_memory = egui.ctx().memory().clone();
|
|
|
|
egui.ctx().memory().set_everything_is_visible(true);
|
|
|
|
|
|
|
|
egui.begin_frame(&display);
|
|
|
|
let (ctx, painter) = egui.ctx_and_painter_mut();
|
2021-01-02 13:42:43 +00:00
|
|
|
let mut app_output = epi::backend::AppOutput::default();
|
|
|
|
let mut frame = epi::backend::FrameBuilder {
|
|
|
|
info: integration_info(&display, None),
|
2021-04-25 15:02:27 +00:00
|
|
|
tex_allocator: painter,
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "http")]
|
2021-01-02 13:42:43 +00:00
|
|
|
http: http.clone(),
|
|
|
|
output: &mut app_output,
|
|
|
|
repaint_signal: repaint_signal.clone(),
|
|
|
|
}
|
|
|
|
.build();
|
|
|
|
|
2021-06-22 21:25:54 +00:00
|
|
|
app.update(ctx, &mut frame);
|
2021-01-02 13:42:43 +00:00
|
|
|
|
2021-04-25 15:02:27 +00:00
|
|
|
let _ = egui.end_frame(&display);
|
2021-03-13 11:27:05 +00:00
|
|
|
|
2021-04-25 15:02:27 +00:00
|
|
|
*egui.ctx().memory() = saved_memory; // We don't want to remember that windows were huge.
|
|
|
|
egui.ctx().clear_animations();
|
2021-03-13 11:27:05 +00:00
|
|
|
|
2021-01-02 13:42:43 +00:00
|
|
|
// TODO: handle app_output
|
|
|
|
// eprintln!("Warmed up in {} ms", warm_up_start.elapsed().as_millis())
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:59:32 +00:00
|
|
|
let mut is_focused = true;
|
|
|
|
let mut running = true;
|
|
|
|
let mut repaint_asap = true;
|
|
|
|
|
|
|
|
while running {
|
|
|
|
use glium::glutin::platform::run_return::EventLoopExtRunReturn as _;
|
|
|
|
event_loop.run_return(|event, _, control_flow| {
|
|
|
|
use glium::glutin::event_loop::ControlFlow;
|
|
|
|
|
|
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
|
|
|
|
match event {
|
|
|
|
// Platform-dependent event handlers to workaround a winit bug
|
|
|
|
// See: https://github.com/rust-windowing/winit/issues/987
|
|
|
|
// See: https://github.com/rust-windowing/winit/issues/1619
|
|
|
|
glutin::event::Event::RedrawEventsCleared if cfg!(windows) => {
|
|
|
|
*control_flow = ControlFlow::Exit; // Time to redraw
|
|
|
|
}
|
|
|
|
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => {
|
|
|
|
*control_flow = ControlFlow::Exit; // Time to redraw
|
|
|
|
}
|
|
|
|
glutin::event::Event::MainEventsCleared => {
|
|
|
|
if repaint_asap {
|
|
|
|
*control_flow = ControlFlow::Exit; // Time to redraw
|
|
|
|
} else {
|
|
|
|
// Winit uses up all the CPU of one core when returning ControlFlow::Wait.
|
|
|
|
// Sleeping here helps, but still uses 1-3% of CPU :(
|
2021-08-20 20:20:45 +00:00
|
|
|
if is_focused || !egui.input_state.raw.hovered_files.is_empty() {
|
2021-08-20 16:59:32 +00:00
|
|
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
|
|
|
} else {
|
2021-08-20 20:20:45 +00:00
|
|
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
2021-08-20 16:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glutin::event::Event::WindowEvent { event, .. } => {
|
|
|
|
if egui.is_quit_event(&event) {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let glutin::event::WindowEvent::Focused(new_focused) = event {
|
|
|
|
is_focused = new_focused;
|
|
|
|
}
|
|
|
|
|
|
|
|
egui.on_event(&event);
|
|
|
|
|
|
|
|
// TODO: ask egui if the events warrants a repaint instead of repainting on each event.
|
|
|
|
display.gl_window().window().request_redraw();
|
2021-08-20 20:20:45 +00:00
|
|
|
repaint_asap = true;
|
2021-08-20 16:59:32 +00:00
|
|
|
}
|
|
|
|
glutin::event::Event::UserEvent(RequestRepaintEvent) => {
|
|
|
|
display.gl_window().window().request_redraw();
|
|
|
|
*control_flow = ControlFlow::Exit; // Time to redraw
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
repaint_asap = false;
|
|
|
|
|
|
|
|
if running {
|
2021-04-22 18:12:49 +00:00
|
|
|
if !is_focused {
|
|
|
|
// On Mac, a minimized Window uses up all CPU: https://github.com/emilk/egui/issues/325
|
|
|
|
// We can't know if we are minimized: https://github.com/rust-windowing/winit/issues/208
|
|
|
|
// But we know if we are focused (in foreground). When minimized, we are not focused.
|
|
|
|
// However, a user may want an egui with an animation in the background,
|
|
|
|
// so we still need to repaint quite fast.
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
|
|
|
}
|
|
|
|
|
2021-04-25 15:02:27 +00:00
|
|
|
let frame_start = std::time::Instant::now();
|
2020-09-14 18:55:35 +00:00
|
|
|
|
2021-04-25 15:02:27 +00:00
|
|
|
egui.begin_frame(&display);
|
|
|
|
let (ctx, painter) = egui.ctx_and_painter_mut();
|
2020-12-31 13:31:11 +00:00
|
|
|
let mut app_output = epi::backend::AppOutput::default();
|
|
|
|
let mut frame = epi::backend::FrameBuilder {
|
2021-01-02 13:42:43 +00:00
|
|
|
info: integration_info(&display, previous_frame_time),
|
2021-04-25 15:02:27 +00:00
|
|
|
tex_allocator: painter,
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "http")]
|
2020-12-31 13:31:11 +00:00
|
|
|
http: http.clone(),
|
|
|
|
output: &mut app_output,
|
2020-11-20 19:35:16 +00:00
|
|
|
repaint_signal: repaint_signal.clone(),
|
2020-12-31 13:31:11 +00:00
|
|
|
}
|
|
|
|
.build();
|
2021-04-25 15:02:27 +00:00
|
|
|
app.update(ctx, &mut frame);
|
|
|
|
let (needs_repaint, shapes) = egui.end_frame(&display);
|
2020-09-14 18:55:35 +00:00
|
|
|
|
2020-12-19 19:50:00 +00:00
|
|
|
let frame_time = (Instant::now() - frame_start).as_secs_f64() as f32;
|
2020-10-17 10:33:30 +00:00
|
|
|
previous_frame_time = Some(frame_time);
|
2021-04-25 15:02:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
use glium::Surface as _;
|
|
|
|
let mut target = display.draw();
|
|
|
|
let clear_color = app.clear_color();
|
|
|
|
target.clear_color(
|
|
|
|
clear_color[0],
|
|
|
|
clear_color[1],
|
|
|
|
clear_color[2],
|
|
|
|
clear_color[3],
|
|
|
|
);
|
|
|
|
egui.paint(&display, &mut target, shapes);
|
|
|
|
target.finish().unwrap();
|
|
|
|
}
|
2020-10-17 10:33:30 +00:00
|
|
|
|
|
|
|
{
|
2021-08-28 12:03:27 +00:00
|
|
|
let epi::backend::AppOutput {
|
|
|
|
quit,
|
|
|
|
window_size,
|
|
|
|
decorated,
|
|
|
|
} = app_output;
|
|
|
|
|
|
|
|
if let Some(decorated) = decorated {
|
|
|
|
display.gl_window().window().set_decorations(decorated);
|
|
|
|
}
|
2020-10-17 10:33:30 +00:00
|
|
|
|
2020-10-24 16:45:31 +00:00
|
|
|
if let Some(window_size) = window_size {
|
2021-01-17 10:53:55 +00:00
|
|
|
display.gl_window().window().set_inner_size(
|
|
|
|
glutin::dpi::PhysicalSize {
|
2021-04-25 15:02:27 +00:00
|
|
|
width: (egui.ctx().pixels_per_point() * window_size.x).round(),
|
|
|
|
height: (egui.ctx().pixels_per_point() * window_size.y).round(),
|
2021-01-17 10:53:55 +00:00
|
|
|
}
|
|
|
|
.to_logical::<f32>(native_pixels_per_point(&display) as f64),
|
|
|
|
);
|
2020-10-24 16:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:59:32 +00:00
|
|
|
if quit {
|
|
|
|
running = false;
|
2021-04-25 15:02:27 +00:00
|
|
|
} else if needs_repaint {
|
2020-10-17 10:33:30 +00:00
|
|
|
display.gl_window().window().request_redraw();
|
2021-08-20 16:59:32 +00:00
|
|
|
repaint_asap = true;
|
2020-10-17 10:33:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:44:02 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
2020-12-19 20:06:59 +00:00
|
|
|
if let Some(storage) = &mut storage {
|
|
|
|
let now = Instant::now();
|
|
|
|
if now - last_auto_save > app.auto_save_interval() {
|
2020-12-29 13:15:46 +00:00
|
|
|
epi::set_value(
|
2020-12-19 20:06:59 +00:00
|
|
|
storage.as_mut(),
|
|
|
|
WINDOW_KEY,
|
|
|
|
&WindowSettings::from_display(&display),
|
|
|
|
);
|
2021-04-25 15:02:27 +00:00
|
|
|
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
2020-12-19 20:06:59 +00:00
|
|
|
app.save(storage.as_mut());
|
|
|
|
storage.flush();
|
|
|
|
last_auto_save = now;
|
|
|
|
}
|
|
|
|
}
|
2021-08-20 16:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 19:35:16 +00:00
|
|
|
|
2021-08-20 16:59:32 +00:00
|
|
|
app.on_exit();
|
2020-11-20 19:35:16 +00:00
|
|
|
|
2021-08-20 16:59:32 +00:00
|
|
|
#[cfg(feature = "persistence")]
|
|
|
|
if let Some(storage) = &mut storage {
|
|
|
|
epi::set_value(
|
|
|
|
storage.as_mut(),
|
|
|
|
WINDOW_KEY,
|
|
|
|
&WindowSettings::from_display(&display),
|
|
|
|
);
|
|
|
|
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*egui.ctx().memory());
|
|
|
|
app.save(storage.as_mut());
|
|
|
|
storage.flush();
|
|
|
|
}
|
2020-07-22 16:46:12 +00:00
|
|
|
}
|