egui: eframe-app-creation-refactor

This commit is contained in:
Simon Gardling 2022-03-15 19:07:14 -04:00
parent 5e9dc18469
commit 5d5b959f0d
4 changed files with 14 additions and 19 deletions

View File

@ -22,7 +22,7 @@ opt-level = 2
lto = false
[dependencies]
eframe = { git = "https://github.com/emilk/egui", default-features = false }
eframe = { git = "https://github.com/emilk/egui", default-features = false, branch = "eframe-app-creation-refactor" }
shadow-rs = { version = "0.9", default-features = false }
const_format = { version = "0.2.22", default-features = false, features = ["fmt"] }
cfg-if = "1.0.0"

View File

@ -10,7 +10,7 @@ use egui::{
Button, CentralPanel, Color32, ComboBox, Context, FontData, FontDefinitions, FontFamily,
RichText, SidePanel, Slider, TopBottomPanel, Vec2, Visuals, Window,
};
use epi::{Frame, Storage};
use epi::Frame;
use instant::Duration;
use serde_json::Value;
use shadow_rs::shadow;
@ -318,6 +318,14 @@ impl Default for MathApp {
}
impl MathApp {
#[allow(dead_code)] // this is used lol
pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
#[cfg(target_arch = "wasm32")]
stop_loading();
log_helper("egui app initialized.");
Self::default()
}
fn side_panel(&mut self, ctx: &Context) {
// Side Panel which contains vital options to the operation of the application
// (such as adding functions and other options)
@ -497,19 +505,6 @@ impl MathApp {
}
impl epi::App for MathApp {
// The name of the program (displayed when running natively as the window title)
fn name(&self) -> &str { "(Yet-to-be-named) Graphing Software" }
// Called once before the first frame.
fn setup(
&mut self, _ctx: &Context, _frame: &Frame, _storage: Option<&dyn Storage>,
_gl: &std::rc::Rc<epi::glow::Context>,
) {
#[cfg(target_arch = "wasm32")]
stop_loading();
log_helper("egui app initialized.");
}
// Called each time the UI needs repainting, which may be many times per second.
#[inline(always)]
fn update(&mut self, ctx: &Context, _frame: &Frame) {

View File

@ -27,8 +27,7 @@ cfg_if::cfg_if! {
log_helper("Finished initializing!");
log_helper("Starting App...");
let app = egui_app::MathApp::default();
eframe::start_web("canvas", Box::new(app))
eframe::start_web("canvas", |cc| Box::new(egui_app::MathApp::new(cc)))
}
}
}

View File

@ -9,11 +9,12 @@ mod parsing;
// For running the program natively! (Because why not?)
#[cfg(not(target_arch = "wasm32"))]
fn main() {
let app = egui_app::MathApp::default();
let options = eframe::NativeOptions {
transparent: true,
drag_and_drop_support: true,
..Default::default()
};
eframe::run_native(Box::new(app), options);
eframe::run_native("(Yet-to-be-named) Graphing Software", options, |cc| {
Box::new(egui_app::MathApp::new(cc))
});
}