Move egui::app
into new epi
crate
This commit is contained in:
parent
6953dc7d5d
commit
d7459bc13d
21 changed files with 157 additions and 72 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -629,7 +629,6 @@ dependencies = [
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rusttype",
|
"rusttype",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -640,6 +639,7 @@ dependencies = [
|
||||||
"egui_demo_lib",
|
"egui_demo_lib",
|
||||||
"egui_glium",
|
"egui_glium",
|
||||||
"egui_web",
|
"egui_web",
|
||||||
|
"epi",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"serde",
|
"serde",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
@ -651,6 +651,7 @@ version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"criterion",
|
"criterion",
|
||||||
"egui",
|
"egui",
|
||||||
|
"epi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -661,6 +662,7 @@ dependencies = [
|
||||||
"clipboard",
|
"clipboard",
|
||||||
"directories-next",
|
"directories-next",
|
||||||
"egui",
|
"egui",
|
||||||
|
"epi",
|
||||||
"glium",
|
"glium",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -672,6 +674,7 @@ name = "egui_web"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"egui",
|
"egui",
|
||||||
|
"epi",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -686,12 +689,22 @@ version = "1.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "epi"
|
||||||
|
version = "0.6.0"
|
||||||
|
dependencies = [
|
||||||
|
"egui",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "example_web"
|
name = "example_web"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"egui",
|
"egui",
|
||||||
"egui_web",
|
"egui_web",
|
||||||
|
"epi",
|
||||||
"image",
|
"image",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -5,6 +5,7 @@ members = [
|
||||||
"egui_glium",
|
"egui_glium",
|
||||||
"egui_web",
|
"egui_web",
|
||||||
"egui",
|
"egui",
|
||||||
|
"epi",
|
||||||
"example_web",
|
"example_web",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
2
TODO.md
2
TODO.md
|
@ -151,4 +151,4 @@ Ability to do a search for any widget. The search works even for collapsed regio
|
||||||
* [x] Use HW clip rects
|
* [x] Use HW clip rects
|
||||||
* [x] Image support
|
* [x] Image support
|
||||||
* [x] Show user textures
|
* [x] Show user textures
|
||||||
* [x] API for creating a texture managed by `egui::app::Backend`
|
* [x] API for creating a texture managed by `epi` backend
|
||||||
|
|
|
@ -24,7 +24,6 @@ atomic_refcell = { version = "0.1", optional = true } # Used instead of parking_
|
||||||
parking_lot = { version = "0.11", optional = true } # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios
|
parking_lot = { version = "0.11", optional = true } # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios
|
||||||
rusttype = "0.9"
|
rusttype = "0.9"
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
serde_json = { version = "1", optional = true }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["atomic_refcell", "default_fonts"]
|
default = ["atomic_refcell", "default_fonts"]
|
||||||
|
|
|
@ -79,7 +79,6 @@
|
||||||
|
|
||||||
pub mod align;
|
pub mod align;
|
||||||
mod animation_manager;
|
mod animation_manager;
|
||||||
pub mod app;
|
|
||||||
pub mod containers;
|
pub mod containers;
|
||||||
mod context;
|
mod context;
|
||||||
mod id;
|
mod id;
|
||||||
|
|
|
@ -9,8 +9,9 @@ edition = "2018"
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { path = "../egui", features = ["serde", "serde_json"] }
|
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||||
egui_demo_lib = { path = "../egui_demo_lib" }
|
egui_demo_lib = { path = "../egui_demo_lib" }
|
||||||
|
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
||||||
# For compiling natively:
|
# For compiling natively:
|
||||||
|
|
|
@ -16,6 +16,7 @@ include = [ "**/*.rs", "Cargo.toml"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.6.0", path = "../egui" }
|
egui = { version = "0.6.0", path = "../egui" }
|
||||||
|
epi = { version = "0.6.0", path = "../epi" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = { version = "0.3", default-features = false }
|
criterion = { version = "0.3", default-features = false }
|
||||||
|
|
|
@ -171,7 +171,7 @@ impl FrameHistory {
|
||||||
|
|
||||||
/// Demonstrates how to make an app using Egui.
|
/// Demonstrates how to make an app using Egui.
|
||||||
///
|
///
|
||||||
/// Implements `egui::app::App` so it can be used with
|
/// Implements `epi::App` so it can be used with
|
||||||
/// [`egui_glium`](https://crates.io/crates/egui_glium) and [`egui_web`](https://crates.io/crates/egui_web).
|
/// [`egui_glium`](https://crates.io/crates/egui_glium) and [`egui_web`](https://crates.io/crates/egui_web).
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
@ -192,7 +192,7 @@ pub struct DemoApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DemoApp {
|
impl DemoApp {
|
||||||
fn backend_ui(&mut self, ui: &mut Ui, integration_context: &mut app::IntegrationContext<'_>) {
|
fn backend_ui(&mut self, ui: &mut Ui, integration_context: &mut epi::IntegrationContext<'_>) {
|
||||||
let is_web = integration_context.info.web_info.is_some();
|
let is_web = integration_context.info.web_info.is_some();
|
||||||
|
|
||||||
if is_web {
|
if is_web {
|
||||||
|
@ -227,7 +227,7 @@ impl DemoApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pixels_per_point_ui(&mut self, ui: &mut Ui, info: &app::IntegrationInfo) -> Option<f32> {
|
fn pixels_per_point_ui(&mut self, ui: &mut Ui, info: &epi::IntegrationInfo) -> Option<f32> {
|
||||||
self.pixels_per_point = self
|
self.pixels_per_point = self
|
||||||
.pixels_per_point
|
.pixels_per_point
|
||||||
.or(info.native_pixels_per_point)
|
.or(info.native_pixels_per_point)
|
||||||
|
@ -278,22 +278,22 @@ impl DemoApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl app::App for DemoApp {
|
impl epi::App for DemoApp {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"Egui Demo"
|
"Egui Demo"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde_json")]
|
#[cfg(feature = "serde_json")]
|
||||||
fn load(&mut self, storage: &dyn egui::app::Storage) {
|
fn load(&mut self, storage: &dyn epi::Storage) {
|
||||||
*self = egui::app::get_value(storage, egui::app::APP_KEY).unwrap_or_default()
|
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde_json")]
|
#[cfg(feature = "serde_json")]
|
||||||
fn save(&mut self, storage: &mut dyn egui::app::Storage) {
|
fn save(&mut self, storage: &mut dyn epi::Storage) {
|
||||||
egui::app::set_value(storage, egui::app::APP_KEY, self);
|
epi::set_value(storage, epi::APP_KEY, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ui(&mut self, ctx: &CtxRef, integration_context: &mut egui::app::IntegrationContext<'_>) {
|
fn ui(&mut self, ctx: &CtxRef, integration_context: &mut epi::IntegrationContext<'_>) {
|
||||||
self.frame_history
|
self.frame_history
|
||||||
.on_new_frame(ctx.input().time, integration_context.info.cpu_usage);
|
.on_new_frame(ctx.input().time, integration_context.info.cpu_usage);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl ColorTest {
|
||||||
pub fn ui(
|
pub fn ui(
|
||||||
&mut self,
|
&mut self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
mut tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
mut tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||||
) {
|
) {
|
||||||
ui.label("This is made to test if your Egui painter backend is set up correctly");
|
ui.label("This is made to test if your Egui painter backend is set up correctly");
|
||||||
ui.label("It is meant to ensure you do proper sRGBA decoding of both texture and vertex colors, and blend using premultiplied alpha.");
|
ui.label("It is meant to ensure you do proper sRGBA decoding of both texture and vertex colors, and blend using premultiplied alpha.");
|
||||||
|
@ -132,7 +132,7 @@ impl ColorTest {
|
||||||
fn show_gradients(
|
fn show_gradients(
|
||||||
&mut self,
|
&mut self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||||
bg_fill: Srgba,
|
bg_fill: Srgba,
|
||||||
(left, right): (Srgba, Srgba),
|
(left, right): (Srgba, Srgba),
|
||||||
) {
|
) {
|
||||||
|
@ -226,7 +226,7 @@ impl ColorTest {
|
||||||
fn tex_gradient(
|
fn tex_gradient(
|
||||||
&mut self,
|
&mut self,
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||||
label: &str,
|
label: &str,
|
||||||
bg_fill: Srgba,
|
bg_fill: Srgba,
|
||||||
gradient: &Gradient,
|
gradient: &Gradient,
|
||||||
|
@ -358,7 +358,7 @@ struct TextureManager(HashMap<Gradient, TextureId>);
|
||||||
impl TextureManager {
|
impl TextureManager {
|
||||||
fn get(
|
fn get(
|
||||||
&mut self,
|
&mut self,
|
||||||
tex_allocator: &mut dyn app::TextureAllocator,
|
tex_allocator: &mut dyn epi::TextureAllocator,
|
||||||
gradient: &Gradient,
|
gradient: &Gradient,
|
||||||
) -> TextureId {
|
) -> TextureId {
|
||||||
*self.0.entry(gradient.clone()).or_insert_with(|| {
|
*self.0.entry(gradient.clone()).or_insert_with(|| {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use egui::{app, CtxRef, Resize, ScrollArea, Ui, Window};
|
use egui::{CtxRef, Resize, ScrollArea, Ui, Window};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ impl DemoWindows {
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &CtxRef,
|
ctx: &CtxRef,
|
||||||
env: &DemoEnvironment,
|
env: &DemoEnvironment,
|
||||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||||
sidebar_ui: impl FnOnce(&mut Ui),
|
sidebar_ui: impl FnOnce(&mut Ui),
|
||||||
) {
|
) {
|
||||||
if self.previous_link != env.link {
|
if self.previous_link != env.link {
|
||||||
|
@ -144,7 +144,7 @@ impl DemoWindows {
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &CtxRef,
|
ctx: &CtxRef,
|
||||||
env: &DemoEnvironment,
|
env: &DemoEnvironment,
|
||||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||||
) {
|
) {
|
||||||
let Self {
|
let Self {
|
||||||
open_windows,
|
open_windows,
|
||||||
|
|
|
@ -16,7 +16,8 @@ include = [ "**/*.rs", "Cargo.toml"]
|
||||||
chrono = { version = "0.4" }
|
chrono = { version = "0.4" }
|
||||||
clipboard = "0.5"
|
clipboard = "0.5"
|
||||||
directories-next = "2"
|
directories-next = "2"
|
||||||
egui = { version = "0.6.0", path = "../egui", features = ["serde", "serde_json"] }
|
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||||
|
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||||
glium = "0.29"
|
glium = "0.29"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
|
@ -2,15 +2,12 @@ use std::time::Instant;
|
||||||
|
|
||||||
use crate::{storage::WindowSettings, *};
|
use crate::{storage::WindowSettings, *};
|
||||||
|
|
||||||
pub use egui::{
|
pub use egui::Srgba;
|
||||||
app::{self, App, Storage},
|
|
||||||
Srgba,
|
|
||||||
};
|
|
||||||
|
|
||||||
const EGUI_MEMORY_KEY: &str = "egui";
|
const EGUI_MEMORY_KEY: &str = "egui";
|
||||||
const WINDOW_KEY: &str = "window";
|
const WINDOW_KEY: &str = "window";
|
||||||
|
|
||||||
impl egui::app::TextureAllocator for Painter {
|
impl epi::TextureAllocator for Painter {
|
||||||
fn alloc(&mut self) -> egui::TextureId {
|
fn alloc(&mut self) -> egui::TextureId {
|
||||||
self.alloc_user_texture()
|
self.alloc_user_texture()
|
||||||
}
|
}
|
||||||
|
@ -35,7 +32,7 @@ struct GliumRepaintSignal(
|
||||||
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl egui::app::RepaintSignal for GliumRepaintSignal {
|
impl epi::RepaintSignal for GliumRepaintSignal {
|
||||||
fn request_repaint(&self) {
|
fn request_repaint(&self) {
|
||||||
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
|
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
|
||||||
}
|
}
|
||||||
|
@ -72,7 +69,7 @@ fn create_display(
|
||||||
display
|
display
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_storage(app_name: &str) -> Option<Box<dyn egui::app::Storage>> {
|
fn create_storage(app_name: &str) -> Option<Box<dyn epi::Storage>> {
|
||||||
if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", app_name) {
|
if let Some(proj_dirs) = directories_next::ProjectDirs::from("", "", app_name) {
|
||||||
let data_dir = proj_dirs.data_dir().to_path_buf();
|
let data_dir = proj_dirs.data_dir().to_path_buf();
|
||||||
if let Err(err) = std::fs::create_dir_all(&data_dir) {
|
if let Err(err) = std::fs::create_dir_all(&data_dir) {
|
||||||
|
@ -94,7 +91,7 @@ fn create_storage(app_name: &str) -> Option<Box<dyn egui::app::Storage>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run an egui app
|
/// Run an egui app
|
||||||
pub fn run(mut app: Box<dyn App>) -> ! {
|
pub fn run(mut app: Box<dyn epi::App>) -> ! {
|
||||||
let mut storage = create_storage(app.name());
|
let mut storage = create_storage(app.name());
|
||||||
|
|
||||||
if let Some(storage) = &mut storage {
|
if let Some(storage) = &mut storage {
|
||||||
|
@ -103,7 +100,7 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
|
|
||||||
let window_settings: Option<WindowSettings> = storage
|
let window_settings: Option<WindowSettings> = storage
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.and_then(|storage| egui::app::get_value(storage.as_ref(), WINDOW_KEY));
|
.and_then(|storage| epi::get_value(storage.as_ref(), WINDOW_KEY));
|
||||||
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
let event_loop = glutin::event_loop::EventLoop::with_user_event();
|
||||||
let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop);
|
let display = create_display(app.name(), window_settings, app.is_resizable(), &event_loop);
|
||||||
|
|
||||||
|
@ -114,7 +111,7 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
let mut ctx = egui::CtxRef::default();
|
let mut ctx = egui::CtxRef::default();
|
||||||
*ctx.memory() = storage
|
*ctx.memory() = storage
|
||||||
.as_mut()
|
.as_mut()
|
||||||
.and_then(|storage| egui::app::get_value(storage.as_ref(), EGUI_MEMORY_KEY))
|
.and_then(|storage| epi::get_value(storage.as_ref(), EGUI_MEMORY_KEY))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
app.setup(&ctx);
|
app.setup(&ctx);
|
||||||
|
|
||||||
|
@ -137,8 +134,8 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
));
|
));
|
||||||
|
|
||||||
ctx.begin_frame(input_state.raw.take());
|
ctx.begin_frame(input_state.raw.take());
|
||||||
let mut integration_context = egui::app::IntegrationContext {
|
let mut integration_context = epi::IntegrationContext {
|
||||||
info: egui::app::IntegrationInfo {
|
info: epi::IntegrationInfo {
|
||||||
web_info: None,
|
web_info: None,
|
||||||
cpu_usage: previous_frame_time,
|
cpu_usage: previous_frame_time,
|
||||||
seconds_since_midnight: Some(seconds_since_midnight()),
|
seconds_since_midnight: Some(seconds_since_midnight()),
|
||||||
|
@ -164,7 +161,7 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
{
|
{
|
||||||
let egui::app::AppOutput {
|
let epi::AppOutput {
|
||||||
quit,
|
quit,
|
||||||
window_size,
|
window_size,
|
||||||
pixels_per_point,
|
pixels_per_point,
|
||||||
|
@ -200,12 +197,12 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
if let Some(storage) = &mut storage {
|
if let Some(storage) = &mut storage {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if now - last_auto_save > app.auto_save_interval() {
|
if now - last_auto_save > app.auto_save_interval() {
|
||||||
egui::app::set_value(
|
epi::set_value(
|
||||||
storage.as_mut(),
|
storage.as_mut(),
|
||||||
WINDOW_KEY,
|
WINDOW_KEY,
|
||||||
&WindowSettings::from_display(&display),
|
&WindowSettings::from_display(&display),
|
||||||
);
|
);
|
||||||
egui::app::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory());
|
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory());
|
||||||
app.save(storage.as_mut());
|
app.save(storage.as_mut());
|
||||||
storage.flush();
|
storage.flush();
|
||||||
last_auto_save = now;
|
last_auto_save = now;
|
||||||
|
@ -227,12 +224,12 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
||||||
glutin::event::Event::LoopDestroyed => {
|
glutin::event::Event::LoopDestroyed => {
|
||||||
app.on_exit();
|
app.on_exit();
|
||||||
if let Some(storage) = &mut storage {
|
if let Some(storage) = &mut storage {
|
||||||
egui::app::set_value(
|
epi::set_value(
|
||||||
storage.as_mut(),
|
storage.as_mut(),
|
||||||
WINDOW_KEY,
|
WINDOW_KEY,
|
||||||
&WindowSettings::from_display(&display),
|
&WindowSettings::from_display(&display),
|
||||||
);
|
);
|
||||||
egui::app::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory());
|
epi::set_value(storage.as_mut(), EGUI_MEMORY_KEY, &*ctx.memory());
|
||||||
app.save(storage.as_mut());
|
app.save(storage.as_mut());
|
||||||
storage.flush();
|
storage.flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl FileStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui::app::Storage for FileStorage {
|
impl epi::Storage for FileStorage {
|
||||||
fn get_string(&self, key: &str) -> Option<String> {
|
fn get_string(&self, key: &str) -> Option<String> {
|
||||||
self.kv.get(key).cloned()
|
self.kv.get(key).cloned()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||||
|
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
serde = "1"
|
serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub use egui::{
|
pub use egui::{pos2, Srgba};
|
||||||
app::{App, WebInfo},
|
|
||||||
pos2, Srgba,
|
|
||||||
};
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -68,7 +65,7 @@ impl WebBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui::app::TextureAllocator for webgl::Painter {
|
impl epi::TextureAllocator for webgl::Painter {
|
||||||
fn alloc(&mut self) -> egui::TextureId {
|
fn alloc(&mut self) -> egui::TextureId {
|
||||||
self.alloc_user_texture()
|
self.alloc_user_texture()
|
||||||
}
|
}
|
||||||
|
@ -131,7 +128,7 @@ impl NeedRepaint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui::app::RepaintSignal for NeedRepaint {
|
impl epi::RepaintSignal for NeedRepaint {
|
||||||
fn request_repaint(&self) {
|
fn request_repaint(&self) {
|
||||||
self.0.store(true, SeqCst);
|
self.0.store(true, SeqCst);
|
||||||
}
|
}
|
||||||
|
@ -142,14 +139,14 @@ impl egui::app::RepaintSignal for NeedRepaint {
|
||||||
pub struct AppRunner {
|
pub struct AppRunner {
|
||||||
pub web_backend: WebBackend,
|
pub web_backend: WebBackend,
|
||||||
pub input: WebInput,
|
pub input: WebInput,
|
||||||
pub app: Box<dyn App>,
|
pub app: Box<dyn epi::App>,
|
||||||
pub needs_repaint: std::sync::Arc<NeedRepaint>,
|
pub needs_repaint: std::sync::Arc<NeedRepaint>,
|
||||||
pub storage: LocalStorage,
|
pub storage: LocalStorage,
|
||||||
pub last_save_time: f64,
|
pub last_save_time: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppRunner {
|
impl AppRunner {
|
||||||
pub fn new(web_backend: WebBackend, mut app: Box<dyn App>) -> Result<Self, JsValue> {
|
pub fn new(web_backend: WebBackend, mut app: Box<dyn epi::App>) -> Result<Self, JsValue> {
|
||||||
load_memory(&web_backend.ctx);
|
load_memory(&web_backend.ctx);
|
||||||
let storage = LocalStorage::default();
|
let storage = LocalStorage::default();
|
||||||
app.load(&storage);
|
app.load(&storage);
|
||||||
|
@ -185,9 +182,9 @@ impl AppRunner {
|
||||||
let raw_input = self.input.new_frame(canvas_size);
|
let raw_input = self.input.new_frame(canvas_size);
|
||||||
self.web_backend.begin_frame(raw_input);
|
self.web_backend.begin_frame(raw_input);
|
||||||
|
|
||||||
let mut integration_context = egui::app::IntegrationContext {
|
let mut integration_context = epi::IntegrationContext {
|
||||||
info: egui::app::IntegrationInfo {
|
info: epi::IntegrationInfo {
|
||||||
web_info: Some(WebInfo {
|
web_info: Some(epi::WebInfo {
|
||||||
web_location_hash: location_hash().unwrap_or_default(),
|
web_location_hash: location_hash().unwrap_or_default(),
|
||||||
}),
|
}),
|
||||||
cpu_usage: self.web_backend.previous_frame_time,
|
cpu_usage: self.web_backend.previous_frame_time,
|
||||||
|
@ -206,7 +203,7 @@ impl AppRunner {
|
||||||
handle_output(&egui_output);
|
handle_output(&egui_output);
|
||||||
|
|
||||||
{
|
{
|
||||||
let egui::app::AppOutput {
|
let epi::AppOutput {
|
||||||
quit: _, // Can't quit a web page
|
quit: _, // Can't quit a web page
|
||||||
window_size: _, // Can't resize a web page
|
window_size: _, // Can't resize a web page
|
||||||
pixels_per_point: _, // Can't zoom from within the app (we respect the web browser's zoom level)
|
pixels_per_point: _, // Can't zoom from within the app (we respect the web browser's zoom level)
|
||||||
|
@ -223,7 +220,7 @@ impl AppRunner {
|
||||||
|
|
||||||
/// Install event listeners to register different input events
|
/// Install event listeners to register different input events
|
||||||
/// and starts running the given app.
|
/// and starts running the given app.
|
||||||
pub fn start(canvas_id: &str, app: Box<dyn App>) -> Result<AppRunnerRef, JsValue> {
|
pub fn start(canvas_id: &str, app: Box<dyn epi::App>) -> Result<AppRunnerRef, JsValue> {
|
||||||
let backend = WebBackend::new(canvas_id)?;
|
let backend = WebBackend::new(canvas_id)?;
|
||||||
let runner = AppRunner::new(backend, app)?;
|
let runner = AppRunner::new(backend, app)?;
|
||||||
start_runner(runner)
|
start_runner(runner)
|
||||||
|
|
|
@ -172,7 +172,7 @@ pub fn save_memory(ctx: &egui::Context) {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LocalStorage {}
|
pub struct LocalStorage {}
|
||||||
|
|
||||||
impl egui::app::Storage for LocalStorage {
|
impl epi::Storage for LocalStorage {
|
||||||
fn get_string(&self, key: &str) -> Option<String> {
|
fn get_string(&self, key: &str) -> Option<String> {
|
||||||
local_storage_get(key)
|
local_storage_get(key)
|
||||||
}
|
}
|
||||||
|
|
20
epi/Cargo.toml
Normal file
20
epi/Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
[package]
|
||||||
|
name = "epi"
|
||||||
|
version = "0.6.0"
|
||||||
|
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
|
||||||
|
description = "Backend-agnostic interface for writing apps using Egui"
|
||||||
|
edition = "2018"
|
||||||
|
homepage = "https://github.com/emilk/egui"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/emilk/egui"
|
||||||
|
categories = ["gui", "graphics"]
|
||||||
|
keywords = ["glium", "egui", "gui", "gamedev"]
|
||||||
|
include = [ "**/*.rs", "Cargo.toml"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
egui = { version = "0.6.0", path = "../egui" }
|
||||||
|
serde = { version = "1", optional = true }
|
||||||
|
serde_json = { version = "1", optional = true }
|
7
epi/README.md
Normal file
7
epi/README.md
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Egui app Programming Interface
|
||||||
|
|
||||||
|
Backend-agnostic interface for writing apps using Egui.
|
||||||
|
|
||||||
|
Egui is a GUI library, which can be plugged in to e.g. a game engine.
|
||||||
|
|
||||||
|
This crate provides a common interface for programming an app, using Egui, so you can then easily plug it in to a backend such as `egui_web` or `egui_glium`.
|
|
@ -1,11 +1,56 @@
|
||||||
//! Traits and helper for writing Egui apps.
|
//! Backend-agnostic interface for writing apps using Egui.
|
||||||
//!
|
//!
|
||||||
//! This module is very experimental, and you don't need to use it.
|
//! Egui is a GUI library, which can be plugged in to e.g. a game engine.
|
||||||
//!
|
//!
|
||||||
//! Egui can be used as a library, but you can also use it as a framework to write apps in.
|
//! This crate provides a common interface for programming an app, using Egui,
|
||||||
//! This module defined the `App` trait that can be implemented and used with the `egui_web` and `egui_glium` crates.
|
//! so you can then easily plug it in to a backend such as `egui_web` or `egui_glium`.
|
||||||
|
//!
|
||||||
|
//! This crate is primarily used by the `egui_web` and `egui_glium` crates.
|
||||||
|
|
||||||
// TODO: move egui/src/app.rs to own crate, e.g. egui_framework ?
|
#![cfg_attr(not(debug_assertions), deny(warnings))] // Forbid warnings in release builds
|
||||||
|
#![forbid(unsafe_code)]
|
||||||
|
#![warn(
|
||||||
|
clippy::all,
|
||||||
|
clippy::await_holding_lock,
|
||||||
|
clippy::dbg_macro,
|
||||||
|
clippy::doc_markdown,
|
||||||
|
clippy::empty_enum,
|
||||||
|
clippy::enum_glob_use,
|
||||||
|
clippy::exit,
|
||||||
|
clippy::filter_map_next,
|
||||||
|
clippy::fn_params_excessive_bools,
|
||||||
|
clippy::if_let_mutex,
|
||||||
|
clippy::imprecise_flops,
|
||||||
|
clippy::inefficient_to_string,
|
||||||
|
clippy::linkedlist,
|
||||||
|
clippy::lossy_float_literal,
|
||||||
|
clippy::macro_use_imports,
|
||||||
|
clippy::match_on_vec_items,
|
||||||
|
clippy::match_wildcard_for_single_variants,
|
||||||
|
clippy::mem_forget,
|
||||||
|
clippy::mismatched_target_os,
|
||||||
|
clippy::missing_errors_doc,
|
||||||
|
clippy::missing_safety_doc,
|
||||||
|
clippy::needless_borrow,
|
||||||
|
clippy::needless_continue,
|
||||||
|
clippy::needless_pass_by_value,
|
||||||
|
clippy::option_option,
|
||||||
|
clippy::pub_enum_variant_names,
|
||||||
|
clippy::rest_pat_in_fully_bound_structs,
|
||||||
|
clippy::todo,
|
||||||
|
clippy::unimplemented,
|
||||||
|
clippy::unnested_or_patterns,
|
||||||
|
clippy::verbose_file_reads,
|
||||||
|
future_incompatible,
|
||||||
|
missing_crate_level_docs,
|
||||||
|
missing_doc_code_examples,
|
||||||
|
// missing_docs,
|
||||||
|
nonstandard_style,
|
||||||
|
rust_2018_idioms,
|
||||||
|
unused_doc_comments,
|
||||||
|
)]
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Implement this trait to write apps that can be compiled both natively using the [`egui_glium`](https://crates.io/crates/egui_glium) crate,
|
/// 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.
|
/// and deployed as a web site using the [`egui_web`](https://crates.io/crates/egui_web) crate.
|
||||||
|
@ -15,9 +60,9 @@ pub trait App {
|
||||||
|
|
||||||
/// Background color for the app, e.g. what is sent to `gl.clearColor`.
|
/// Background color for the app, e.g. what is sent to `gl.clearColor`.
|
||||||
/// This is the background of your windows if you don't set a central panel.
|
/// This is the background of your windows if you don't set a central panel.
|
||||||
fn clear_color(&self) -> crate::Rgba {
|
fn clear_color(&self) -> egui::Rgba {
|
||||||
// NOTE: a bright gray makes the shadows of the windows look weird.
|
// NOTE: a bright gray makes the shadows of the windows look weird.
|
||||||
crate::Srgba::from_rgb(12, 12, 12).into()
|
egui::Srgba::from_rgb(12, 12, 12).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called once on start. Allows you to restore state.
|
/// Called once on start. Allows you to restore state.
|
||||||
|
@ -37,7 +82,7 @@ pub trait App {
|
||||||
/// Called once before the first frame.
|
/// Called once before the first frame.
|
||||||
/// Allows you to do setup code and to call `ctx.set_fonts()`.
|
/// Allows you to do setup code and to call `ctx.set_fonts()`.
|
||||||
/// Optional.
|
/// Optional.
|
||||||
fn setup(&mut self, _ctx: &crate::CtxRef) {}
|
fn setup(&mut self, _ctx: &egui::CtxRef) {}
|
||||||
|
|
||||||
/// Returns true if this app window should be resizable.
|
/// Returns true if this app window should be resizable.
|
||||||
fn is_resizable(&self) -> bool {
|
fn is_resizable(&self) -> bool {
|
||||||
|
@ -46,7 +91,7 @@ pub trait App {
|
||||||
|
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// 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`.
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
fn ui(&mut self, ctx: &crate::CtxRef, integration_context: &mut IntegrationContext<'_>);
|
fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut IntegrationContext<'_>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IntegrationContext<'a> {
|
pub struct IntegrationContext<'a> {
|
||||||
|
@ -92,7 +137,7 @@ pub struct AppOutput {
|
||||||
pub quit: bool,
|
pub quit: bool,
|
||||||
|
|
||||||
/// Set to some size to resize the outer window (e.g. glium window) to this size.
|
/// Set to some size to resize the outer window (e.g. glium window) to this size.
|
||||||
pub window_size: Option<crate::Vec2>,
|
pub window_size: Option<egui::Vec2>,
|
||||||
|
|
||||||
/// If the app sets this, change the `pixels_per_point` of Egui to this next frame.
|
/// If the app sets this, change the `pixels_per_point` of Egui to this next frame.
|
||||||
pub pixels_per_point: Option<f32>,
|
pub pixels_per_point: Option<f32>,
|
||||||
|
@ -100,18 +145,18 @@ pub struct AppOutput {
|
||||||
|
|
||||||
pub trait TextureAllocator {
|
pub trait TextureAllocator {
|
||||||
/// A.locate a new user texture.
|
/// A.locate a new user texture.
|
||||||
fn alloc(&mut self) -> crate::TextureId;
|
fn alloc(&mut self) -> egui::TextureId;
|
||||||
|
|
||||||
/// Set or change the pixels of a user texture.
|
/// Set or change the pixels of a user texture.
|
||||||
fn set_srgba_premultiplied(
|
fn set_srgba_premultiplied(
|
||||||
&mut self,
|
&mut self,
|
||||||
id: crate::TextureId,
|
id: egui::TextureId,
|
||||||
size: (usize, usize),
|
size: (usize, usize),
|
||||||
srgba_pixels: &[crate::Srgba],
|
srgba_pixels: &[egui::Srgba],
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Free the given texture.
|
/// Free the given texture.
|
||||||
fn free(&mut self, id: crate::TextureId);
|
fn free(&mut self, id: egui::TextureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RepaintSignal: Send + Sync {
|
pub trait RepaintSignal: Send + Sync {
|
||||||
|
@ -120,6 +165,8 @@ pub trait RepaintSignal: Send + Sync {
|
||||||
fn request_repaint(&self);
|
fn request_repaint(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// A place where you can store custom data in a way that persists when you restart the app.
|
/// A place where you can store custom data in a way that persists when you restart the app.
|
||||||
///
|
///
|
||||||
/// On the web this is backed by [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
|
/// On the web this is backed by [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
|
|
@ -11,6 +11,7 @@ crate-type = ["cdylib", "rlib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { path = "../egui", features = ["serde"] }
|
egui = { path = "../egui", features = ["serde"] }
|
||||||
egui_web = { path = "../egui_web" }
|
egui_web = { path = "../egui_web" }
|
||||||
|
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||||
image = { version = "0.23", default_features = false, features = ["jpeg", "png"] }
|
image = { version = "0.23", default_features = false, features = ["jpeg", "png"] }
|
||||||
js-sys = "0.3"
|
js-sys = "0.3"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
|
|
@ -48,14 +48,14 @@ impl Default for ExampleApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl egui::app::App for ExampleApp {
|
impl epi::App for ExampleApp {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"Egui Fetch Example"
|
"Egui Fetch Example"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// 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`.
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut egui::app::IntegrationContext) {
|
fn ui(&mut self, ctx: &egui::CtxRef, integration_context: &mut epi::IntegrationContext) {
|
||||||
if let Some(receiver) = &mut self.in_progress {
|
if let Some(receiver) = &mut self.in_progress {
|
||||||
// Are we there yet?
|
// Are we there yet?
|
||||||
if let Ok(result) = receiver.try_recv() {
|
if let Ok(result) = receiver.try_recv() {
|
||||||
|
@ -137,7 +137,7 @@ fn ui_url(ui: &mut egui::Ui, url: &mut String) -> Option<String> {
|
||||||
|
|
||||||
fn ui_resouce(
|
fn ui_resouce(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
integration_context: &mut egui::app::IntegrationContext,
|
integration_context: &mut epi::IntegrationContext,
|
||||||
tex_mngr: &mut TexMngr,
|
tex_mngr: &mut TexMngr,
|
||||||
resource: &Resource,
|
resource: &Resource,
|
||||||
) {
|
) {
|
||||||
|
@ -250,7 +250,7 @@ struct TexMngr {
|
||||||
impl TexMngr {
|
impl TexMngr {
|
||||||
fn texture(
|
fn texture(
|
||||||
&mut self,
|
&mut self,
|
||||||
integration_context: &mut egui::app::IntegrationContext,
|
integration_context: &mut epi::IntegrationContext,
|
||||||
url: &str,
|
url: &str,
|
||||||
image: &Image,
|
image: &Image,
|
||||||
) -> Option<egui::TextureId> {
|
) -> Option<egui::TextureId> {
|
||||||
|
|
Loading…
Reference in a new issue