pub struct RenderContext2D { /* private fields */ }
Expand description
The RenderContext2D trait, provides the rendering context (ctx
). It is used
for drawing shapes, text, images, and other objects.
Implementations§
Source§impl RenderContext2D
impl RenderContext2D
Sourcepub fn register_font(&mut self, family: &str, font_file: &'static [u8])
pub fn register_font(&mut self, family: &str, font_file: &'static [u8])
Registers a new font file.
Sourcepub fn set_background(&mut self, background: Color)
pub fn set_background(&mut self, background: Color)
Set the background of the render context.
Sourcepub fn fill_rect(&mut self, x: f64, y: f64, width: f64, height: f64)
pub fn fill_rect(&mut self, x: f64, y: f64, width: f64, height: f64)
Draws a filled rectangle whose starting point is at the coordinates {x, y} with the specified width and height and whose style is determined by the fillStyle attribute.
Sourcepub fn stroke_rect(&mut self, x: f64, y: f64, width: f64, height: f64)
pub fn stroke_rect(&mut self, x: f64, y: f64, width: f64, height: f64)
Draws a rectangle that is stroked (outlined) according to the current strokeStyle and other ctx settings.
Sourcepub fn arc(
&mut self,
x: f64,
y: f64,
radius: f64,
start_angle: f64,
end_angle: f64,
)
pub fn arc( &mut self, x: f64, y: f64, radius: f64, start_angle: f64, end_angle: f64, )
Creates a circular arc centered at (x, y) with a radius of
given radius
value. The path starts at value startAngle
and ends at value endAngle
.
Sourcepub fn begin_path(&mut self)
pub fn begin_path(&mut self)
Starts a new path by emptying the list of sub-paths. You should call this method, if you want to create a new path.
Sourcepub fn bezier_curve_to(
&mut self,
cp1x: f64,
cp1y: f64,
cp2x: f64,
cp2y: f64,
x: f64,
y: f64,
)
pub fn bezier_curve_to( &mut self, cp1x: f64, cp1y: f64, cp2x: f64, cp2y: f64, x: f64, y: f64, )
Adds a cubic Bézier curve to the current sub-path. It requires three points: the first two are control points and the third one is the end point. The starting point is the latest point in the current path, which can be changed using MoveTo{} before creating the Bézier curve.
Sourcepub fn clip(&mut self)
pub fn clip(&mut self)
Creates a clipping mask applied to the current paths. Everything drawn after calling clip() will only act inside the clipping path.
Sourcepub fn close_path(&mut self)
pub fn close_path(&mut self)
When closing a path, the method attempts to add a straight line starting from the current point to the start point of the current sub-path. Nothing will happen, if the shape has already been closed or only a single point is referenced.
Sourcepub fn draw_image(&mut self, image: &Image, x: f64, y: f64)
pub fn draw_image(&mut self, image: &Image, x: f64, y: f64)
Draws the image.
Sourcepub fn draw_pipeline(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
pipeline: Box<dyn PipelineTrait>,
)
pub fn draw_pipeline( &mut self, x: f64, y: f64, width: f64, height: f64, pipeline: Box<dyn PipelineTrait>, )
Draws the pipeline.
Sourcepub fn draw_render_target(
&mut self,
render_target: &RenderTarget,
x: f64,
y: f64,
)
pub fn draw_render_target( &mut self, render_target: &RenderTarget, x: f64, y: f64, )
Draws a render target.
Sourcepub fn fill_text(&mut self, text: &str, x: f64, y: f64)
pub fn fill_text(&mut self, text: &str, x: f64, y: f64)
Draws (fills) a given text at the given (x, y) position.
Sourcepub fn line_to(&mut self, x: f64, y: f64)
pub fn line_to(&mut self, x: f64, y: f64)
Adds a straight line to the current sub-path by connecting the sub-path’s last point to the specified {x, y} coordinates.
Sourcepub fn measure(
&mut self,
text: &str,
font_size: f64,
family: impl Into<String>,
) -> TextMetrics
pub fn measure( &mut self, text: &str, font_size: f64, family: impl Into<String>, ) -> TextMetrics
Returns a TextMetrics object.
Sourcepub fn measure_text(&mut self, text: &str) -> TextMetrics
pub fn measure_text(&mut self, text: &str) -> TextMetrics
Returns a TextMetrics object.
Sourcepub fn move_to(&mut self, x: f64, y: f64)
pub fn move_to(&mut self, x: f64, y: f64)
Begins a new sub-path at given point
. The point is specified
by given {x, y} coordinates.
Sourcepub fn quadratic_curve_to(&mut self, cpx: f64, cpy: f64, x: f64, y: f64)
pub fn quadratic_curve_to(&mut self, cpx: f64, cpy: f64, x: f64, y: f64)
Adds a quadratic Bézier curve to the current sub-path.
Sourcepub fn stroke(&mut self)
pub fn stroke(&mut self)
Strokes {outlines} the current or given path with the current stroke style.
Sourcepub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64)
pub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64)
Adds a rectangle to the current path.
Sourcepub fn set_font_family(&mut self, family: impl Into<String>)
pub fn set_font_family(&mut self, family: impl Into<String>)
Specifies the font family.
Sourcepub fn set_font_size(&mut self, size: f64)
pub fn set_font_size(&mut self, size: f64)
Specifies the font size.
Sourcepub fn set_line_width(&mut self, line_width: f64)
pub fn set_line_width(&mut self, line_width: f64)
Sets the thickness of lines.
Sourcepub fn set_fill_style(&mut self, fill_style: impl Into<Brush>)
pub fn set_fill_style(&mut self, fill_style: impl Into<Brush>)
Specifies the fill color to use inside shapes.
Sourcepub fn set_stroke_style(&mut self, stroke_style: impl Into<Brush>)
pub fn set_stroke_style(&mut self, stroke_style: impl Into<Brush>)
Specifies the fill stroke to use inside shapes.
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Return the pixmap data lenght as an u8 reference value.
Byteorder: RGBA
Sourcepub fn data_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_mut(&mut self) -> &mut [u8] ⓘ
Return the pixmap data lenght as a mutable u8 reference value.
Byteorder: RGBA
Sourcepub fn data_u8_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_u8_mut(&mut self) -> &mut [u8] ⓘ
Return the pixmap data lenght as a mutable u8 reference value.
Byteorder: RGBA
Sourcepub fn restore(&mut self)
pub fn restore(&mut self)
Restores the most recently saved canvas state by popping the top entry in the drawing state stack. If there is no saved state, this method does nothing.