How to use set_position to center the window on the screen? #3859
-
I'm trying to center the window with the following code: let win = MainWindow::new().with_context(|| "Cannot create main window")?;
win.window().set_position(????); My question is how to specify the center position? Do I need to calculate the position manually? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Note that first of all, I think it's quite unusual for applications to position their window explicitly. It is generally better left to the window manager to choose a good starting location (which might take into account existing windows, current focus, mouse position, etc.). Exception might be when you're restoring the previous state of the application, or when the window is an alert that needs to be centered for attention. But to answer the question, yes you need to calculate the position manually. This will require using some private API to access the
|
Beta Was this translation helpful? Give feedback.
Note that first of all, I think it's quite unusual for applications to position their window explicitly. It is generally better left to the window manager to choose a good starting location (which might take into account existing windows, current focus, mouse position, etc.). Exception might be when you're restoring the previous state of the application, or when the window is an alert that needs to be centered for attention.
But to answer the question, yes you need to calculate the position manually. This will require using some private API to access the
winit
window and then using thatwinit
…