Setup a layer trait
This commit is contained in:
+18
-10
@@ -1,20 +1,23 @@
|
||||
use std::time::Duration;
|
||||
use eframe::{egui, Frame, Storage, CreationContext};
|
||||
use eframe::{Frame, Storage, CreationContext};
|
||||
use eframe::egui::{Context, Ui};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Application {
|
||||
settings: AppSettings,
|
||||
layers: Vec<Box<dyn crate::layer::Layer>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct AppSettings {
|
||||
serialization_test_string: String,
|
||||
use_cookies: bool,
|
||||
use_firefox_cookies: bool,
|
||||
use_chrome_cookies: bool,
|
||||
save_thumbnails: bool,
|
||||
}
|
||||
|
||||
impl Application {
|
||||
pub fn new(cc: &CreationContext) -> Self {
|
||||
pub fn new(cc: &CreationContext, layers: Vec<Box<dyn crate::layer::Layer>>) -> Self {
|
||||
let mut settings = AppSettings::default();
|
||||
if let Some(storage) = cc.storage {
|
||||
if let Some(stored_str) = storage.get_string("app_settings") {
|
||||
@@ -24,21 +27,26 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
Self { settings }
|
||||
Self { settings, layers }
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for Application {
|
||||
|
||||
fn logic(&mut self, ctx: &Context, frame: &mut Frame) {
|
||||
|
||||
let mut layers = std::mem::take(&mut self.layers);
|
||||
for layer in &mut layers {
|
||||
layer.logic(self, ctx, frame);
|
||||
}
|
||||
self.layers = layers;
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut Ui, frame: &mut Frame) {
|
||||
egui::CentralPanel::default().show(ui, |ui| {
|
||||
ui.heading("Hello!");
|
||||
ui.text_edit_singleline(&mut self.settings.serialization_test_string);
|
||||
});
|
||||
let mut layers = std::mem::take(&mut self.layers);
|
||||
for layer in &mut layers {
|
||||
layer.ui(self, ui, frame);
|
||||
}
|
||||
self.layers = layers;
|
||||
}
|
||||
|
||||
fn save(&mut self, _storage: &mut dyn Storage) {
|
||||
|
||||
Reference in New Issue
Block a user