Move epi-code from egui_glow into eframe
This commit is contained in:
parent
0a400a5bcc
commit
4922b1912b
6 changed files with 51 additions and 60 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -986,6 +986,7 @@ dependencies = [
|
|||
"ehttp",
|
||||
"epi",
|
||||
"glow",
|
||||
"glutin",
|
||||
"image",
|
||||
"parking_lot 0.12.0",
|
||||
"poll-promise",
|
||||
|
@ -1082,7 +1083,6 @@ dependencies = [
|
|||
"bytemuck",
|
||||
"egui",
|
||||
"egui-winit",
|
||||
"epi",
|
||||
"glow",
|
||||
"glutin",
|
||||
"memoffset",
|
||||
|
|
|
@ -46,16 +46,18 @@ screen_reader = [
|
|||
[dependencies]
|
||||
egui = { version = "0.17.0", path = "../egui", default-features = false }
|
||||
epi = { version = "0.17.0", path = "../epi" }
|
||||
glow = "0.11"
|
||||
parking_lot = "0.12"
|
||||
|
||||
# native:
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [
|
||||
"clipboard",
|
||||
"epi",
|
||||
"links",
|
||||
"winit",
|
||||
] }
|
||||
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false }
|
||||
glutin = "0.28.0"
|
||||
|
||||
# web:
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
|
|
@ -98,43 +98,8 @@ pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bi
|
|||
// ----------------------------------------------------------------------------
|
||||
// When compiling natively
|
||||
|
||||
/// This is how you start a native (desktop) app.
|
||||
///
|
||||
/// The first argument is name of your app, used for the title bar of the native window
|
||||
/// and the save location of persistence (see [`epi::App::save`]).
|
||||
///
|
||||
/// Call from `fn main` like this:
|
||||
/// ``` no_run
|
||||
/// use eframe::egui;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let native_options = eframe::NativeOptions::default();
|
||||
/// eframe::run_native("MyApp", native_options, Box::new(|cc| Box::new(MyEguiApp::new(cc))));
|
||||
/// }
|
||||
///
|
||||
/// #[derive(Default)]
|
||||
/// struct MyEguiApp {}
|
||||
///
|
||||
/// impl MyEguiApp {
|
||||
/// fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
/// // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
|
||||
/// // Restore app state using cc.storage (requires the "persistence" feature).
|
||||
/// // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
|
||||
/// // for e.g. egui::PaintCallback.
|
||||
/// Self::default()
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl eframe::App for MyEguiApp {
|
||||
/// fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
|
||||
/// egui::CentralPanel::default().show(ctx, |ui| {
|
||||
/// ui.heading("Hello World!");
|
||||
/// });
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! {
|
||||
egui_glow::run(app_name, &native_options, app_creator)
|
||||
}
|
||||
mod native;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use native::run_native;
|
||||
|
|
|
@ -32,18 +32,56 @@ fn create_display(
|
|||
|
||||
pub use epi::NativeOptions;
|
||||
|
||||
/// Run an egui app
|
||||
/// This is how you start a native (desktop) app.
|
||||
///
|
||||
/// The first argument is name of your app, used for the title bar of the native window
|
||||
/// and the save location of persistence (see [`epi::App::save`]).
|
||||
///
|
||||
/// Call from `fn main` like this:
|
||||
/// ``` no_run
|
||||
/// use eframe::egui;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let native_options = eframe::NativeOptions::default();
|
||||
/// eframe::run_native("MyApp", native_options, |cc| Box::new(MyEguiApp::new(cc)));
|
||||
/// }
|
||||
///
|
||||
/// #[derive(Default)]
|
||||
/// struct MyEguiApp {}
|
||||
///
|
||||
/// impl MyEguiApp {
|
||||
/// fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
/// // Customize egui here with cc.egui_ctx.set_fonts and cc.egui_ctx.set_visuals.
|
||||
/// // Restore app state using cc.storage (requires the "persistence" feature).
|
||||
/// // Use the cc.gl (a glow::Context) to create graphics shaders and buffers that you can use
|
||||
/// // for e.g. egui::PaintCallback.
|
||||
/// Self::default()
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl eframe::App for MyEguiApp {
|
||||
/// fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
|
||||
/// egui::CentralPanel::default().show(ctx, |ui| {
|
||||
/// ui.heading("Hello World!");
|
||||
/// });
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[allow(unsafe_code)]
|
||||
pub fn run(app_name: &str, native_options: &epi::NativeOptions, app_creator: epi::AppCreator) -> ! {
|
||||
pub fn run_native(
|
||||
app_name: &str,
|
||||
native_options: epi::NativeOptions,
|
||||
app_creator: epi::AppCreator,
|
||||
) -> ! {
|
||||
let persistence = egui_winit::epi::Persistence::from_app_name(app_name);
|
||||
let window_settings = persistence.load_window_settings();
|
||||
let window_builder =
|
||||
egui_winit::epi::window_builder(native_options, &window_settings).with_title(app_name);
|
||||
egui_winit::epi::window_builder(&native_options, &window_settings).with_title(app_name);
|
||||
let event_loop = winit::event_loop::EventLoop::with_user_event();
|
||||
let (gl_window, gl) = create_display(window_builder, &event_loop);
|
||||
let gl = std::rc::Rc::new(gl);
|
||||
|
||||
let mut painter = crate::Painter::new(gl.clone(), None, "")
|
||||
let mut painter = egui_glow::Painter::new(gl.clone(), None, "")
|
||||
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
|
||||
|
||||
let mut integration = egui_winit::epi::EpiIntegration::new(
|
|
@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"]
|
|||
links = ["egui-winit/links"]
|
||||
|
||||
# enable persisting native window options and egui memory
|
||||
persistence = [
|
||||
"egui-winit/persistence",
|
||||
"egui/persistence",
|
||||
"epi", # also implied by the lines below, see https://github.com/rust-lang/cargo/issues/8832
|
||||
"epi/file_storage",
|
||||
"epi/persistence",
|
||||
]
|
||||
persistence = ["egui-winit/persistence", "egui/persistence"]
|
||||
|
||||
# experimental support for a screen reader
|
||||
screen_reader = ["egui-winit/screen_reader"]
|
||||
|
@ -58,7 +52,6 @@ winit = ["egui-winit", "glutin"]
|
|||
egui = { version = "0.17.0", path = "../egui", default-features = false, features = [
|
||||
"convert_bytemuck",
|
||||
] }
|
||||
epi = { version = "0.17.0", path = "../epi", optional = true }
|
||||
|
||||
bytemuck = "1.7"
|
||||
glow = "0.11"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//!
|
||||
//! The main type you want to use is [`EguiGlow`].
|
||||
//!
|
||||
//! This library is an [`epi`] backend.
|
||||
//! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead.
|
||||
|
||||
// Forbid warnings in release builds:
|
||||
|
@ -99,9 +98,3 @@ mod vao_emulate;
|
|||
pub mod winit;
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||
pub use winit::*;
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||
mod epi_backend;
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||
pub use epi_backend::{run, NativeOptions};
|
||||
|
|
Loading…
Reference in a new issue