-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
use bevy::{prelude::*, winit::WinitWindows}; | ||
use winit::window::Icon; | ||
|
||
pub fn set_window_icon(windows: NonSend<WinitWindows>) { | ||
if let Ok(icon) = try_get_icon() { | ||
for window in windows.windows.values() { | ||
window.set_window_icon(Some(icon.clone())); | ||
} | ||
} | ||
} | ||
|
||
/// Try to get the icon from the assets directory. | ||
/// Will likely fail to find the file during devlopment, but | ||
/// should work correctly in the distributed release. | ||
fn try_get_icon() -> Result<Icon> { | ||
let (icon_rgba, icon_width, icon_height) = { | ||
let image = image::open( | ||
std::env::current_exe()? | ||
.parent() | ||
.unwrap() | ||
.join(PathBuf::from_iter(["assets", "images", "logo.png"])), | ||
)? | ||
.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)?; | ||
Ok(icon) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod db; | ||
mod dirs; | ||
pub mod icon; | ||
pub mod update; |