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",
|
||||
"rusttype",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -640,6 +639,7 @@ dependencies = [
|
|||
"egui_demo_lib",
|
||||
"egui_glium",
|
||||
"egui_web",
|
||||
"epi",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
|
@ -651,6 +651,7 @@ version = "0.6.0"
|
|||
dependencies = [
|
||||
"criterion",
|
||||
"egui",
|
||||
"epi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -661,6 +662,7 @@ dependencies = [
|
|||
"clipboard",
|
||||
"directories-next",
|
||||
"egui",
|
||||
"epi",
|
||||
"glium",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -672,6 +674,7 @@ name = "egui_web"
|
|||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"egui",
|
||||
"epi",
|
||||
"js-sys",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -686,12 +689,22 @@ version = "1.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "epi"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"egui",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example_web"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"egui",
|
||||
"egui_web",
|
||||
"epi",
|
||||
"image",
|
||||
"js-sys",
|
||||
"serde",
|
||||
|
|
|
@ -5,6 +5,7 @@ members = [
|
|||
"egui_glium",
|
||||
"egui_web",
|
||||
"egui",
|
||||
"epi",
|
||||
"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] Image support
|
||||
* [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
|
||||
rusttype = "0.9"
|
||||
serde = { version = "1", features = ["derive"], optional = true }
|
||||
serde_json = { version = "1", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["atomic_refcell", "default_fonts"]
|
||||
|
|
|
@ -79,7 +79,6 @@
|
|||
|
||||
pub mod align;
|
||||
mod animation_manager;
|
||||
pub mod app;
|
||||
pub mod containers;
|
||||
mod context;
|
||||
mod id;
|
||||
|
|
|
@ -9,8 +9,9 @@ edition = "2018"
|
|||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
egui = { path = "../egui", features = ["serde", "serde_json"] }
|
||||
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||
egui_demo_lib = { path = "../egui_demo_lib" }
|
||||
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
||||
# For compiling natively:
|
||||
|
|
|
@ -16,6 +16,7 @@ include = [ "**/*.rs", "Cargo.toml"]
|
|||
|
||||
[dependencies]
|
||||
egui = { version = "0.6.0", path = "../egui" }
|
||||
epi = { version = "0.6.0", path = "../epi" }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3", default-features = false }
|
||||
|
|
|
@ -171,7 +171,7 @@ impl FrameHistory {
|
|||
|
||||
/// 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).
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
|
@ -192,7 +192,7 @@ pub struct 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();
|
||||
|
||||
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
|
||||
.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 {
|
||||
"Egui Demo"
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde_json")]
|
||||
fn load(&mut self, storage: &dyn egui::app::Storage) {
|
||||
*self = egui::app::get_value(storage, egui::app::APP_KEY).unwrap_or_default()
|
||||
fn load(&mut self, storage: &dyn epi::Storage) {
|
||||
*self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde_json")]
|
||||
fn save(&mut self, storage: &mut dyn egui::app::Storage) {
|
||||
egui::app::set_value(storage, egui::app::APP_KEY, self);
|
||||
fn save(&mut self, storage: &mut dyn epi::Storage) {
|
||||
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
|
||||
.on_new_frame(ctx.input().time, integration_context.info.cpu_usage);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl ColorTest {
|
|||
pub fn ui(
|
||||
&mut self,
|
||||
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("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(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
bg_fill: Srgba,
|
||||
(left, right): (Srgba, Srgba),
|
||||
) {
|
||||
|
@ -226,7 +226,7 @@ impl ColorTest {
|
|||
fn tex_gradient(
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
label: &str,
|
||||
bg_fill: Srgba,
|
||||
gradient: &Gradient,
|
||||
|
@ -358,7 +358,7 @@ struct TextureManager(HashMap<Gradient, TextureId>);
|
|||
impl TextureManager {
|
||||
fn get(
|
||||
&mut self,
|
||||
tex_allocator: &mut dyn app::TextureAllocator,
|
||||
tex_allocator: &mut dyn epi::TextureAllocator,
|
||||
gradient: &Gradient,
|
||||
) -> TextureId {
|
||||
*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,
|
||||
ctx: &CtxRef,
|
||||
env: &DemoEnvironment,
|
||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
sidebar_ui: impl FnOnce(&mut Ui),
|
||||
) {
|
||||
if self.previous_link != env.link {
|
||||
|
@ -144,7 +144,7 @@ impl DemoWindows {
|
|||
&mut self,
|
||||
ctx: &CtxRef,
|
||||
env: &DemoEnvironment,
|
||||
tex_allocator: &mut Option<&mut dyn app::TextureAllocator>,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
) {
|
||||
let Self {
|
||||
open_windows,
|
||||
|
|
|
@ -16,7 +16,8 @@ include = [ "**/*.rs", "Cargo.toml"]
|
|||
chrono = { version = "0.4" }
|
||||
clipboard = "0.5"
|
||||
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"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
|
|
|
@ -2,15 +2,12 @@ use std::time::Instant;
|
|||
|
||||
use crate::{storage::WindowSettings, *};
|
||||
|
||||
pub use egui::{
|
||||
app::{self, App, Storage},
|
||||
Srgba,
|
||||
};
|
||||
pub use egui::Srgba;
|
||||
|
||||
const EGUI_MEMORY_KEY: &str = "egui";
|
||||
const WINDOW_KEY: &str = "window";
|
||||
|
||||
impl egui::app::TextureAllocator for Painter {
|
||||
impl epi::TextureAllocator for Painter {
|
||||
fn alloc(&mut self) -> egui::TextureId {
|
||||
self.alloc_user_texture()
|
||||
}
|
||||
|
@ -35,7 +32,7 @@ struct GliumRepaintSignal(
|
|||
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
||||
);
|
||||
|
||||
impl egui::app::RepaintSignal for GliumRepaintSignal {
|
||||
impl epi::RepaintSignal for GliumRepaintSignal {
|
||||
fn request_repaint(&self) {
|
||||
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
|
||||
}
|
||||
|
@ -72,7 +69,7 @@ fn create_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) {
|
||||
let data_dir = proj_dirs.data_dir().to_path_buf();
|
||||
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
|
||||
pub fn run(mut app: Box<dyn App>) -> ! {
|
||||
pub fn run(mut app: Box<dyn epi::App>) -> ! {
|
||||
let mut storage = create_storage(app.name());
|
||||
|
||||
if let Some(storage) = &mut storage {
|
||||
|
@ -103,7 +100,7 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
|||
|
||||
let window_settings: Option<WindowSettings> = storage
|
||||
.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 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();
|
||||
*ctx.memory() = storage
|
||||
.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();
|
||||
app.setup(&ctx);
|
||||
|
||||
|
@ -137,8 +134,8 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
|||
));
|
||||
|
||||
ctx.begin_frame(input_state.raw.take());
|
||||
let mut integration_context = egui::app::IntegrationContext {
|
||||
info: egui::app::IntegrationInfo {
|
||||
let mut integration_context = epi::IntegrationContext {
|
||||
info: epi::IntegrationInfo {
|
||||
web_info: None,
|
||||
cpu_usage: previous_frame_time,
|
||||
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,
|
||||
window_size,
|
||||
pixels_per_point,
|
||||
|
@ -200,12 +197,12 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
|||
if let Some(storage) = &mut storage {
|
||||
let now = Instant::now();
|
||||
if now - last_auto_save > app.auto_save_interval() {
|
||||
egui::app::set_value(
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&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());
|
||||
storage.flush();
|
||||
last_auto_save = now;
|
||||
|
@ -227,12 +224,12 @@ pub fn run(mut app: Box<dyn App>) -> ! {
|
|||
glutin::event::Event::LoopDestroyed => {
|
||||
app.on_exit();
|
||||
if let Some(storage) = &mut storage {
|
||||
egui::app::set_value(
|
||||
epi::set_value(
|
||||
storage.as_mut(),
|
||||
WINDOW_KEY,
|
||||
&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());
|
||||
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> {
|
||||
self.kv.get(key).cloned()
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ crate-type = ["cdylib", "rlib"]
|
|||
|
||||
[dependencies]
|
||||
egui = { version = "0.6.0", path = "../egui", features = ["serde"] }
|
||||
epi = { version = "0.6.0", path = "../epi", features = ["serde", "serde_json"] }
|
||||
js-sys = "0.3"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
pub use egui::{
|
||||
app::{App, WebInfo},
|
||||
pos2, Srgba,
|
||||
};
|
||||
pub use egui::{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 {
|
||||
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) {
|
||||
self.0.store(true, SeqCst);
|
||||
}
|
||||
|
@ -142,14 +139,14 @@ impl egui::app::RepaintSignal for NeedRepaint {
|
|||
pub struct AppRunner {
|
||||
pub web_backend: WebBackend,
|
||||
pub input: WebInput,
|
||||
pub app: Box<dyn App>,
|
||||
pub app: Box<dyn epi::App>,
|
||||
pub needs_repaint: std::sync::Arc<NeedRepaint>,
|
||||
pub storage: LocalStorage,
|
||||
pub last_save_time: f64,
|
||||
}
|
||||
|
||||
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);
|
||||
let storage = LocalStorage::default();
|
||||
app.load(&storage);
|
||||
|
@ -185,9 +182,9 @@ impl AppRunner {
|
|||
let raw_input = self.input.new_frame(canvas_size);
|
||||
self.web_backend.begin_frame(raw_input);
|
||||
|
||||
let mut integration_context = egui::app::IntegrationContext {
|
||||
info: egui::app::IntegrationInfo {
|
||||
web_info: Some(WebInfo {
|
||||
let mut integration_context = epi::IntegrationContext {
|
||||
info: epi::IntegrationInfo {
|
||||
web_info: Some(epi::WebInfo {
|
||||
web_location_hash: location_hash().unwrap_or_default(),
|
||||
}),
|
||||
cpu_usage: self.web_backend.previous_frame_time,
|
||||
|
@ -206,7 +203,7 @@ impl AppRunner {
|
|||
handle_output(&egui_output);
|
||||
|
||||
{
|
||||
let egui::app::AppOutput {
|
||||
let epi::AppOutput {
|
||||
quit: _, // Can't quit 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)
|
||||
|
@ -223,7 +220,7 @@ impl AppRunner {
|
|||
|
||||
/// Install event listeners to register different input events
|
||||
/// 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 runner = AppRunner::new(backend, app)?;
|
||||
start_runner(runner)
|
||||
|
|
|
@ -172,7 +172,7 @@ pub fn save_memory(ctx: &egui::Context) {
|
|||
#[derive(Default)]
|
||||
pub struct LocalStorage {}
|
||||
|
||||
impl egui::app::Storage for LocalStorage {
|
||||
impl epi::Storage for LocalStorage {
|
||||
fn get_string(&self, key: &str) -> Option<String> {
|
||||
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 module defined the `App` trait that can be implemented and used with the `egui_web` and `egui_glium` crates.
|
||||
//! 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`.
|
||||
//!
|
||||
//! 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,
|
||||
/// 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`.
|
||||
/// 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.
|
||||
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.
|
||||
|
@ -37,7 +82,7 @@ pub trait App {
|
|||
/// Called once before the first frame.
|
||||
/// Allows you to do setup code and to call `ctx.set_fonts()`.
|
||||
/// Optional.
|
||||
fn setup(&mut self, _ctx: &crate::CtxRef) {}
|
||||
fn setup(&mut self, _ctx: &egui::CtxRef) {}
|
||||
|
||||
/// Returns true if this app window should be resizable.
|
||||
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.
|
||||
/// 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> {
|
||||
|
@ -92,7 +137,7 @@ pub struct AppOutput {
|
|||
pub quit: bool,
|
||||
|
||||
/// 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.
|
||||
pub pixels_per_point: Option<f32>,
|
||||
|
@ -100,18 +145,18 @@ pub struct AppOutput {
|
|||
|
||||
pub trait TextureAllocator {
|
||||
/// 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.
|
||||
fn set_srgba_premultiplied(
|
||||
&mut self,
|
||||
id: crate::TextureId,
|
||||
id: egui::TextureId,
|
||||
size: (usize, usize),
|
||||
srgba_pixels: &[crate::Srgba],
|
||||
srgba_pixels: &[egui::Srgba],
|
||||
);
|
||||
|
||||
/// Free the given texture.
|
||||
fn free(&mut self, id: crate::TextureId);
|
||||
fn free(&mut self, id: egui::TextureId);
|
||||
}
|
||||
|
||||
pub trait RepaintSignal: Send + Sync {
|
||||
|
@ -120,6 +165,8 @@ pub trait RepaintSignal: Send + Sync {
|
|||
fn request_repaint(&self);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// 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).
|
|
@ -11,6 +11,7 @@ crate-type = ["cdylib", "rlib"]
|
|||
[dependencies]
|
||||
egui = { path = "../egui", features = ["serde"] }
|
||||
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"] }
|
||||
js-sys = "0.3"
|
||||
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 {
|
||||
"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(&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 {
|
||||
// Are we there yet?
|
||||
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(
|
||||
ui: &mut egui::Ui,
|
||||
integration_context: &mut egui::app::IntegrationContext,
|
||||
integration_context: &mut epi::IntegrationContext,
|
||||
tex_mngr: &mut TexMngr,
|
||||
resource: &Resource,
|
||||
) {
|
||||
|
@ -250,7 +250,7 @@ struct TexMngr {
|
|||
impl TexMngr {
|
||||
fn texture(
|
||||
&mut self,
|
||||
integration_context: &mut egui::app::IntegrationContext,
|
||||
integration_context: &mut epi::IntegrationContext,
|
||||
url: &str,
|
||||
image: &Image,
|
||||
) -> Option<egui::TextureId> {
|
||||
|
|
Loading…
Reference in a new issue