bevy-website
bevy-website copied to clipboard
The 0.9 to 0.10 migration guide does not explain how to work with icons
The guide mentiones that WindowDescriptor are no longer used but it does not explain how to add/change icon of the app
This wasn't in the migration guide because it has not changed.
Bevy does not have a direct API for setting a window icon yet. You'll have to access it via the windowing library Bevy uses called winit
.
There's a (slightly outdated, but mostly functional) example of how to do it in the cheat book here.
I've got the following snippet working on my machine. Hope it helps!
fn set_window_icon(
new_windows: Query<Entity, Added<Window>>,
winit_windows: NonSend<WinitWindows>,
) {
for entity in &new_windows {
let winit_window = winit_windows.get_window(entity).unwrap();
let (icon_rgba, icon_width, icon_height) = {
let image = image::open("my_icon.png")
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
let rgba = image.into_raw();
(rgba, width, height)
};
let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height).unwrap();
winit_window.set_window_icon(Some(icon));
}
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_system(set_window_icon)
.run();
}
Still requires adding winit
(version 0.28) and image
to your Cargo.toml
Closing this as won't fix, since the method for setting the icon was not changed between 0.9 and 0.10.