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]
|
[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"
|
||||||
+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 GRAVITY: f32 = -1800.0;
|
||||||
const JUMP_VEL: f32 = 600.0;
|
const JUMP_VEL: f32 = 600.0;
|
||||||
|
|
||||||
@@ -17,40 +23,62 @@ 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 {
|
||||||
backends: Some(
|
backends: Some(
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
Backends::DX12,
|
Backends::DX12,
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
Backends::VULKAN,
|
Backends::VULKAN,
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
Backends::METAL,
|
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()
|
|
||||||
}),
|
|
||||||
..default()
|
..default()
|
||||||
}),
|
}),
|
||||||
)
|
..default()
|
||||||
.add_systems(Startup, setup)
|
})
|
||||||
.add_systems(Update, update_position)
|
.set(WindowPlugin {
|
||||||
.run();
|
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>) {
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, window: Query<&Window>) {
|
||||||
|
|||||||
Reference in new issue
Block a user