mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40: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:
@@ -12,6 +12,8 @@ pub struct EguiGlow {
|
||||
pub egui_winit: egui_winit::State,
|
||||
pub painter: crate::Painter,
|
||||
|
||||
viewport_info: egui::ViewportInfo,
|
||||
|
||||
// output from the last update:
|
||||
shapes: Vec<egui::epaint::ClippedShape>,
|
||||
pixels_per_point: f32,
|
||||
@@ -43,6 +45,7 @@ impl EguiGlow {
|
||||
egui_ctx: Default::default(),
|
||||
egui_winit,
|
||||
painter,
|
||||
viewport_info: Default::default(),
|
||||
shapes: Default::default(),
|
||||
pixels_per_point,
|
||||
textures_delta: Default::default(),
|
||||
@@ -50,7 +53,8 @@ impl EguiGlow {
|
||||
}
|
||||
|
||||
pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) -> EventResponse {
|
||||
self.egui_winit.on_event(&self.egui_ctx, event)
|
||||
self.egui_winit
|
||||
.on_event(&self.egui_ctx, event, ViewportId::ROOT)
|
||||
}
|
||||
|
||||
/// Call [`Self::paint`] later to paint.
|
||||
@@ -71,7 +75,17 @@ impl EguiGlow {
|
||||
log::warn!("Multiple viewports not yet supported by EguiGlow");
|
||||
}
|
||||
for (_, ViewportOutput { commands, .. }) in viewport_output {
|
||||
egui_winit::process_viewport_commands(commands, window, true);
|
||||
let mut screenshot_requested = false;
|
||||
egui_winit::process_viewport_commands(
|
||||
&mut self.viewport_info,
|
||||
commands,
|
||||
window,
|
||||
true,
|
||||
&mut screenshot_requested,
|
||||
);
|
||||
if screenshot_requested {
|
||||
log::warn!("Screenshot not yet supported by EguiGlow");
|
||||
}
|
||||
}
|
||||
|
||||
self.egui_winit.handle_platform_output(
|
||||
|
||||
Reference in New Issue
Block a user