-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Export the needed parts of Winit or add better utilities for centering a window. #4993
Comments
This is an excellent write-up, thanks! I agree with your analysis, and would like this to be simple. We get this question pretty regularly! |
@alice-i-cecile Thank you for the compliment. I feel honored to have gotten the "Good-First-Issue" tag, even for as little as its worth. |
I just had an afterthought, and this may or may not be a good idea, but it would be cool to control the window's visibility in a |
Ideally we reuse our standard visibility component for that, by making windows entities in #4530 :) |
I think that should use the default position assigned by the window manager, not use a centered position. |
@bjorn3 Then how would one make the window centered using a |
Maybe make |
That's exactly what mockersf suggested in #4999 (and I now implemented) |
I didn't see PR until after I commented. |
# Objective - Fixes bevyengine#4993 ## Solution - ~~Add `centered` property to `WindowDescriptor`~~ - Add `WindowPosition` enum - `WindowDescriptor.position` is now `WindowPosition` instead of `Option<Vec2>` - Add `center_window` function to `Window` ## Migration Guide - If using `WindowDescriptor`, replace `position: None` with `position: WindowPosition::Default` and `position: Some(vec2)` with `WindowPosition::At(vec2)`. I'm not sure if this is the best approach, so feel free to give any feedback. Also I'm not sure how `Option`s should be handled in `bevy_winit/src/lib.rs:161`. Also, on window creation we can't (or at least I couldn't) get `outer_size`, so this doesn't include decorations in calculations.
# Objective - Fixes bevyengine#4993 ## Solution - ~~Add `centered` property to `WindowDescriptor`~~ - Add `WindowPosition` enum - `WindowDescriptor.position` is now `WindowPosition` instead of `Option<Vec2>` - Add `center_window` function to `Window` ## Migration Guide - If using `WindowDescriptor`, replace `position: None` with `position: WindowPosition::Default` and `position: Some(vec2)` with `WindowPosition::At(vec2)`. I'm not sure if this is the best approach, so feel free to give any feedback. Also I'm not sure how `Option`s should be handled in `bevy_winit/src/lib.rs:161`. Also, on window creation we can't (or at least I couldn't) get `outer_size`, so this doesn't include decorations in calculations.
# Objective - Fixes bevyengine#4993 ## Solution - ~~Add `centered` property to `WindowDescriptor`~~ - Add `WindowPosition` enum - `WindowDescriptor.position` is now `WindowPosition` instead of `Option<Vec2>` - Add `center_window` function to `Window` ## Migration Guide - If using `WindowDescriptor`, replace `position: None` with `position: WindowPosition::Default` and `position: Some(vec2)` with `WindowPosition::At(vec2)`. I'm not sure if this is the best approach, so feel free to give any feedback. Also I'm not sure how `Option`s should be handled in `bevy_winit/src/lib.rs:161`. Also, on window creation we can't (or at least I couldn't) get `outer_size`, so this doesn't include decorations in calculations.
What problem does this solve or what need does it fill?
The problem this proposition intents to solve is making the task of centering a window easier.
It intents to remove the need to have dependencies for both
bevy
andwinit
.What solution would you like?
There's multiple ways to o about this.
First, the way I would not like to see, by re-exporting the required parts of
winit
to center a window:winit::dpi::
(::PhysicalPosition
) andwinit::event_loop
(::EventLoop
).Second, the solution I'd like to see implemented,
WindowDescriptor.position
when set toNone
should say that the window should be centered, then Bevy can take care of everything behind the scenes.This also allows all windows to be centered by default.
What alternative(s) have you considered?
The alternative I'm using is to have dependencies for both
winit
andbevy
in myCargo.toml
file:However, this seems inconvenient.
Additional Context
I believe centering the window could be delegated to
WindowDescriptor.position = None
or acenter()
method on aWindow
.Check out the current solution for centering a window in a Discord-thread on the Bevy Discord guild.
The text was updated successfully, but these errors were encountered: