trait App now has fn name() for specifying egui_glium window title

This commit is contained in:
Emil Ernerfeldt 2020-12-18 22:30:59 +01:00
parent 71449fe61c
commit b0e17638df
9 changed files with 22 additions and 8 deletions

View file

@ -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<Vec2>` 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.

View file

@ -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));
}

View file

@ -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.

View file

@ -278,6 +278,10 @@ impl DemoApp {
}
impl app::App for DemoApp {
fn name(&self) -> &str {
"Egui Demo"
}
fn ui(
&mut self,
ctx: &Arc<Context>,

View file

@ -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<dyn App>` (you need to add `Box::new(app)` to your code).
* Window title is now passed via the `trait` function `egui::App::name()`
### Fixed 🐛

View file

@ -64,11 +64,11 @@ fn create_display(
}
/// Run an egui app
pub fn run(title: &str, mut storage: Box<dyn egui::app::Storage>, mut app: Box<dyn App>) -> ! {
pub fn run(mut storage: Box<dyn egui::app::Storage>, mut app: Box<dyn App>) -> ! {
let window_settings: Option<WindowSettings> =
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()));

View file

@ -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(

View file

@ -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));
}

View file

@ -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(