pub struct ScreenScaler { /* private fields */ }
Expand description

A wrapper for a Canvas that handles scaling the image to fit the screen.

Examples

The scaling example demonstrates how to use a ScreenScaler with each of the different scaling algorithms.

Implementations§

source§

impl ScreenScaler

source

pub fn new( ctx: &mut Context, inner_width: i32, inner_height: i32, outer_width: i32, outer_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>

Returns a new ScreenScaler, with the specified inner and outer width and height. The mode will determine how the image is scaled to fit the screen.

source

pub fn from_canvas( canvas: Canvas, outer_width: i32, outer_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>

Returns a new ScreenScaler, using the given canvas for drawing. The mode will determine how the image is scaled to fit the screen.

source

pub fn with_window_size( ctx: &mut Context, inner_width: i32, inner_height: i32, mode: ScalingMode ) -> Result<ScreenScaler>

Returns a new ScreenScaler, with the specified inner width and height, and the outer size set to the current dimensions of the window.

source

pub fn draw(&self, ctx: &mut Context)

Draws the scaled image to the screen.

source

pub fn set_outer_size(&mut self, outer_width: i32, outer_height: i32)

Updates the scaler’s outer size (i.e. the size of the box that the screen will be scaled to fit within).

source

pub fn outer_size(&self) -> (i32, i32)

Returns the scaler’s outer size (i.e. the size of the box that the screen will be scaled to fit within).
The format is (width, height).

source

pub fn inner_size(&self) -> (i32, i32)

Returns the scaler’s inner size (i.e. the logical screen size).
The format is (width, height).

source

pub fn scale_factor(&self) -> f32

Returns the optimal scale factor for the current ScalingMode and configured sizes.
This can be used for simple use cases where scaling by canvas is not feasible (e.g. 3rd party UI libraries).

source

pub fn canvas(&self) -> &Canvas

Returns a reference to the canvas that is being scaled.

source

pub fn mode(&self) -> ScalingMode

Returns the current scaling mode.

source

pub fn set_mode(&mut self, mode: ScalingMode)

Sets the scaling mode that should be used.

source

pub fn project(&self, position: Vec2<f32>) -> Vec2<f32>

Converts a point from window co-ordinates to scaled screen co-ordinates.

source

pub fn unproject(&self, position: Vec2<f32>) -> Vec2<f32>

Converts a point from scaled screen co-ordinates to window co-ordinates.

source

pub fn mouse_position(&self, ctx: &Context) -> Vec2<f32>

Returns the position of the mouse in scaled screen co-ordinates.

This is a shortcut for calling .project(input::get_mouse_position(ctx)).

source

pub fn mouse_x(&self, ctx: &Context) -> f32

Returns the X co-ordinate of the mouse in scaled screen co-ordinates.

This is a shortcut for calling project(input::get_mouse_position(ctx)).x.

source

pub fn mouse_y(&self, ctx: &Context) -> f32

Returns the Y co-ordinate of the mouse in scaled screen co-ordinates.

This is a shortcut for calling project(input::get_mouse_position(ctx)).y.

Trait Implementations§

source§

impl Debug for ScreenScaler

source§

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

Formats the value using the given formatter. 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
§

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>,