Set actual window icon on windows
This commit is contained in:
2 files changed
+63
-31
No files matched your search
@@ -6,5 +6,9 @@ edition = "2024"
|
||||
[dependencies]
|
||||
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]
|
||||
winresource = "0.1.31"
|
||||
+59
-31
@@ -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 JUMP_VEL: f32 = 600.0;
|
||||
|
||||
@@ -17,40 +23,62 @@ struct Player {
|
||||
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() {
|
||||
App::new()
|
||||
.add_plugins(
|
||||
DefaultPlugins
|
||||
.set(RenderPlugin {
|
||||
render_creation: RenderCreation::Automatic(WgpuSettings {
|
||||
backends: Some(
|
||||
#[cfg(target_os = "windows")]
|
||||
Backends::DX12,
|
||||
#[cfg(target_os = "linux")]
|
||||
Backends::VULKAN,
|
||||
#[cfg(target_os = "macos")]
|
||||
Backends::METAL,
|
||||
),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
})
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Berry Dash RS".into(),
|
||||
resize_constraints: WindowResizeConstraints {
|
||||
min_width: 800.0,
|
||||
min_height: 600.0,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}),
|
||||
let mut app = App::new();
|
||||
app.add_plugins(
|
||||
DefaultPlugins
|
||||
.set(RenderPlugin {
|
||||
render_creation: RenderCreation::Automatic(WgpuSettings {
|
||||
backends: Some(
|
||||
#[cfg(target_os = "windows")]
|
||||
Backends::DX12,
|
||||
#[cfg(target_os = "linux")]
|
||||
Backends::VULKAN,
|
||||
#[cfg(target_os = "macos")]
|
||||
Backends::METAL,
|
||||
),
|
||||
..default()
|
||||
}),
|
||||
)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, update_position)
|
||||
.run();
|
||||
..default()
|
||||
})
|
||||
.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Berry Dash RS".into(),
|
||||
resize_constraints: WindowResizeConstraints {
|
||||
min_width: 800.0,
|
||||
min_height: 600.0,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}),
|
||||
)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, update_position);
|
||||
|
||||
#[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>) {
|
||||
|
||||
Reference in new issue
Block a user