Struct tetra::ContextBuilder

source ·
pub struct ContextBuilder { /* private fields */ }
Expand description

Settings that can be configured when starting up a game.

Serde

Serialization and deserialization of this type (via Serde) can be enabled via the serde_support feature.

Note that the available settings could change between releases of Tetra (semver permitting). If you need a config file schema that will be stable in the long term, consider making your own and then mapping it to Tetra’s API, rather than relying on ContextBuilder to not change.

Implementations§

source§

impl ContextBuilder

source

pub fn new<S>(title: S, window_width: i32, window_height: i32) -> ContextBuilderwhere S: Into<String>,

Create a new ContextBuilder, with a title and window size.

source

pub fn title<S>(&mut self, title: S) -> &mut ContextBuilderwhere S: Into<String>,

Sets the title of the window.

Defaults to "Tetra".

source

pub fn size(&mut self, width: i32, height: i32) -> &mut ContextBuilder

Sets the size of the window.

Defaults to 1280 by 720.

source

pub fn vsync(&mut self, vsync: bool) -> &mut ContextBuilder

Enables or disables vsync.

Setting this flag does not guarantee that the requested vsync mode will be used - some platforms do not support vsync, and others enforce vsync. If you want to find out which vsync mode was actually chosen, you can call window::is_vsync_enabled.

Defaults to true.

source

pub fn fps_limit(&mut self, fps_limit: bool) -> &mut ContextBuilder

Enables or disables the 1000 FPS limit.

The framework will sleep for 1 millisecond on the main thread if this flag is set to true to provide a sensible FPS limit when running without vsync, and to avoid CPU usage skyrocketing on some systems.

Defaults to true.

source

pub fn timestep(&mut self, timestep: Timestep) -> &mut ContextBuilder

Sets the game’s timestep.

Defaults to Timestep::Fixed(60.0).

source

pub fn fullscreen(&mut self, fullscreen: bool) -> &mut ContextBuilder

Sets whether or not the window should start in fullscreen.

Defaults to false.

source

pub fn maximized(&mut self, maximized: bool) -> &mut ContextBuilder

Sets whether or not the window should start maximized.

Defaults to false.

source

pub fn minimized(&mut self, minimized: bool) -> &mut ContextBuilder

Sets whether or not the window should start minimized.

Defaults to false.

source

pub fn resizable(&mut self, resizable: bool) -> &mut ContextBuilder

Sets whether or not the window should be resizable.

Defaults to false.

source

pub fn borderless(&mut self, borderless: bool) -> &mut ContextBuilder

Sets whether or not the window should be borderless.

Defaults to false.

source

pub fn multisampling(&mut self, multisampling: u8) -> &mut ContextBuilder

Sets the number of samples that should be used for multisample anti-aliasing.

The number of samples that can be used varies between graphics cards - 2, 4 and 8 are reasonably well supported. Setting the number of samples to 0 will disable multisampling.

Note that this setting only applies to the main backbuffer - multisampled canvases can be created via Canvas::builder.

Defaults to 0.

source

pub fn stencil_buffer(&mut self, stencil_buffer: bool) -> &mut ContextBuilder

Sets whether or not the window should have a stencil buffer.

If this is enabled, you can use the stencil functions in the graphics module when rendering to the main backbuffer.

Note that this setting only applies to the main backbuffer - to create a canvas with a stencil buffer, use Canvas::builder.

Defaults to false.

source

pub fn high_dpi(&mut self, high_dpi: bool) -> &mut ContextBuilder

Sets whether or not the window should use a high-DPI backbuffer, on platforms that support it (e.g. MacOS with a retina display).

Note that you may also need some platform-specific config to enable high-DPI rendering:

  • On Windows, set dpiAware to true/pm and dpiAwareness to permonitorv2 in your application manifest. This should enable the best behaviour available, regardless of how old the user’s version of Windows is.
  • On Mac, set NSHighResolutionCapable to true in your Info.plist. This is the default on Catalina and higher.

Defaults to false.

source

pub fn screen_saver_enabled( &mut self, screen_saver_enabled: bool ) -> &mut ContextBuilder

Sets whether or not the user’s screen saver can be displayed while the game is running.

Defaults to false.

source

pub fn key_repeat(&mut self, key_repeat: bool) -> &mut ContextBuilder

Sets whether or not key repeat should be enabled.

Normally, a KeyPressed event will only be fired once, when the key is initially pressed. Enabling key repeat causes KeyPressed events to be fired continuously while the key is held down.

Defaults to false.

source

pub fn show_mouse(&mut self, show_mouse: bool) -> &mut ContextBuilder

Sets whether or not the mouse cursor should be visible when it is within the game window.

Defaults to false.

source

pub fn grab_mouse(&mut self, grab_mouse: bool) -> &mut ContextBuilder

Sets whether or not the mouse cursor should be grabbed by the game window at startup.

Defaults to false.

source

pub fn relative_mouse_mode( &mut self, relative_mouse_mode: bool ) -> &mut ContextBuilder

Sets whether or not relative mouse mode should be enabled.

While the mouse is in relative mode, the cursor is hidden and can move beyond the bounds of the window. The delta field of Event::MouseMoved can then be used to track the cursor’s changes in position. This is useful when implementing control schemes that require the mouse to be able to move infinitely in any direction (for example, FPS-style movement).

While this mode is enabled, the absolute position of the mouse may not be updated - as such, you should not rely on it.

Defaults to false.

source

pub fn quit_on_escape(&mut self, quit_on_escape: bool) -> &mut ContextBuilder

Sets whether or not the game should close when the Escape key is pressed.

Defaults to false.

source

pub fn debug_info(&mut self, debug_info: bool) -> &mut ContextBuilder

Sets whether or not the game should print out debug info at startup. Please include this if you’re submitting a bug report!

source

pub fn build(&self) -> Result<Context>

Builds the context.

Errors

Trait Implementations§

source§

impl Clone for ContextBuilder

source§

fn clone(&self) -> ContextBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ContextBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ContextBuilder

source§

fn default() -> ContextBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,