Struct tetra::graphics::DrawParams

source ·
pub struct DrawParams {
    pub position: Vec2<f32>,
    pub scale: Vec2<f32>,
    pub origin: Vec2<f32>,
    pub rotation: f32,
    pub color: Color,
}
Expand description

Parameters that can be manipulated when drawing an object.

You can either use this as a builder by calling DrawParams::new and then chaining methods, or construct it manually - whichever you find more pleasant to write.

Fields§

§position: Vec2<f32>

The position that the graphic should be drawn at. Defaults to (0.0, 0.0).

§scale: Vec2<f32>

The scale that the graphic should be drawn at. Defaults to (1.0, 1.0).

This can be set to a negative value to flip the graphic around the origin.

§origin: Vec2<f32>

The origin of the graphic. Defaults to (0.0, 0.0) (the top left).

This offset is applied before scaling, rotation and positioning. For example, if you have a 16x16 image and set the origin to [8.0, 8.0], subsequent transformations will be performed relative to the center of the image.

§rotation: f32

The rotation of the graphic, in radians. Defaults to 0.0.

§color: Color

A color to multiply the graphic by. Defaults to Color::WHITE.

Implementations§

source§

impl DrawParams

source

pub fn new() -> DrawParams

Creates a new set of DrawParams.

source

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

Sets the position that the graphic should be drawn at.

source

pub fn scale(self, scale: Vec2<f32>) -> DrawParams

Sets the scale that the graphic should be drawn at.

source

pub fn origin(self, origin: Vec2<f32>) -> DrawParams

Sets the origin of the graphic.

source

pub fn rotation(self, rotation: f32) -> DrawParams

Sets the rotation of the graphic, in radians.

source

pub fn color(self, color: Color) -> DrawParams

Sets the color to multiply the graphic by.

source

pub fn to_matrix(&self) -> Mat4<f32>

Creates a new transformation matrix equivalent to this set of params.

This method does not take into account color, as it cannot be represented via a matrix.

Trait Implementations§

source§

impl Clone for DrawParams

source§

fn clone(&self) -> DrawParams

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 DrawParams

source§

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

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

impl Default for DrawParams

source§

fn default() -> DrawParams

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

impl From<DrawParams> for Mat4<f32>

source§

fn from(params: DrawParams) -> Self

Converts to this type from the input type.
source§

impl From<Vec2<f32>> for DrawParams

source§

fn from(position: Vec2<f32>) -> DrawParams

Converts to this type from the input type.
source§

impl PartialEq<DrawParams> for DrawParams

source§

fn eq(&self, other: &DrawParams) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for DrawParams

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