1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 21:00:03 -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:
Emil Ernerfeldt
2023-11-18 19:27:53 +01:00
committed by GitHub
parent 3e37e9dfc7
commit 1571027556
29 changed files with 905 additions and 915 deletions

View File

@@ -49,7 +49,6 @@ impl AppRunner {
},
system_theme,
cpu_usage: None,
native_pixels_per_point: Some(super::native_pixels_per_point()),
};
let storage = LocalStorage::default();
@@ -78,7 +77,6 @@ impl AppRunner {
let frame = epi::Frame {
info,
output: Default::default(),
storage: Some(Box::new(storage)),
#[cfg(feature = "glow")]
@@ -114,6 +112,7 @@ impl AppRunner {
};
runner.input.raw.max_texture_side = Some(runner.painter.max_texture_side());
runner.input.raw.native_pixels_per_point = Some(super::native_pixels_per_point());
Ok(runner)
}
@@ -192,17 +191,19 @@ impl AppRunner {
if viewport_output.len() > 1 {
log::warn!("Multiple viewports not yet supported on the web");
}
// TODO(emilk): handle some of the command in `viewport_output`, like setting the title and icon?
for viewport_output in viewport_output.values() {
for command in &viewport_output.commands {
// TODO(emilk): handle some of the commands
log::warn!(
"Unhandled egui viewport command: {command:?} - not implemented in web backend"
);
}
}
self.handle_platform_output(platform_output);
self.textures_delta.append(textures_delta);
let clipped_primitives = self.egui_ctx.tessellate(shapes, pixels_per_point);
{
let app_output = self.frame.take_app_output();
let epi::backend::AppOutput {} = app_output;
}
self.frame.info.cpu_usage = Some((now_sec() - frame_start) as f32);
clipped_primitives