Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace eframe::Frame commands and WindowInfo with egui #3564

Merged
merged 36 commits into from
Nov 18, 2023

Conversation

emilk
Copy link
Owner

@emilk emilk commented Nov 17, 2023

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:

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 ViewportCommands.

@emilk emilk changed the title Small improvements for multi-viewports Replace eframe::Frame commands and WindowInfo with egui Nov 18, 2023
@emilk emilk added eframe Relates to epi and eframe egui labels Nov 18, 2023
@emilk emilk marked this pull request as ready for review November 18, 2023 18:01
@emilk emilk merged commit 1571027 into master Nov 18, 2023
35 checks passed
@emilk emilk deleted the emilk/viewport-improvements branch November 18, 2023 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant