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
impl Draw
sourcepub fn transform(&self, transform_matrix: Mat4) -> Self
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.
sourcepub fn translate(&self, v: Vec3) -> Self
pub fn translate(&self, v: Vec3) -> Self
Translate the position of the origin by the given translation vector.
sourcepub fn xyz(&self, v: Vec3) -> Self
pub fn xyz(&self, v: Vec3) -> Self
Translate the position of the origin by the given translation vector.
This method is short for translate
.
sourcepub fn xy(&self, v: Vec2) -> Self
pub fn xy(&self, v: Vec2) -> Self
Translate the position of the origin by the given translation vector.
sourcepub fn x_y_z(&self, x: f32, y: f32, z: f32) -> Self
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.
sourcepub fn x_y(&self, x: f32, y: f32) -> Self
pub fn x_y(&self, x: f32, y: f32) -> Self
Translate the position of the origin by the given amount across each axis.
sourcepub fn scale(&self, s: f32) -> Self
pub fn scale(&self, s: f32) -> Self
Produce a new Draw instance where the contents are scaled uniformly by the given value.
sourcepub fn scale_axes(&self, v: Vec3) -> Self
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.
sourcepub fn scale_x(&self, s: f32) -> Self
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
sourcepub fn scale_y(&self, s: f32) -> Self
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
sourcepub fn scale_z(&self, s: f32) -> Self
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
sourcepub fn euler(&self, euler: Vec3) -> Self
pub fn euler(&self, euler: Vec3) -> Self
The given vector is interpreted as a Euler angle in radians and a transform is applied accordingly.
sourcepub fn quaternion(&self, q: Quat) -> Self
pub fn quaternion(&self, q: Quat) -> Self
Specify the orientation with the given Quaternion.
sourcepub fn radians(&self, v: Vec3) -> Self
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
.
sourcepub fn degrees(&self, v: Vec3) -> Self
pub fn degrees(&self, v: Vec3) -> Self
Specify the orientation along each axis with the given Vector of degrees.
sourcepub fn turns(&self, v: Vec3) -> Self
pub fn turns(&self, v: Vec3) -> Self
Specify the orientation along each axis with the given Vector of degrees.
sourcepub fn x_turns(&self, x: f32) -> Self
pub fn x_turns(&self, x: f32) -> Self
Specify the orientation around the x axis as a number of turns around the axis.
sourcepub fn y_turns(&self, y: f32) -> Self
pub fn y_turns(&self, y: f32) -> Self
Specify the orientation around the y axis as a number of turns around the axis.
sourcepub fn z_turns(&self, z: f32) -> Self
pub fn z_turns(&self, z: f32) -> Self
Specify the orientation around the z axis as a number of turns around the axis.
sourcepub fn pitch(&self, pitch: f32) -> Self
pub fn pitch(&self, pitch: f32) -> Self
Specify the “pitch” of the orientation in radians.
This has the same effect as calling x_radians
.
sourcepub fn yaw(&self, yaw: f32) -> Self
pub fn yaw(&self, yaw: f32) -> Self
Specify the “yaw” of the orientation in radians.
This has the same effect as calling y_radians
.
sourcepub fn roll(&self, roll: f32) -> Self
pub fn roll(&self, roll: f32) -> Self
Specify the “roll” of the orientation in radians.
This has the same effect as calling z_radians
.
sourcepub fn rotate(&self, radians: f32) -> Self
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.
sourcepub fn alpha_blend(&self, blend_descriptor: BlendComponent) -> Self
pub fn alpha_blend(&self, blend_descriptor: BlendComponent) -> Self
Produce a new Draw instance that will draw with the given alpha blend descriptor.
sourcepub fn color_blend(&self, blend_descriptor: BlendComponent) -> Self
pub fn color_blend(&self, blend_descriptor: BlendComponent) -> Self
Produce a new Draw instance that will draw with the given color blend descriptor.
sourcepub fn blend(&self, blend_descriptor: BlendComponent) -> Self
pub fn blend(&self, blend_descriptor: BlendComponent) -> Self
Short-hand for color_blend
, the common use-case.
sourcepub fn scissor(&self, scissor: Rect<f32>) -> Self
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.
sourcepub fn line_mode(&self) -> Self
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.
sourcepub fn point_mode(&self) -> Self
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.
sourcepub fn triangle_mode(&self) -> Self
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.
sourcepub fn sampler(&self, desc: SamplerDescriptor<'static>) -> Self
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.
sourcepub fn background(&self) -> Background<'_>
pub fn background(&self) -> Background<'_>
Specify a color with which the background should be cleared.
sourcepub fn polygon(&self) -> Drawing<'_, PolygonInit>
pub fn polygon(&self) -> Drawing<'_, PolygonInit>
Begin drawing a Polygon.
sourcepub fn mesh(&self) -> Drawing<'_, Vertexless>
pub fn mesh(&self) -> Drawing<'_, Vertexless>
Begin drawing a Mesh.
sourcepub fn polyline(&self) -> Drawing<'_, PathStroke>
pub fn polyline(&self) -> Drawing<'_, PathStroke>
Begin drawing a Polyline.
Note that this is simply short-hand for draw.path().stroke()
sourcepub fn texture(&self, view: &dyn ToTextureView) -> Drawing<'_, Texture>
pub fn texture(&self, view: &dyn ToTextureView) -> Drawing<'_, Texture>
Begin drawing a Texture.
sourcepub fn drain_commands(&self) -> impl Iterator<Item = DrawCommand>
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.
sourcepub fn finish_remaining_drawings(&self)
pub fn finish_remaining_drawings(&self)
Drain any remaining drawing
s and convert them to draw commands.
Trait Implementations§
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
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains the unclamped color. Read more