Struct graphics::context::Context

source ·
pub struct Context {
    pub viewport: Option<Viewport>,
    pub view: Matrix2d,
    pub transform: Matrix2d,
    pub draw_state: DrawState,
}
Expand description

Drawing 2d context.

Fields§

§viewport: Option<Viewport>

Viewport information.

§view: Matrix2d

View transformation.

§transform: Matrix2d

Current transformation.

§draw_state: DrawState

Current draw state settings.

Implementations§

source§

impl Context

source

pub fn new() -> Context

Creates a new drawing context.

source

pub fn new_viewport(viewport: Viewport) -> Context

Creates a new context with absolute transform in point coordinates.

This function assumes the default coordinate system being centered with x axis pointing to the right and y axis pointing up.

Returns a drawing context with origin in the upper left corner and x axis pointing to the right and y axis pointing down.

source

pub fn new_abs(w: Scalar, h: Scalar) -> Context

Creates a new drawing context in absolute coordinates.

This function assumes the default coordinate system being centered with x axis pointing to the right and y axis pointing up.

Returns a drawing context with origin in the upper left corner and x axis pointing to the right and y axis pointing down.

source

pub fn view(self) -> Self

Moves the current transform to the view coordinate system.

This is usually [0.0, 0.0] in the upper left corner with the x axis pointing to the right and the y axis pointing down.

source

pub fn reset(self) -> Self

Moves the current transform to the default coordinate system.

This is usually [0.0, 0.0] in the center with the x axis pointing to the right and the y axis pointing up.

source

pub fn store_view(self) -> Self

Stores the current transform as new view.

source

pub fn get_view_size(&self) -> Vec2d

Computes the current view size.

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

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 Transformed for Context

source§

fn append_transform(self, transform: Matrix2d) -> Self

Appends transform to the current one.
source§

fn prepend_transform(self, transform: Matrix2d) -> Self

Prepends transform to the current one.
source§

fn trans(self, x: Scalar, y: Scalar) -> Self

Translate x and y in local coordinates.
source§

fn rot_rad(self, angle: Scalar) -> Self

Rotate radians in local coordinates.
source§

fn orient(self, x: Scalar, y: Scalar) -> Self

Orients x axis to look at point locally. Read more
source§

fn scale(self, sx: Scalar, sy: Scalar) -> Self

Scales in local coordinates.
source§

fn shear(self, x: Scalar, y: Scalar) -> Self

Shears in local coordinates.
source§

fn rot_deg(self, angle: Scalar) -> Self

Rotates degrees in local coordinates.
source§

fn trans_pos<P: Into<Vec2d>>(self, pos: P) -> Self

Translate position in local coordinates.
source§

fn orient_pos<P: Into<Vec2d>>(self, pos: P) -> Self

Orients x axis to look at point locally.
source§

fn scale_pos<P: Into<Vec2d>>(self, pos: P) -> Self

Scales in local coordinates.
source§

fn zoom(self, s: Scalar) -> Self

Scales in both directions in local coordinates.
source§

fn flip_v(self) -> Self

Flips vertically in local coordinates.
source§

fn flip_h(self) -> Self

Flips horizontally in local coordinates.
source§

fn flip_hv(self) -> Self

Flips horizontally and vertically in local coordinates.
source§

fn shear_pos<P: Into<Vec2d>>(self, pos: P) -> Self

Shears in local coordinates.
source§

impl Copy for Context

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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.

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
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
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.
source§

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

Performs the conversion.