Struct View

Source
#[repr(C)]
pub struct View { /* private fields */ }
Expand description

2D camera that defines what region is shown on screen

This is a very powerful concept: you can scroll, rotate or zoom the entire scene without altering the way that your drawable objects are drawn.

Implementations§

Source§

impl View

Creation

Source

pub fn new() -> SfResult<FBox<Self>>

Creates a default View of (0, 0, 1000, 1000)

Source

pub fn with_center_and_size(center: Vector2f, size: Vector2f) -> FBox<View>

Creates a view with position and size

§Arguments
  • center - The center of the view
  • size - The size of the view
Source

pub fn from_rect(rectangle: FloatRect) -> SfResult<FBox<View>>

Construct a view from a rectangle

§Arguments
  • rectangle - The rectangle defining the zone to display
Source§

impl View

Query properties

Source

pub fn rotation(&self) -> f32

Get the current orientation of a view

Return the rotation angle of the view, in degrees

Source

pub fn center(&self) -> Vector2f

Get the center of a view

Return the center of the view

Source

pub fn size(&self) -> Vector2f

Get the size of a view

Return the size of the view

Source

pub fn viewport(&self) -> FloatRect

Get the target viewport rectangle of a view

Return the viewport rectangle, expressed as a factor of the target size

Source§

impl View

Set properties

Source

pub fn set_rotation(&mut self, angle: f32)

Set the orientation of a view

The default rotation of a view is 0 degree.

§Arguments
  • angle - New angle, in degrees
Source

pub fn rotate(&mut self, angle: f32)

Rotate a view relatively to its current orientation

§Arguments
  • angle - Angle to rotate, in degrees
Source

pub fn zoom(&mut self, factor: f32)

Resize a view rectangle relatively to its current size

Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks.

§factor is a multiplier:
  • 1 keeps the size unchanged
  • bigger than 1 makes the view bigger (objects appear smaller)
  • smaller than 1 makes the view smaller (objects appear bigger)
§Arguments
  • factor - Zoom factor to apply
Source

pub fn set_center<C: Into<Vector2f>>(&mut self, center: C)

Set the center of a view

§Arguments
  • center - New center
Source

pub fn set_size<S: Into<Vector2f>>(&mut self, size: S)

Set the size of a view

§Arguments
  • size - New size of the view
Source

pub fn move_<O: Into<Vector2f>>(&mut self, offset: O)

Move a view relatively to its current position

§Arguments
  • offset - Offset
Source

pub fn set_viewport(&mut self, viewport: FloatRect)

Set the target viewport of a view

The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor (between 0 and 1) of the size of the render target to which the view is applied. For example, a view which takes the left side of the target would be defined by a rect of (0, 0, 0.5, 1). By default, a view has a viewport which covers the entire target.

§Arguments
  • viewport - New viewport rectangle
Source

pub fn reset(&mut self, rectangle: FloatRect)

Reset a view to the given rectangle

Note that this function resets the rotation angle to 0.

§Arguments
  • rectangle - Rectangle defining the zone to display

Trait Implementations§

Source§

impl Debug for View

Source§

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

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

impl Drop for View

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ToOwned for View

Source§

type Owned = FBox<View>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

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

Auto Trait Implementations§

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnwindSafe for View

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.