Set actual window icon on windows

This commit is contained in:
Lncvrt committed 2026-03-23 21:41:30 -07:00
1 parent 5ba37fe26d
commit dcf241a12b
2 files changed
+36 -4

No files matched your search

+4
View File
@@ -6,5 +6,9 @@ edition = "2024"
[dependencies] [dependencies]
bevy = "0.18.1" bevy = "0.18.1"
[target.'cfg(target_os = "windows")'.dependencies]
image = "0.25.10"
winit = "0.30.13"
[target.'cfg(target_os = "windows")'.build-dependencies] [target.'cfg(target_os = "windows")'.build-dependencies]
winresource = "0.1.31" winresource = "0.1.31"
+32 -4
View File
@@ -7,6 +7,12 @@ use bevy::{
}, },
}; };
#[cfg(target_os = "windows")]
use {
bevy::{ecs::system::NonSendMarker, winit::WINIT_WINDOWS},
winit::window::Icon,
};
const GRAVITY: f32 = -1800.0; const GRAVITY: f32 = -1800.0;
const JUMP_VEL: f32 = 600.0; const JUMP_VEL: f32 = 600.0;
@@ -17,9 +23,27 @@ struct Player {
on_ground: bool, on_ground: bool,
} }
#[cfg(target_os = "windows")]
fn set_window_icon(_marker: NonSendMarker) {
let (icon_rgba, icon_width, icon_height) = {
let image = image::open("assets/Icon.png")
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
(image.into_raw(), width, height)
};
let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height).unwrap();
WINIT_WINDOWS.with_borrow(|winit_windows| {
for window in winit_windows.windows.values() {
window.set_window_icon(Some(icon.clone()));
}
});
}
fn main() { fn main() {
App::new() let mut app = App::new();
.add_plugins( app.add_plugins(
DefaultPlugins DefaultPlugins
.set(RenderPlugin { .set(RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings { render_creation: RenderCreation::Automatic(WgpuSettings {
@@ -49,8 +73,12 @@ fn main() {
}), }),
) )
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems(Update, update_position) .add_systems(Update, update_position);
.run();
#[cfg(target_os = "windows")]
app.add_systems(Startup, set_window_icon);
app.run();
} }
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) { fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {