mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> - I fixed the TODO to use the `log` crate instead of `eprintln` - Set the rust-version in the `scripts/check.sh` to the same as egui is on - I made xtask use anyhow to remove some unwraps * [x] I have followed the instructions in the PR template
85 lines
2.6 KiB
Rust
85 lines
2.6 KiB
Rust
//! Demo app for egui
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
|
#![allow(clippy::never_loop)] // False positive
|
|
|
|
// When compiling natively:
|
|
fn main() -> eframe::Result {
|
|
for arg in std::env::args().skip(1) {
|
|
match arg.as_str() {
|
|
"--profile" => {
|
|
#[cfg(feature = "puffin")]
|
|
start_puffin_server();
|
|
|
|
#[cfg(not(feature = "puffin"))]
|
|
panic!("Unknown argument: {arg} - you need to enable the 'puffin' feature to use this.");
|
|
}
|
|
|
|
_ => {
|
|
panic!("Unknown argument: {arg}");
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
// Silence wgpu log spam (https://github.com/gfx-rs/wgpu/issues/3206)
|
|
let mut rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| {
|
|
if cfg!(debug_assertions) {
|
|
"debug".to_owned()
|
|
} else {
|
|
"info".to_owned()
|
|
}
|
|
});
|
|
for loud_crate in ["naga", "wgpu_core", "wgpu_hal"] {
|
|
if !rust_log.contains(&format!("{loud_crate}=")) {
|
|
rust_log += &format!(",{loud_crate}=warn");
|
|
}
|
|
}
|
|
std::env::set_var("RUST_LOG", rust_log);
|
|
}
|
|
|
|
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
|
|
|
let options = eframe::NativeOptions {
|
|
viewport: egui::ViewportBuilder::default()
|
|
.with_inner_size([1280.0, 1024.0])
|
|
.with_drag_and_drop(true),
|
|
|
|
#[cfg(feature = "wgpu")]
|
|
renderer: eframe::Renderer::Wgpu,
|
|
|
|
..Default::default()
|
|
};
|
|
eframe::run_native(
|
|
"egui demo app",
|
|
options,
|
|
Box::new(|cc| Ok(Box::new(egui_demo_app::WrapApp::new(cc)))),
|
|
)
|
|
}
|
|
|
|
#[cfg(feature = "puffin")]
|
|
fn start_puffin_server() {
|
|
puffin::set_scopes_on(true); // tell puffin to collect data
|
|
|
|
match puffin_http::Server::new("127.0.0.1:8585") {
|
|
Ok(puffin_server) => {
|
|
log::info!("Run: cargo install puffin_viewer && puffin_viewer --url 127.0.0.1:8585");
|
|
|
|
std::process::Command::new("puffin_viewer")
|
|
.arg("--url")
|
|
.arg("127.0.0.1:8585")
|
|
.spawn()
|
|
.ok();
|
|
|
|
// We can store the server if we want, but in this case we just want
|
|
// it to keep running. Dropping it closes the server, so let's not drop it!
|
|
#[allow(clippy::mem_forget)]
|
|
std::mem::forget(puffin_server);
|
|
}
|
|
Err(err) => {
|
|
log::error!("Failed to start puffin server: {err}");
|
|
}
|
|
};
|
|
}
|