mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 07:23:13 -04:00
Replace eframe::Frame commands and WindowInfo with egui (#3564)
* 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.
This commit is contained in:
@@ -65,7 +65,7 @@ impl eframe::App for MyApp {
|
||||
ui.label("Hello from immediate viewport");
|
||||
});
|
||||
|
||||
if ctx.input(|i| i.raw.viewport.close_requested) {
|
||||
if ctx.input(|i| i.viewport().close_requested) {
|
||||
// Tell parent viewport that we should not show next frame:
|
||||
self.show_immediate_viewport = false;
|
||||
ctx.request_repaint(); // make sure there is a next frame
|
||||
@@ -90,7 +90,7 @@ impl eframe::App for MyApp {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.label("Hello from deferred viewport");
|
||||
});
|
||||
if ctx.input(|i| i.raw.viewport.close_requested) {
|
||||
if ctx.input(|i| i.viewport().close_requested) {
|
||||
// Tell parent to close us.
|
||||
show_deferred_viewport.store(false, Ordering::Relaxed);
|
||||
ctx.request_repaint(); // make sure there is a next frame
|
||||
|
||||
Reference in New Issue
Block a user