Skip to content

Commit

Permalink
Expose winit always_on_top
Browse files Browse the repository at this point in the history
  • Loading branch information
laundmo committed Nov 9, 2022
1 parent 1914a3f commit 44807db
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,17 @@ category = "UI (User Interface)"
wasm = true

# Window
[[example]]
name = "always_on_top"
path = "examples/window/always_on_top.rs"

[package.metadata.example.always_on_top]
name = "Always On Top"
description = "A Window which is always over other windows."
category = "Window"
wasm = false


[[example]]
name = "clear_color"
path = "examples/window/clear_color.rs"
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,12 @@ pub struct WindowDescriptor {
pub fit_canvas_to_parent: bool,
/// Specifies how the alpha channel of the textures should be handled during compositing.
pub alpha_mode: CompositeAlphaMode,
/// Sets the window to always be on top of other windows.
///
/// ## Platform-specific
/// - iOS / Android / Web: Unsupported.
/// - Linux (Wayland): Unsupported.
pub always_on_top: bool,
}

impl Default for WindowDescriptor {
Expand All @@ -994,6 +1000,7 @@ impl Default for WindowDescriptor {
canvas: None,
fit_canvas_to_parent: false,
alpha_mode: CompositeAlphaMode::Auto,
always_on_top: false,
}
}
}
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 @@ -72,7 +72,8 @@ impl WinitWindows {
}
.with_resizable(window_descriptor.resizable)
.with_decorations(window_descriptor.decorations)
.with_transparent(window_descriptor.transparent),
.with_transparent(window_descriptor.transparent)
.with_always_on_top(window_descriptor.always_on_top),
};

let constraints = window_descriptor.resize_constraints.check_constraints();
Expand Down
29 changes: 29 additions & 0 deletions examples/window/always_on_top.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Shows how to display a window in transparent mode.
//!
//! This feature works as expected depending on the platform. Please check the
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.WindowDescriptor.html#structfield.transparent)
//! for more details.

use bevy::prelude::*;

fn main() {
App::new()
.add_startup_system(setup)
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
// Set always_on_top to force the window to stay on top of other windows.
always_on_top: true,
..default()
},
..default()
}))
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/icon.png"),
..default()
});
}

0 comments on commit 44807db

Please sign in to comment.