//! This example illustrates how have a mouse's clicks/wheel/movement etc fall through the spawned transparent window to a window below.1//! If you build this, and hit 'P' it should toggle on/off the mouse's passthrough.2//! Note: this example will not work on following platforms: iOS / Android / Web / X11. Window fall through is not supported there.34use bevy::{prelude::*, window::CursorOptions};56fn main() {7App::new()8.insert_resource(ClearColor(Color::NONE)) // Use a transparent window, to make effects obvious.9.add_plugins(DefaultPlugins.set(WindowPlugin {10primary_window: Some(Window {11// Set the window's parameters, note we're setting the window to always be on top.12transparent: true,13decorations: true,14window_level: bevy::window::WindowLevel::AlwaysOnTop,15..default()16}),17..default()18}))19.add_systems(Startup, setup)20.add_systems(Update, toggle_mouse_passthrough) // This allows us to hit 'P' to toggle on/off the mouse's passthrough21.run();22}2324fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {25// UI camera26commands.spawn(Camera2d);27// Text with one span28commands.spawn((29// Accepts a `String` or any type that converts into a `String`, such as `&str`30Text::new("Hit 'P' then scroll/click around!"),31TextFont {32font: asset_server.load("fonts/FiraSans-Bold.ttf"),33font_size: 83.0, // Nice and big so you can see it!34..default()35},36// Set the style of the TextBundle itself.37Node {38position_type: PositionType::Absolute,39bottom: px(5),40right: px(10),41..default()42},43));44}45// A simple system to handle some keyboard input and toggle on/off the hit test.46fn toggle_mouse_passthrough(47keyboard_input: Res<ButtonInput<KeyCode>>,48mut cursor_options: Single<&mut CursorOptions>,49) {50if keyboard_input.just_pressed(KeyCode::KeyP) {51cursor_options.hit_test = !cursor_options.hit_test;52}53}545556