mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
* Part of https://github.com/emilk/egui/issues/3556 ## In short You now almost never need to use `eframe::Frame` - instead use `ui.input(|i| i.viewport())` for information about the current viewport (native window), and use `ctx.send_viewport_cmd` to modify it. ## In detail This PR removes most commands from `eframe::Frame`, and replaces them with `ViewportCommand`. So `frame.close()` becomes `ctx.send_viewport_cmd(ViewportCommand::Close)`, etc. `frame.info().window_info` is now also gone, replaced with `ui.input(|i| i.viewport())`. `frame.info().native_pixels_per_point` is replaced with `ui.input(|i| i.raw.native_pixels_per_point)`. `RawInput` now contains one `ViewportInfo` for each viewport. Screenshots are taken with `ctx.send_viewport_cmd(ViewportCommand::Screenshots)` and are returned in `egui::Event` which you can check with: ``` ust ui.input(|i| { for event in &i.raw.events { if let egui::Event::Screenshot { viewport_id, image } = event { // handle it here } } }); ``` ### Motivation You no longer need to pass around the `&eframe::Frame` everywhere. This also opens the door for other integrations to use the same API of `ViewportCommand`s.
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
//! Demo-code for showing how egui is used.
|
|
//!
|
|
//! The demo-code is also used in benchmarks and tests.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
pub mod about;
|
|
pub mod code_editor;
|
|
pub mod code_example;
|
|
pub mod context_menu;
|
|
pub mod dancing_strings;
|
|
pub mod demo_app_windows;
|
|
pub mod drag_and_drop;
|
|
pub mod extra_viewport;
|
|
pub mod font_book;
|
|
pub mod highlighting;
|
|
pub mod layout_test;
|
|
pub mod misc_demo_window;
|
|
pub mod multi_touch;
|
|
pub mod paint_bezier;
|
|
pub mod painting;
|
|
pub mod password;
|
|
pub mod plot_demo;
|
|
pub mod scrolling;
|
|
pub mod sliders;
|
|
pub mod strip_demo;
|
|
pub mod table_demo;
|
|
pub mod tests;
|
|
pub mod text_edit;
|
|
pub mod text_layout;
|
|
pub mod toggle_switch;
|
|
pub mod widget_gallery;
|
|
pub mod window_options;
|
|
pub mod window_with_panels;
|
|
|
|
pub use {
|
|
about::About, demo_app_windows::DemoWindows, misc_demo_window::MiscDemoWindow,
|
|
widget_gallery::WidgetGallery,
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/// Something to view in the demo windows
|
|
pub trait View {
|
|
fn ui(&mut self, ui: &mut egui::Ui);
|
|
}
|
|
|
|
/// Something to view
|
|
pub trait Demo {
|
|
/// Is the demo enabled for this integraton?
|
|
fn is_enabled(&self, _ctx: &egui::Context) -> bool {
|
|
true
|
|
}
|
|
|
|
/// `&'static` so we can also use it as a key to store open/close state.
|
|
fn name(&self) -> &'static str;
|
|
|
|
/// Show windows, etc
|
|
fn show(&mut self, ctx: &egui::Context, open: &mut bool);
|
|
}
|