Skip to content

Commit

Permalink
eframe: re-export epi::* so users don't need to care about what epi is
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Mar 15, 2022
1 parent b24f650 commit 1f0e84a
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 45 deletions.
6 changes: 3 additions & 3 deletions eframe/examples/confirm_exit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

fn main() {
let options = eframe::NativeOptions::default();
Expand All @@ -13,13 +13,13 @@ struct MyApp {
is_exiting: bool,
}

impl epi::App for MyApp {
impl eframe::App for MyApp {
fn on_exit_event(&mut self) -> bool {
self.is_exiting = true;
self.can_exit
}

fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Try to close the window");
});
Expand Down
8 changes: 4 additions & 4 deletions eframe/examples/custom_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

use parking_lot::Mutex;
use std::sync::Arc;
Expand All @@ -27,16 +27,16 @@ struct MyApp {
}

impl MyApp {
fn new(cc: &epi::CreationContext<'_>) -> Self {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
Self {
rotating_triangle: Arc::new(Mutex::new(RotatingTriangle::new(&cc.gl))),
angle: 0.0,
}
}
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
Expand Down
8 changes: 4 additions & 4 deletions eframe/examples/custom_font.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

fn main() {
let options = eframe::NativeOptions::default();
Expand Down Expand Up @@ -43,16 +43,16 @@ struct MyApp {
}

impl MyApp {
fn new(cc: &epi::CreationContext<'_>) -> Self {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
setup_custom_fonts(&cc.egui_ctx);
Self {
text: "Edit this text field if you want".to_owned(),
}
}
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("egui using custom fonts");
ui.text_edit_multiline(&mut self.text);
Expand Down
6 changes: 3 additions & 3 deletions eframe/examples/download_image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;
use egui_extras::RetainedImage;
use poll_promise::Promise;

Expand All @@ -19,8 +19,8 @@ struct MyApp {
promise: Option<Promise<ehttp::Result<RetainedImage>>>,
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
let promise = self.promise.get_or_insert_with(|| {
// Begin download.
// We download the image using `ehttp`, a library that works both in WASM and on native.
Expand Down
6 changes: 3 additions & 3 deletions eframe/examples/file_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

fn main() {
let options = eframe::NativeOptions {
Expand All @@ -20,8 +20,8 @@ struct MyApp {
picked_path: Option<String>,
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Drag-and-drop files onto the window!");

Expand Down
6 changes: 3 additions & 3 deletions eframe/examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

fn main() {
let options = eframe::NativeOptions::default();
Expand All @@ -21,8 +21,8 @@ impl Default for MyApp {
}
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application");
ui.horizontal(|ui| {
Expand Down
6 changes: 3 additions & 3 deletions eframe/examples/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;
use egui_extras::RetainedImage;

fn main() {
Expand All @@ -26,8 +26,8 @@ impl Default for MyApp {
}
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("This is an image:");
self.image.show(ui);
Expand Down
6 changes: 3 additions & 3 deletions eframe/examples/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use eframe::{egui, epi};
use eframe::egui;

fn main() {
let options = eframe::NativeOptions {
Expand All @@ -30,8 +30,8 @@ impl Default for MyApp {
}
}

impl epi::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("SVG example");
ui.label("The SVG is rasterized and displayed as a texture.");
Expand Down
32 changes: 13 additions & 19 deletions eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! ## Usage, native:
//! ``` no_run
//! use eframe::{epi, egui};
//! use eframe::egui;
//!
//! fn main() {
//! let native_options = eframe::NativeOptions::default();
Expand All @@ -27,7 +27,7 @@
//! struct MyEguiApp {}
//!
//! impl MyEguiApp {
//! fn new(cc: &epi::CreationContext<'_>) -> Self {
//! 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
Expand All @@ -36,8 +36,8 @@
//! }
//! }
//!
//! impl epi::App for MyEguiApp {
//! fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
//! 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!");
//! });
Expand Down Expand Up @@ -69,10 +69,11 @@
)]
#![allow(clippy::needless_doctest_main)]

// Re-export all useful libraries:
pub use {egui, egui::emath, egui::epaint, epi};

#[cfg(not(target_arch = "wasm32"))]
pub use epi::NativeOptions;
// Re-export everything in `epi` so `eframe` users don't have to care about what `epi` is:
pub use epi::*;

// ----------------------------------------------------------------------------
// When compiling for web
Expand Down Expand Up @@ -102,10 +103,7 @@ pub use egui_web::wasm_bindgen;
/// }
/// ```
#[cfg(target_arch = "wasm32")]
pub fn start_web(
canvas_id: &str,
app_creator: epi::AppCreator,
) -> Result<(), wasm_bindgen::JsValue> {
pub fn start_web(canvas_id: &str, app_creator: AppCreator) -> Result<(), wasm_bindgen::JsValue> {
egui_web::start(canvas_id, app_creator)?;
Ok(())
}
Expand All @@ -120,7 +118,7 @@ pub fn start_web(
///
/// Call from `fn main` like this:
/// ``` no_run
/// use eframe::{epi, egui};
/// use eframe::egui;
///
/// fn main() {
/// let native_options = eframe::NativeOptions::default();
Expand All @@ -131,7 +129,7 @@ pub fn start_web(
/// struct MyEguiApp {}
///
/// impl MyEguiApp {
/// fn new(cc: &epi::CreationContext<'_>) -> Self {
/// 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
Expand All @@ -140,19 +138,15 @@ pub fn start_web(
/// }
/// }
///
/// impl epi::App for MyEguiApp {
/// fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) {
/// 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"))]
pub fn run_native(
app_name: &str,
native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> ! {
pub fn run_native(app_name: &str, native_options: NativeOptions, app_creator: AppCreator) -> ! {
egui_glow::run(app_name, &native_options, app_creator)
}

0 comments on commit 1f0e84a

Please sign in to comment.