summaryrefslogtreecommitdiff
path: root/engine/src/windowing/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/windowing/window.rs')
-rw-r--r--engine/src/windowing/window.rs55
1 files changed, 54 insertions, 1 deletions
diff --git a/engine/src/windowing/window.rs b/engine/src/windowing/window.rs
index 67554ca..8f95dc8 100644
--- a/engine/src/windowing/window.rs
+++ b/engine/src/windowing/window.rs
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use crate::ecs::Component;
+use crate::image::Image;
use crate::reflection::Reflection;
use crate::windowing::dpi::{PhysicalSize, Position, Size};
@@ -32,6 +33,8 @@ pub struct CreationAttributes
pub resizable: bool,
pub position: Option<Position>,
pub inner_size: Option<Size>,
+ pub icon: Option<Icon>,
+
pub x_visual_id: Option<XVisualID>,
// These do not have equivalents in winit::window::WindowAttributes
@@ -62,6 +65,8 @@ gen_creation_attrs_with_fn!(visible, bool);
gen_creation_attrs_with_fn!(resizable, bool);
gen_creation_attrs_with_fn!(position, Option<Position>);
gen_creation_attrs_with_fn!(inner_size, Option<Size>);
+gen_creation_attrs_with_fn!(icon, Option<Icon>);
+
gen_creation_attrs_with_fn!(x_visual_id, Option<XVisualID>);
gen_creation_attrs_with_fn!(cursor_visible, bool);
@@ -69,6 +74,7 @@ gen_creation_attrs_with_fn!(cursor_grab_mode, CursorGrabMode);
impl CreationAttributes
{
+ #[tracing::instrument(skip_all)]
pub(crate) fn into_window_attrs(self) -> winit::window::WindowAttributes
{
let mut window_attrs = winit::window::WindowAttributes::default()
@@ -82,7 +88,42 @@ impl CreationAttributes
None => None,
})
.with_visible(self.visible)
- .with_resizable(self.resizable);
+ .with_resizable(self.resizable)
+ .with_window_icon(match self.icon {
+ Some(Icon::Image(image)) => {
+ let image_dimens = image.dimensions();
+
+ let result = winit::window::Icon::from_rgba(
+ image.into_rgba8().into_bytes(),
+ image_dimens.width,
+ image_dimens.height,
+ );
+
+ if let Err(err) = &result {
+ tracing::error!("Invalid icon image: {err}");
+ }
+
+ result.ok()
+ }
+ #[cfg(windows)]
+ Some(Icon::WindowsResource(resource_name)) => {
+ use winit::platform::windows::IconExtWindows;
+
+ let result = winit::window::Icon::from_resource_name(
+ resource_name.as_ref(),
+ None,
+ );
+
+ if let Err(err) = &result {
+ tracing::error!(
+ "Invalid icon image in resource {resource_name}: {err}"
+ );
+ }
+
+ result.ok()
+ }
+ None => None,
+ });
window_attrs.position = self.position.map(Into::into);
window_attrs.inner_size = self.inner_size.map(Into::into);
@@ -116,6 +157,7 @@ impl Default for CreationAttributes
resizable: true,
position: None,
inner_size: None,
+ icon: None,
x_visual_id: None,
cursor_visible: true,
cursor_grab_mode: CursorGrabMode::None,
@@ -130,6 +172,17 @@ pub enum Fullscreen
Borderless,
}
+/// Window icon
+#[derive(Debug, Clone)]
+#[non_exhaustive]
+pub enum Icon
+{
+ Image(Image),
+
+ #[cfg(windows)]
+ WindowsResource(Cow<'static, str>),
+}
+
#[derive(Debug, Component, Clone, Copy)]
pub struct CreationReady;