-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add icon to WindowDesciptor #1163
Conversation
This PR adds an optional icon to WindowDescriptor and updates `window_settings` example to use it.
This also includes minor refactoring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start, thanks
Future work would be to support changing the icon at runtime, although I'm not sure if winit supports that presently.
/// Creates an `Icon` from 32bpp RGBA data. | ||
/// | ||
/// The length of `rgba` must be divisible by 4, and `width * height` must equal | ||
/// `rgba.len() / 4`. Otherwise, this will icon will not be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// `rgba.len() / 4`. Otherwise, this will icon will not be used. | |
/// `rgba.len() / 4`. Otherwise, the icon will not be used. |
@@ -383,6 +404,8 @@ pub struct WindowDescriptor { | |||
pub cursor_visible: bool, | |||
pub cursor_locked: bool, | |||
pub mode: WindowMode, | |||
#[cfg(any(target_os = "windows", target_os = "linux"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd be happier to have the icon be silently ignored on platforms where it isn't supported.
In its current form this is a feature gate footgun which makes it less likely that applications would support e.g. darwin or android out of the gate.
Additionally, it seems reasonable that we might in future support making this change the website favicon, perhaps behind a feature gate
#[cfg(any(target_os = "windows", target_os = "linux"))] | |
/// The icon for the window. Only active on platforms which support it, which is currently Windows and X11 Linux. |
match winit::window::Icon::from_rgba(icon.rgba.clone(), icon.width, icon.height) { | ||
Ok(icon) => Some(icon), | ||
Err(bad_icon) => { | ||
println!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably use the tracing error!
macro
/// | ||
/// The length of `rgba` must be divisible by 4, and `width * height` must equal | ||
/// `rgba.len() / 4`. Otherwise, this will icon will not be used. | ||
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd support create an icon from any image type supported by the image
crate. I'm not sure which crate that support should live in, however.
@@ -8,6 +10,12 @@ fn main() { | |||
width: 500., | |||
height: 300., | |||
vsync: true, | |||
#[cfg(any(target_os = "windows", target_os = "linux"))] | |||
icon: Some(Icon::from_rgba( | |||
include_bytes!("bevy_icon.rgba").to_vec(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if this used Cow<'static, [u8]>
we could avoid the to_vec
, in case another backend supported &'static [u8]
icons for example
That being said, requiring the user to create the Vec to match the winit API is also reasonable.
If possible, I think it would be nice if we could load icons using the asset system (ex: make the window descriptor take a |
I'm closing this due to inactivity and because I think this should use bevy_asset |
This PR adds an optional icon to WindowDescriptor and updates
window_settings
example to use it.Fixes #1031