Struct gate::AppContext
source · pub struct AppContext<A: AppAssetId> {
pub audio: Audio<A>,
/* private fields */
}
Expand description
Context passed to methods in App
.
Fields
audio: Audio<A>
Audio playback.
Implementations
sourceimpl<A: AppAssetId> AppContext<A>
impl<A: AppAssetId> AppContext<A>
sourcepub fn dims(&self) -> (f64, f64)
pub fn dims(&self) -> (f64, f64)
Returns the app (width, height), which are restricted by the min/max dimensions
specified in AppInfo
.
sourcepub fn cursor(&self) -> (f64, f64)
pub fn cursor(&self) -> (f64, f64)
Returns the mouse cursor (x, y) position in app coordinates.
The x coordinate lies in the range 0
to self.dims().0
.
The y coordinate lies in the range 0
to self.dims().1
.
sourcepub fn native_px(&self) -> f64
pub fn native_px(&self) -> f64
Returns the width of a native pixel, measured in “app pixels”.
This value will always be at most 1.
sourcepub fn native_px_align(&self, x: f64, y: f64) -> (f64, f64)
pub fn native_px_align(&self, x: f64, y: f64) -> (f64, f64)
Convenience method for aligning an (x, y)
position to the nearest native pixel boundaries.
This is typically used to align a camera position.
See also self.native_px()
.
sourcepub fn request_fullscreen(&mut self)
pub fn request_fullscreen(&mut self)
Requests the app to enter fullscreen mode.
Depending on the target and how this method is invoked, the app may or may not
actually enter fullscreen mode. When compiling to wasm32-unknown-unknown
and
running in a web browser, fullscreen requests can only be made successfully during
certain user input events, so invoking fullscreen during App.start
or App.advance
will likely fail.
sourcepub fn cancel_fullscreen(&mut self)
pub fn cancel_fullscreen(&mut self)
Requests the app to cancel fullscreen mode.
sourcepub fn is_fullscreen(&self) -> bool
pub fn is_fullscreen(&self) -> bool
Checks whether or not the app is currently in fullscreen mode.
This value will not change immediately after a call to request_fullscreen
or
cancel_fullscreen
.
sourcepub fn close(&mut self)
pub fn close(&mut self)
Closes the app entirely.
When compiling to wasm32-unknown-unknown
, the app may be resumed after it is closed
via invoking a JavaScript method.
Gets current cookie data.
NOTE: this API is likely to change change. Returns an empty array if cookie is not set or if not running in WebAssembly mode.
Writes cookie data.
NOTE: this API is likely to change change. Cookie can be used as lightweight save data when built in WebAssembly mode. Only writes persistent cookie data if built in WebAssembly mode. To use cookies, the readCookie and writeCookie functions must be passed into gate.js.