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",
|
"ehttp",
|
||||||
"epi",
|
"epi",
|
||||||
"glow",
|
"glow",
|
||||||
|
"glutin",
|
||||||
"image",
|
"image",
|
||||||
"parking_lot 0.12.0",
|
"parking_lot 0.12.0",
|
||||||
"poll-promise",
|
"poll-promise",
|
||||||
|
@ -1082,7 +1083,6 @@ dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
"egui-winit",
|
"egui-winit",
|
||||||
"epi",
|
|
||||||
"glow",
|
"glow",
|
||||||
"glutin",
|
"glutin",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
|
|
|
@ -46,16 +46,18 @@ screen_reader = [
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.17.0", path = "../egui", default-features = false }
|
egui = { version = "0.17.0", path = "../egui", default-features = false }
|
||||||
epi = { version = "0.17.0", path = "../epi" }
|
epi = { version = "0.17.0", path = "../epi" }
|
||||||
|
glow = "0.11"
|
||||||
|
parking_lot = "0.12"
|
||||||
|
|
||||||
# native:
|
# native:
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [
|
egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false, features = [
|
||||||
"clipboard",
|
"clipboard",
|
||||||
"epi",
|
|
||||||
"links",
|
"links",
|
||||||
"winit",
|
"winit",
|
||||||
] }
|
] }
|
||||||
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false }
|
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false }
|
||||||
|
glutin = "0.28.0"
|
||||||
|
|
||||||
# web:
|
# web:
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[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
|
// 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"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[allow(clippy::needless_pass_by_value)]
|
mod native;
|
||||||
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! {
|
|
||||||
egui_glow::run(app_name, &native_options, app_creator)
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
}
|
pub use native::run_native;
|
||||||
|
|
|
@ -32,18 +32,56 @@ fn create_display(
|
||||||
|
|
||||||
pub use epi::NativeOptions;
|
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)]
|
#[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 persistence = egui_winit::epi::Persistence::from_app_name(app_name);
|
||||||
let window_settings = persistence.load_window_settings();
|
let window_settings = persistence.load_window_settings();
|
||||||
let window_builder =
|
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 event_loop = winit::event_loop::EventLoop::with_user_event();
|
||||||
let (gl_window, gl) = create_display(window_builder, &event_loop);
|
let (gl_window, gl) = create_display(window_builder, &event_loop);
|
||||||
let gl = std::rc::Rc::new(gl);
|
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));
|
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
|
||||||
|
|
||||||
let mut integration = egui_winit::epi::EpiIntegration::new(
|
let mut integration = egui_winit::epi::EpiIntegration::new(
|
|
@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"]
|
||||||
links = ["egui-winit/links"]
|
links = ["egui-winit/links"]
|
||||||
|
|
||||||
# enable persisting native window options and egui memory
|
# enable persisting native window options and egui memory
|
||||||
persistence = [
|
persistence = ["egui-winit/persistence", "egui/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",
|
|
||||||
]
|
|
||||||
|
|
||||||
# experimental support for a screen reader
|
# experimental support for a screen reader
|
||||||
screen_reader = ["egui-winit/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 = [
|
egui = { version = "0.17.0", path = "../egui", default-features = false, features = [
|
||||||
"convert_bytemuck",
|
"convert_bytemuck",
|
||||||
] }
|
] }
|
||||||
epi = { version = "0.17.0", path = "../epi", optional = true }
|
|
||||||
|
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.7"
|
||||||
glow = "0.11"
|
glow = "0.11"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
//!
|
//!
|
||||||
//! The main type you want to use is [`EguiGlow`].
|
//! 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.
|
//! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead.
|
||||||
|
|
||||||
// Forbid warnings in release builds:
|
// Forbid warnings in release builds:
|
||||||
|
@ -99,9 +98,3 @@ mod vao_emulate;
|
||||||
pub mod winit;
|
pub mod winit;
|
||||||
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
#[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
|
||||||
pub use 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