mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10: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:
@@ -221,14 +221,14 @@ fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {
|
||||
|
||||
ui.add_space(8.0);
|
||||
|
||||
if let Some(inner_rect) = ctx.input(|i| i.raw.viewport.inner_rect_px) {
|
||||
if let Some(inner_rect) = ctx.input(|i| i.viewport().inner_rect) {
|
||||
ui.label(format!(
|
||||
"Inner Rect: Pos: {:?}, Size: {:?}",
|
||||
inner_rect.min,
|
||||
inner_rect.size()
|
||||
));
|
||||
}
|
||||
if let Some(outer_rect) = ctx.input(|i| i.raw.viewport.outer_rect_px) {
|
||||
if let Some(outer_rect) = ctx.input(|i| i.viewport().outer_rect) {
|
||||
ui.label(format!(
|
||||
"Outer Rect: Pos: {:?}, Size: {:?}",
|
||||
outer_rect.min,
|
||||
@@ -258,12 +258,12 @@ fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {
|
||||
data.insert_temp(container_id.with("pixels_per_point"), tmp_pixels_per_point);
|
||||
});
|
||||
}
|
||||
egui::gui_zoom::zoom_with_keyboard_shortcuts(&ctx, None);
|
||||
egui::gui_zoom::zoom_with_keyboard_shortcuts(&ctx);
|
||||
|
||||
if ctx.viewport_id() != ctx.parent_viewport_id() {
|
||||
let parent = ctx.parent_viewport_id();
|
||||
if ui.button("Set parent pos 0,0").clicked() {
|
||||
ctx.send_viewport_command_to(
|
||||
ctx.send_viewport_cmd_to(
|
||||
parent,
|
||||
egui::ViewportCommand::OuterPosition(egui::pos2(0.0, 0.0)),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user