Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to egui 0.22 #137

Merged
merged 4 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
435 changes: 331 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions puffin_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,28 @@ include = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
egui = { version = "0.21.0", default-features = false, features = ["default_fonts"] }
egui = { version = "0.22.0", default-features = false, features = [
"default_fonts",
] }
indexmap = { version = "1.9.1", features = ["serde"] }
instant = "0.1"
natord = "1.0.9"
once_cell = "1.7"
puffin = { version = "0.15.0", path = "../puffin", features = ["packing"] }
serde = { version = "1.0", features = ["derive"], optional = true }
time = { version = "0.3.17", default-features = false, features = [ "formatting", "macros" ] }
time = { version = "0.3.17", default-features = false, features = [
"formatting",
"macros",
] }
vec1 = "1.8"

[dev-dependencies]
eframe = { version = "0.21.0", default-features = false, features = ["persistence", "glow", "default_fonts"] }
eframe = { version = "0.22.0", default-features = false, features = [
"default_fonts",
"glow",
"persistence",
] }

# Enable example when this dependency updated to egui 0.20
# Enable example when this dependency is updated to egui 0.22
# egui-macroquad = "0.12.0"
# macroquad = "0.3"
14 changes: 10 additions & 4 deletions puffin_egui/examples/eframe.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use eframe::egui;

fn main() {
fn main() -> eframe::Result<()> {
puffin::set_scopes_on(true); // Remember to call this, or puffin will be disabled!

let native_options = Default::default();
let _ = eframe::run_native(
eframe::run_native(
"puffin egui eframe",
native_options,
Box::new(|_cc| Box::<ExampleApp>::default()),
);
)
}

#[derive(Default)]
Expand All @@ -17,10 +17,16 @@ pub struct ExampleApp {
}

impl eframe::App for ExampleApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
puffin::profile_function!();
puffin::GlobalProfiler::lock().new_frame(); // call once per frame!

egui::CentralPanel::default().show(ctx, |ui| {
if ui.button("Quit").clicked() {
frame.close()
}
});

puffin_egui::profiler_window(ctx);

// Give us something to inspect:
Expand Down
10 changes: 5 additions & 5 deletions puffin_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/EmbarkStudios/puffin"
readme = "README.md"
categories = ["development-tools::profiling", "gui"]
keywords = ["profiler", "instrumentation", "gamedev"]
include = ["**/*.rs", "Cargo.toml", "README.md"]
include = ["**/*.rs", "Cargo.toml", "README.md", "icon.png"]

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -26,14 +26,14 @@ puffin = { version = "0.15.0", path = "../puffin", features = [
puffin_http = { version = "0.12.0", path = "../puffin_http" }

argh = "0.1"
eframe = { version = "0.21.0", default-features = false, features = [
"persistence",
"glow",
eframe = { version = "0.22.0", default-features = false, features = [
"default_fonts",
"glow",
"persistence",
] }
log = "0.4"
rfd = "0.10.0"
simple_logger = "2.1"
env_logger = "0.10"

# native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions puffin_viewer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Use [`puffin_http`](https://github.com/EmbarkStudios/puffin/tree/main/puffin_htt
cargo install puffin_viewer
puffin_viewer --url 127.0.0.1:8585
```

The puffin icon is based on [a photo by Richard Bartz](https://en.wikipedia.org/wiki/File:Papageitaucher_Fratercula_arctica.jpg).
Binary file added puffin_viewer/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 1 addition & 26 deletions puffin_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,29 +333,4 @@ impl eframe::App for PuffinViewer {
// When compiling for web:

#[cfg(target_arch = "wasm32")]
use eframe::wasm_bindgen::{self, prelude::*};

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub struct WebHandle {
_handle: eframe::web::AppRunnerRef,
}

/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
/// It loads the app, installs some callbacks, then returns.
/// You can add more callbacks like this if you want to call in to your code.
#[cfg(target_arch = "wasm32")]
#[allow(clippy::unused_unit)]
#[wasm_bindgen]
pub async fn start(canvas_id: &str) -> Result<WebHandle, eframe::wasm_bindgen::JsValue> {
puffin::set_scopes_on(true); // quiet warning in `puffin_egui`.
let web_options = eframe::WebOptions::default();
eframe::start_web(
canvas_id,
web_options,
Box::new(|_cc| Box::new(PuffinViewer::new(Source::None))),
)
.await
.map(|handle| WebHandle { _handle: handle })
}
mod web;
12 changes: 6 additions & 6 deletions puffin_viewer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(not(target_arch = "wasm32"))]
fn main() {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).

/// puffin profile viewer.
///
/// Can either connect remotely to a puffin server
Expand All @@ -29,12 +31,6 @@ fn main() {

let opt: Arguments = argh::from_env();

simple_logger::SimpleLogger::new()
.with_level(log::LevelFilter::Info)
.without_timestamps()
.init()
.ok();

puffin::set_scopes_on(true); // so we can profile ourselves

let source = if let Some(file) = opt.file {
Expand All @@ -51,6 +47,10 @@ fn main() {
};

let native_options = eframe::NativeOptions {
app_id: Some("puffin_viewer".to_owned()),
icon_data: Some(
eframe::IconData::try_from_png_bytes(include_bytes!("../icon.png")).unwrap(),
),
drag_and_drop_support: true,
..Default::default()
};
Expand Down
26 changes: 26 additions & 0 deletions puffin_viewer/src/web.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use eframe::wasm_bindgen::{self, prelude::*};

/// This is the entry-point for all the web-assembly.
/// This is called once from the HTML.
/// It loads the app, installs some callbacks, then returns.
/// You can add more callbacks like this if you want to call in to your code.
#[allow(clippy::unused_unit)]
#[wasm_bindgen]
pub async fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
puffin::set_scopes_on(true); // quiet warning in `puffin_egui`.

// Redirect [`log`] message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

let web_options = eframe::WebOptions::default();
let runner = eframe::WebRunner::new();
runner
.start(
canvas_id,
web_options,
Box::new(|_cc| Box::new(crate::PuffinViewer::new(crate::Source::None))),
)
.await?;

Ok(())
}