mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
* Closes https://github.com/emilk/egui/issues/3602 You can now zoom any egui app by pressing Cmd+Plus, Cmd+Minus or Cmd+0, just like in a browser. This will change the current `zoom_factor` (default 1.0) which is persisted in the egui memory, and is the same for all viewports. You can turn off the keyboard shortcuts with `ctx.options_mut(|o| o.zoom_with_keyboard = false);` `zoom_factor` can also be explicitly read/written with `ctx.zoom_factor()` and `ctx.set_zoom_factor()`. This redefines `pixels_per_point` as `zoom_factor * native_pixels_per_point`, where `native_pixels_per_point` is whatever is the native scale factor for the monitor that the current viewport is in. This adds some complexity to the interaction with winit, since we need to know the current `zoom_factor` in a lot of places, because all egui IO is done in ui points. I'm pretty sure this PR fixes a bunch of subtle bugs though that used to be in this code. `egui::gui_zoom::zoom_with_keyboard_shortcuts` is now gone, and is no longer needed, as this is now the default behavior. `Context::set_pixels_per_point` is still there, but it is recommended you use `Context::set_zoom_factor` instead.
77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
//! Demo app for egui
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
// When compiling natively:
|
|
fn main() -> Result<(), eframe::Error> {
|
|
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(|_| "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| 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) => {
|
|
eprintln!("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) => {
|
|
eprintln!("Failed to start puffin server: {err}");
|
|
}
|
|
};
|
|
}
|