Skip to content

Commit

Permalink
Try #3105:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Nov 15, 2021
2 parents 94db017 + a9b5844 commit 685262d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ path = "examples/window/multiple_windows.rs"
name = "scale_factor_override"
path = "examples/window/scale_factor_override.rs"

[[example]]
name = "transparent_window"
path = "examples/window/transparent_window.rs"

[[example]]
name = "window_settings"
path = "examples/window/window_settings.rs"
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ pub struct WindowDescriptor {
pub cursor_visible: bool,
pub cursor_locked: bool,
pub mode: WindowMode,
/// Sets whether the background of the window should be transparent.
/// # Platform-specific
/// - iOS / Android / Web: Unsupported.
/// - OSX: Not working as expected.
pub transparent: bool,
#[cfg(target_arch = "wasm32")]
pub canvas: Option<String>,
}
Expand All @@ -554,6 +559,7 @@ impl Default for WindowDescriptor {
cursor_locked: false,
cursor_visible: true,
mode: WindowMode::Windowed,
transparent: false,
#[cfg(target_arch = "wasm32")]
canvas: None,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ impl WinitWindows {
}
}
.with_resizable(window_descriptor.resizable)
.with_decorations(window_descriptor.decorations),
.with_decorations(window_descriptor.decorations)
.with_transparent(window_descriptor.transparent),
};

let constraints = window_descriptor.resize_constraints.check_constraints();
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ Example | File | Description
`clear_color` | [`window/clear_color.rs`](./window/clear_color.rs) | Creates a solid color window
`multiple_windows` | [`window/multiple_windows.rs`](./window/multiple_windows.rs) | Creates two windows and cameras viewing the same mesh
`scale_factor_override` | [`window/scale_factor_override.rs`](./window/scale_factor_override.rs) | Illustrates how to customize the default window settings
`transparent_window` | [`window/transparent_window.rs`](./window/transparent_window.rs) | Illustrates making the window transparent and hiding the window decoration
`window_settings` | [`window/window_settings.rs`](./window/window_settings.rs) | Demonstrates customizing default window settings

# Platform-Specific Examples
Expand Down
32 changes: 32 additions & 0 deletions examples/window/transparent_window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// An example of how to display a window in transparent mode
/// [Documentation & Platform support.](https://github.com/bevyengine/bevy/blob/latest/crates/bevy_window/src/window.rs)
use bevy::{prelude::*, render::pass::ClearColor, window::WindowDescriptor};

fn main() {
App::new()
// ClearColor must have 0 alpha, otherwise some color will bleed through
.insert_resource(ClearColor(Color::NONE))
.insert_resource(WindowDescriptor {
// Setting `transparent` allows the `ClearColor`'s alpha value to take effect
transparent: true,
// Disabling window decorations to make it feel more like a widget than a window
decorations: false,
..Default::default()
})
.add_startup_system(setup)
.add_plugins(DefaultPlugins)
.run();
}

fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let texture_handle = asset_server.load("branding/icon.png");
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(SpriteBundle {
material: materials.add(texture_handle.into()),
..Default::default()
});
}

0 comments on commit 685262d

Please sign in to comment.