diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b4afc5..88d3d4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * `ui.image` now takes `impl Into` as a `size` argument. * Made some more fields of `RawInput` optional. * `Slider` and `DragValue` uses fewer decimals by default. See the full precision by hovering over the value. +* `egui::App`: added `fn name(&self)` ### Deprecated * Deprecated `RawInput::screen_size` - use `RawInput::screen_rect` instead. diff --git a/demo_glium/src/main.rs b/demo_glium/src/main.rs index 51d6bff6..62899896 100644 --- a/demo_glium/src/main.rs +++ b/demo_glium/src/main.rs @@ -3,8 +3,6 @@ #![warn(clippy::all)] fn main() { - let title = "Egui glium demo"; - // Persist app state to file: let storage = egui_glium::storage::FileStorage::from_path(".egui_demo_glium.json"); @@ -12,5 +10,5 @@ fn main() { // let storage = egui::app::DummyStorage::default(); let app: egui::DemoApp = egui::app::get_value(&storage, egui::app::APP_KEY).unwrap_or_default(); - egui_glium::run(title, Box::new(storage), Box::new(app)); + egui_glium::run(Box::new(storage), Box::new(app)); } diff --git a/egui/src/app.rs b/egui/src/app.rs index b34a2582..c2fc61da 100644 --- a/egui/src/app.rs +++ b/egui/src/app.rs @@ -12,6 +12,10 @@ use crate::Context; /// Implement this trait to write apps that can be compiled both natively using the [`egui_glium`](https://crates.io/crates/egui_glium) crate, /// and deployed as a web site using the [`egui_web`](https://crates.io/crates/egui_web) crate. pub trait App { + /// The name of your App. + fn name(&self) -> &str; + } + /// Called once before the first frame. /// Allows you to do setup code and to call `ctx.set_fonts()`. /// Optional. diff --git a/egui/src/demos/app.rs b/egui/src/demos/app.rs index 956fb09d..51a8979d 100644 --- a/egui/src/demos/app.rs +++ b/egui/src/demos/app.rs @@ -278,6 +278,10 @@ impl DemoApp { } impl app::App for DemoApp { + fn name(&self) -> &str { + "Egui Demo" + } + fn ui( &mut self, ctx: &Arc, diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index 0b80d392..cf4f1e72 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed * `egui_glium::run`: the parameter `app` now has signature `Box` (you need to add `Box::new(app)` to your code). +* Window title is now passed via the `trait` function `egui::App::name()` ### Fixed 🐛 diff --git a/egui_glium/src/backend.rs b/egui_glium/src/backend.rs index eb35cf6b..523c139c 100644 --- a/egui_glium/src/backend.rs +++ b/egui_glium/src/backend.rs @@ -64,11 +64,11 @@ fn create_display( } /// Run an egui app -pub fn run(title: &str, mut storage: Box, mut app: Box) -> ! { +pub fn run(mut storage: Box, mut app: Box) -> ! { let window_settings: Option = egui::app::get_value(storage.as_ref(), WINDOW_KEY); let event_loop = glutin::event_loop::EventLoop::with_user_event(); - let display = create_display(title, window_settings, &event_loop); + let display = create_display(app.name(), window_settings, &event_loop); let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(event_loop.create_proxy())); diff --git a/example_glium/src/example_app.rs b/example_glium/src/example_app.rs index 9fb2a705..4ae55768 100644 --- a/example_glium/src/example_app.rs +++ b/example_glium/src/example_app.rs @@ -15,6 +15,10 @@ impl Default for ExampleApp { } impl egui::app::App for ExampleApp { + fn name(&self) -> &str { + "Egui Example" + } + /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. fn ui( diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index 569f58ae..e94c9f28 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -7,8 +7,6 @@ mod example_app; use example_app::ExampleApp; fn main() { - let title = "My Egui Window"; - // Persist app state to file: let storage = egui_glium::storage::FileStorage::from_path(".egui_example_glium.json"); @@ -18,5 +16,5 @@ fn main() { // Restore `example_app` from file, or create new `ExampleApp`: let app: ExampleApp = egui::app::get_value(&storage, egui::app::APP_KEY).unwrap_or_default(); - egui_glium::run(title, Box::new(storage), Box::new(app)); + egui_glium::run(Box::new(storage), Box::new(app)); } diff --git a/example_web/src/example_app.rs b/example_web/src/example_app.rs index 4e351c37..1bf7cf96 100644 --- a/example_web/src/example_app.rs +++ b/example_web/src/example_app.rs @@ -39,6 +39,10 @@ impl Default for ExampleApp { } impl egui::app::App for ExampleApp { + fn name(&self) -> &str { + "Egui Fetch Example" + } + /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. fn ui(