#[warn(missing_docs)]
mod cursor;
mod event;
mod raw_handle;
mod system;
mod window;
mod windows;
pub use crate::raw_handle::*;
pub use cursor::*;
pub use event::*;
pub use system::*;
pub use window::*;
pub use windows::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
CursorEntered, CursorIcon, CursorLeft, CursorMoved, FileDragAndDrop, MonitorSelection,
ReceivedCharacter, Window, WindowDescriptor, WindowMode, WindowMoved, WindowPlugin,
WindowPosition, Windows,
};
}
use bevy_app::prelude::*;
use bevy_ecs::schedule::{IntoSystemDescriptor, SystemLabel};
impl Default for WindowPlugin {
fn default() -> Self {
WindowPlugin {
window: Default::default(),
add_primary_window: true,
exit_on_all_closed: true,
close_when_requested: true,
}
}
}
pub struct WindowPlugin {
pub window: WindowDescriptor,
pub add_primary_window: bool,
pub exit_on_all_closed: bool,
pub close_when_requested: bool,
}
impl Plugin for WindowPlugin {
fn build(&self, app: &mut App) {
app.add_event::<WindowResized>()
.add_event::<CreateWindow>()
.add_event::<WindowCreated>()
.add_event::<WindowClosed>()
.add_event::<WindowCloseRequested>()
.add_event::<RequestRedraw>()
.add_event::<CursorMoved>()
.add_event::<CursorEntered>()
.add_event::<CursorLeft>()
.add_event::<ReceivedCharacter>()
.add_event::<WindowFocused>()
.add_event::<WindowScaleFactorChanged>()
.add_event::<WindowBackendScaleFactorChanged>()
.add_event::<FileDragAndDrop>()
.add_event::<WindowMoved>()
.init_resource::<Windows>();
if self.add_primary_window {
app.world.send_event(CreateWindow {
id: WindowId::primary(),
descriptor: self.window.clone(),
});
}
if self.exit_on_all_closed {
app.add_system_to_stage(
CoreStage::PostUpdate,
exit_on_all_closed.after(ModifiesWindows),
);
}
if self.close_when_requested {
app.add_system(close_when_requested);
}
}
}
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
pub struct ModifiesWindows;