Files
games/crates/engines/engine-v1-common/src/quit.rs

43 lines
1.2 KiB
Rust

// file: crates/engines/engine-v1-common/src/quit.rs
// version: 1
/// Origin of a platform-independent request to leave the current game runtime.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum QuitSource {
/// The operating-system or window manager requested the window to close.
WindowClose,
/// The Desktop Escape key requested leaving the runtime.
Escape,
/// The platform-native Back action requested leaving the runtime.
PlatformBack,
}
/// Decision returned by a game when the runtime requests to leave.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum QuitDecision {
/// Leave the current runtime immediately.
Exit,
/// Keep the runtime active after the game handled the request.
Continue,
}
/// Platform-independent quit request delivered to a game.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct QuitRequest {
source: QuitSource,
}
impl QuitRequest {
/// Creates a quit request from the supplied source.
#[must_use]
pub const fn new(source: QuitSource) -> Self {
return Self { source };
}
/// Returns the physical or platform-level source of the request.
#[must_use]
pub const fn source(self) -> QuitSource {
return self.source;
}
}