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

Add icon to WindowDesciptor #1163

Closed
wants to merge 3 commits into from
Closed

Add icon to WindowDesciptor #1163

wants to merge 3 commits into from

Conversation

goodbadwolf
Copy link

This PR adds an optional icon to WindowDescriptor and updates
window_settings example to use it.

Fixes #1031

This PR adds an optional icon to WindowDescriptor and updates
`window_settings` example to use it.
This also includes minor refactoring
Copy link
Member

@DJMcNab DJMcNab left a 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// `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"))]
Copy link
Member

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

Suggested change
#[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!(
Copy link
Member

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 {
Copy link
Member

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(),
Copy link
Member

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.

@cart
Copy link
Member

cart commented Dec 30, 2020

If possible, I think it would be nice if we could load icons using the asset system (ex: make the window descriptor take a Handle<Texture>). But imo thats only really an option if we can set the winit icon after creating the window. Otherwise we're blocking window construction (and various app startup / gpu allocations) on an image being loaded.

@Moxinilian Moxinilian added C-Enhancement A new feature A-Windowing Platform-agnostic interface layer to run your app in labels Jan 1, 2021
Base automatically changed from master to main February 19, 2021 20:44
@cart
Copy link
Member

cart commented Apr 30, 2021

I'm closing this due to inactivity and because I think this should use bevy_asset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Windowing Platform-agnostic interface layer to run your app in C-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A field in WindowDescriptor resource to set the window's icon ?
4 participants