egui
egui copied to clipboard
Incorrect maximize behaviour
Describe the bug
There are a few problem with maximizing a native window in eframe
.
- Every frame
eframe
provides aFrame
struct and inside it there is anIntegrationInfo
struct that you can retrieve with theinfo()
method. In the integration info, there is some data about the native window including a boolean that indicates if the window is maximized or not. this boolean doesn't change to true even if the window is maximized. - With the persist window option in
NativeOptions
Ive noticed when I start up the app with maximized set to true it does start that way, but instantly shrinks to the previous session's dimensions and if it was closed while maximized it does try to do the dimensions of a maximized window but not actually maximized and it becomes slightly offset.
To Reproduce Steps to reproduce the behavior: I dont know if it matters but here are my egui and eframe in my Cargo.toml
eframe = {version="0.23.0", features = ["persistence"]}
egui = {version="0.23.0", features = ["persistence", "serde"]}
- Set
presist_window
to true - Run the app
- Maximize the window
- Close the window
- Rerun the the app and the window state wont be persisted correctly
Expected behavior
When opening the window, if the presist_window
is true and the window was maximized in the last session it should be maximized again in the same monitor.
Also the WindowInfo
struct in the Frame
provided by eframe should have maximized set to true if the window is maximized.
Desktop:
- OS: Windows
probably related to #1517
Workaround: save the maximized state in you App struct and add a sentinel variable to indicate the first frame (not persisted, default false, set to true on the first frame). Then you can do:
if self.first_frame {
self.first_frame = false;
frame.set_maximized(self.persisted_maximized_state);
}
Fix coming in https://github.com/emilk/egui/pull/3601
Re-opened because of dead-lock: https://github.com/emilk/egui/pull/3612
https://github.com/emilk/egui/pull/3831 will fix this for Windows, but Linux and Mac still has the issue
Hmm, even without the deadlock and with the Windows fix, I think bug 2 in the issue is not addressed. persist_window
does not seem to save the maximized state in the ron file at all.
After closing a maximized window, this is what is saved:
"window": "(inner_position_pixels:Some((x:0.0,y:34.0)),outer_position_pixels:Some((x:-11.0,y:-11.0)),fullscreen:false,inner_size_points:Some((x:2560.0,y:1386.6666)))",
There is no info about maximization saved, which means the window will never be maximized on startup automatically. (In fact, for me, it causes a maximized-sized window to appear halfway off-screen on the wrong monitor).
The coordinates saved are also the ones of the maximized window. I think for consistent and nice behavior, the state should persist:
- the unmaximized position and size, i.e. what a window would restore its position and size to when pressing the restore button
- a flag whether the window was maximized
This way both the maximization state and even the size and position when un-maximizing the window are preserved, even across app restarts.
Maybe it makes sense to split bug 2 out into its own issue, since it's more a feature request than a bug?