Struct nannou::draw::Draw

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

A simple API for drawing 2D and 3D graphics.

Draw provides a simple way to compose together geometry and text with custom colours and textures and draw them to the screen. A suite of methods have been provided for drawing polygons, paths, meshes, text and textures in an accessible-yet-efficient manner.

Draw can also be used to create new Draw instances that refer to the same inner draw state but are slightly different from one another. E.g. draw.rotate(radians) produces a new Draw instance where all drawings will be rotated by the given amount. draw.x(x) produces a new Draw instance where all drawings are translated along the x axis by the given amount.

See the draw examples for a variety of demonstrations of how the Draw type can be used!

Implementations§

source§

impl Draw

source

pub fn to_frame(&self, app: &App, frame: &Frame<'_>) -> Result<(), DrawError>

Render the Draw’s inner list of commands to the texture associated with the Frame.

The App stores a unique render.

source§

impl Draw

source

pub fn new() -> Self

Create a new Draw instance.

This is the same as calling Draw::default.

source

pub fn reset(&self)

Resets all state within the Draw instance.

source

pub fn transform(&self, transform_matrix: Mat4) -> Self

Produce a new Draw instance transformed by the given transform matrix.

The resulting Draw instance will be have a transform equal to the new transform applied to the existing transform.

source

pub fn translate(&self, v: Vec3) -> Self

Translate the position of the origin by the given translation vector.

source

pub fn xyz(&self, v: Vec3) -> Self

Translate the position of the origin by the given translation vector.

This method is short for translate.

source

pub fn xy(&self, v: Vec2) -> Self

Translate the position of the origin by the given translation vector.

source

pub fn x_y_z(&self, x: f32, y: f32, z: f32) -> Self

Translate the position of the origin by the given amount across each axis.

source

pub fn x_y(&self, x: f32, y: f32) -> Self

Translate the position of the origin by the given amount across each axis.

source

pub fn x(&self, x: f32) -> Self

Translate the position of the origin along the x axis.

source

pub fn y(&self, y: f32) -> Self

Translate the position of the origin along the y axis.

source

pub fn z(&self, z: f32) -> Self

Translate the position of the origin along the z axis.

source

pub fn scale(&self, s: f32) -> Self

Produce a new Draw instance where the contents are scaled uniformly by the given value.

source

pub fn scale_axes(&self, v: Vec3) -> Self

Produce a new Draw instance where the contents are scaled by the given amount across each axis.

source

pub fn scale_x(&self, s: f32) -> Self

Produce a new Draw instance where the contents are scaled by the given amount along the x axis

source

pub fn scale_y(&self, s: f32) -> Self

Produce a new Draw instance where the contents are scaled by the given amount along the y axis

source

pub fn scale_z(&self, s: f32) -> Self

Produce a new Draw instance where the contents are scaled by the given amount along the z axis

source

pub fn euler(&self, euler: Vec3) -> Self

The given vector is interpreted as a Euler angle in radians and a transform is applied accordingly.

source

pub fn quaternion(&self, q: Quat) -> Self

Specify the orientation with the given Quaternion.

source

pub fn radians(&self, v: Vec3) -> Self

Specify the orientation along each axis with the given Vector of radians.

This currently has the same affect as calling euler.

source

pub fn x_radians(&self, x: f32) -> Self

Specify the orientation around the x axis in radians.

source

pub fn y_radians(&self, y: f32) -> Self

Specify the orientation around the y axis in radians.

source

pub fn z_radians(&self, z: f32) -> Self

Specify the orientation around the z axis in radians.

source

pub fn degrees(&self, v: Vec3) -> Self

Specify the orientation along each axis with the given Vector of degrees.

source

pub fn x_degrees(&self, x: f32) -> Self

Specify the orientation around the x axis in degrees.

source

pub fn y_degrees(&self, y: f32) -> Self

Specify the orientation around the y axis in degrees.

source

pub fn z_degrees(&self, z: f32) -> Self

Specify the orientation around the z axis in degrees.

source

pub fn turns(&self, v: Vec3) -> Self

Specify the orientation along each axis with the given Vector of degrees.

source

pub fn x_turns(&self, x: f32) -> Self

Specify the orientation around the x axis as a number of turns around the axis.

source

pub fn y_turns(&self, y: f32) -> Self

Specify the orientation around the y axis as a number of turns around the axis.

source

pub fn z_turns(&self, z: f32) -> Self

Specify the orientation around the z axis as a number of turns around the axis.

source

pub fn pitch(&self, pitch: f32) -> Self

Specify the “pitch” of the orientation in radians.

This has the same effect as calling x_radians.

source

pub fn yaw(&self, yaw: f32) -> Self

Specify the “yaw” of the orientation in radians.

This has the same effect as calling y_radians.

source

pub fn roll(&self, roll: f32) -> Self

Specify the “roll” of the orientation in radians.

This has the same effect as calling z_radians.

source

pub fn rotate(&self, radians: f32) -> Self

Assuming we’re looking at a 2D plane, positive values cause a clockwise rotation where the given value is specified in radians.

This is equivalent to calling the z_radians or roll methods.

source

pub fn alpha_blend(&self, blend_descriptor: BlendComponent) -> Self

Produce a new Draw instance that will draw with the given alpha blend descriptor.

source

pub fn color_blend(&self, blend_descriptor: BlendComponent) -> Self

Produce a new Draw instance that will draw with the given color blend descriptor.

source

pub fn blend(&self, blend_descriptor: BlendComponent) -> Self

Short-hand for color_blend, the common use-case.

source

pub fn scissor(&self, scissor: Rect<f32>) -> Self

Produce a new Draw instance that will be cropped to the given rectangle.

If the current Draw instance already contains a scissor, the result will be the overlap between the original scissor and the new one.

source

pub fn line_mode(&self) -> Self

Produce a new Draw instance.

All drawing that occurs on the new instance will be rendered as a “wireframe” between all vertices.

This will cause the draw::Renderer to switch render pipelines in order to use the LineList primitive topology. The switch will only occur if this topology was not already enabled.

source

pub fn point_mode(&self) -> Self

Produce a new Draw instance.

All drawing that occurs on the new instance will be rendered as points on the vertices.

This will cause the draw::Renderer to switch render pipelines in order to use the PointList primitive topology. The switch will only occur if this topology was not already enabled.

source

pub fn triangle_mode(&self) -> Self

Produce a new Draw instance.

All drawing that occurs on the new instance will be rendered as triangles on the vertices.

This will cause the draw::Renderer to switch render pipelines in order to use the TriangleList primitive topology. The switch will only occur if this topology was not already enabled.

This is the default primitive topology mode.

source

pub fn sampler(&self, desc: SamplerDescriptor<'static>) -> Self

Produce a new Draw instance where all textures and textured vertices drawn will be sampled via a sampler of the given descriptor.

source

pub fn background(&self) -> Background<'_>

Specify a color with which the background should be cleared.

source

pub fn a<T>(&self, primitive: T) -> Drawing<'_, T>

Add the given type to be drawn.

source

pub fn path(&self) -> Drawing<'_, PathInit>

Begin drawing a Path.

source

pub fn ellipse(&self) -> Drawing<'_, Ellipse>

Begin drawing an Ellipse.

source

pub fn line(&self) -> Drawing<'_, Line>

Begin drawing a Line.

source

pub fn arrow(&self) -> Drawing<'_, Arrow>

Begin drawing an Arrow.

source

pub fn quad(&self) -> Drawing<'_, Quad>

Begin drawing a Quad.

source

pub fn rect(&self) -> Drawing<'_, Rect>

Begin drawing a Rect.

source

pub fn tri(&self) -> Drawing<'_, Tri>

Begin drawing a Triangle.

source

pub fn polygon(&self) -> Drawing<'_, PolygonInit>

Begin drawing a Polygon.

source

pub fn mesh(&self) -> Drawing<'_, Vertexless>

Begin drawing a Mesh.

source

pub fn polyline(&self) -> Drawing<'_, PathStroke>

Begin drawing a Polyline.

Note that this is simply short-hand for draw.path().stroke()

source

pub fn text(&self, s: &str) -> Drawing<'_, Text>

Begin drawing a Text.

source

pub fn texture(&self, view: &dyn ToTextureView) -> Drawing<'_, Texture>

Begin drawing a Texture.

source

pub fn drain_commands(&self) -> impl Iterator<Item = DrawCommand>

Finish any drawings-in-progress and produce an iterator draining the inner draw commands and yielding them by value.

source

pub fn finish_remaining_drawings(&self)

Drain any remaining drawings and convert them to draw commands.

Trait Implementations§

source§

impl Clone for Draw

source§

fn clone(&self) -> Draw

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 Draw

source§

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

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

impl Default for Draw

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Draw

§

impl !Send for Draw

§

impl !Sync for Draw

§

impl Unpin for Draw

§

impl !UnwindSafe for Draw

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

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 T
where 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 T
where 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 T
where 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V