Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ default = [
"bevy_window",
"bevy_winit",
"custom_cursor",
"custom_window_icon",
"default_font",
"hdr",
"ktx2",
Expand Down Expand Up @@ -563,6 +564,9 @@ reflect_auto_register_static = ["bevy_internal/reflect_auto_register_static"]
# Enable winit custom cursor support
custom_cursor = ["bevy_internal/custom_cursor"]

# Enable winit custom window icon support
custom_window_icon = ["bevy_internal/custom_window_icon"]

# Experimental support for nodes that are ignored for UI layouting
ghost_nodes = ["bevy_internal/ghost_nodes"]

Expand Down Expand Up @@ -3772,6 +3776,7 @@ wasm = false
name = "window_settings"
path = "examples/window/window_settings.rs"
doc-scrape-examples = true
required-features = ["bevy_window", "bevy_winit"]

[package.metadata.example.window_settings]
name = "Window Settings"
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ reflect_documentation = ["bevy_reflect/documentation"]
# Enable custom cursor support
custom_cursor = ["bevy_window/custom_cursor", "bevy_winit/custom_cursor"]

# Enable custom icon support
custom_window_icon = ["bevy_window/custom_window_icon", "bevy_winit/custom_window_icon"]

# Experimental support for nodes that are ignored for UI layouting
ghost_nodes = ["bevy_ui/ghost_nodes"]

Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ serialize = ["serde", "bevy_ecs/serialize", "bevy_input/serialize"]
# Enable custom cursor support
custom_cursor = ["bevy_image", "bevy_asset"]

# Enable custom window icon support
custom_window_icon = ["bevy_image", "bevy_asset"]

# Platform Compatibility

## Allows access to the `std` crate. Enabling this feature will prevent compilation
Expand Down
17 changes: 17 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#[cfg(feature = "std")]
use alloc::format;
use alloc::{borrow::ToOwned, string::String};
#[cfg(feature = "custom_window_icon")]
use bevy_asset::Handle;
#[cfg(feature = "custom_window_icon")]
use bevy_image::Image;
use core::num::NonZero;

use bevy_ecs::{
Expand Down Expand Up @@ -776,6 +780,19 @@ impl Default for CursorOptions {
}
}

/// Icon data for a [`Window`].
#[derive(Component, Debug, Clone, Default)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(Component, Debug, Default, Clone)
)]
#[cfg(feature = "custom_window_icon")]
pub struct WindowIcon {
/// Handle to the asset to be read into the window icon.
pub handle: Handle<Image>,
}

/// Defines where a [`Window`] should be placed on the screen.
#[derive(Default, Debug, Clone, Copy, PartialEq)]
#[cfg_attr(
Expand Down
10 changes: 8 additions & 2 deletions crates/bevy_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ custom_cursor = [
"bytemuck",
]

custom_window_icon = [
"bevy_window/custom_window_icon",
"bevy_image",
"bevy_asset",
]

[dependencies]
# bevy
bevy_a11y = { path = "../bevy_a11y", version = "0.18.0-dev" }
Expand All @@ -52,9 +58,9 @@ bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev", default-fea
] }

# bevy optional
## used by custom_cursor
## used by custom_cursor and custom_window_icon
bevy_asset = { path = "../bevy_asset", version = "0.18.0-dev", optional = true }
## used by custom_cursor
## used by custom_cursor and custom_window_icon
bevy_image = { path = "../bevy_image", version = "0.18.0-dev", optional = true }
## used by custom_cursor
wgpu-types = { version = "26", optional = true }
Expand Down
36 changes: 36 additions & 0 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ use crate::{
winit_monitors::WinitMonitors,
};

#[cfg(feature = "custom_window_icon")]
use system::{changed_window_icon, changed_window_icon_asset, set_winit_window_icon};

pub mod accessibility;
mod converters;
mod cursor;
Expand All @@ -52,6 +55,9 @@ mod winit_config;
mod winit_monitors;
mod winit_windows;

#[cfg(feature = "custom_window_icon")]
mod winit_window_icon;

thread_local! {
/// Temporary storage of WinitWindows data to replace usage of `!Send` resources. This will be replaced with proper
/// storage of `!Send` data after issue #17667 is complete.
Expand Down Expand Up @@ -142,6 +148,12 @@ impl<T: Message> Plugin for WinitPlugin<T> {
// so we don't need to care about its ordering relative to `changed_windows`
changed_windows.ambiguous_with(exit_on_all_closed),
changed_cursor_options,
#[cfg(feature = "custom_window_icon")]
changed_window_icon,
#[cfg(feature = "custom_window_icon")]
changed_window_icon_asset,
#[cfg(feature = "custom_window_icon")]
set_winit_window_icon,
despawn_windows,
check_keyboard_focus_lost,
)
Expand Down Expand Up @@ -203,6 +215,28 @@ impl AppSendEvent for Vec<WindowEvent> {
}

/// The parameters of the [`create_windows`] system.
#[cfg(not(feature = "custom_window_icon"))]
pub type CreateWindowParams<'w, 's, F = ()> = (
Commands<'w, 's>,
Query<
'w,
's,
(
Entity,
&'static mut Window,
&'static CursorOptions,
Option<&'static RawHandleWrapperHolder>,
),
F,
>,
MessageWriter<'w, WindowCreated>,
ResMut<'w, WinitActionRequestHandlers>,
Res<'w, AccessibilityRequested>,
Res<'w, WinitMonitors>,
);

/// The parameters of the [`create_windows`] system.
#[cfg(feature = "custom_window_icon")]
pub type CreateWindowParams<'w, 's, F = ()> = (
Commands<'w, 's>,
Query<
Expand All @@ -212,6 +246,7 @@ pub type CreateWindowParams<'w, 's, F = ()> = (
Entity,
&'static mut Window,
&'static CursorOptions,
Option<&'static bevy_window::WindowIcon>,
Option<&'static RawHandleWrapperHolder>,
),
F,
Expand All @@ -220,6 +255,7 @@ pub type CreateWindowParams<'w, 's, F = ()> = (
ResMut<'w, WinitActionRequestHandlers>,
Res<'w, AccessibilityRequested>,
Res<'w, WinitMonitors>,
Res<'w, bevy_asset::Assets<bevy_image::Image>>, // qualified path used to avoid unused import warnings
);

/// The parameters of the [`create_monitors`] system.
Expand Down
Loading
Loading