pub struct RenderContext2D { /* private fields */ }
Expand description
The RenderContext2D provides a concurrent render ctx.
Implementations§
Source§impl RenderContext2D
impl RenderContext2D
pub fn finish_receiver(&self) -> &Receiver<bool>
pub fn set_background(&mut self, background: Color)
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 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 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.
pub fn measure( &mut self, text: &str, font_size: f64, family: impl Into<String>, ) -> TextMetrics
Sourcepub fn measure_text(&mut self, text: &str) -> TextMetrics
pub fn measure_text(&mut self, text: &str) -> TextMetrics
Returns a TextMetrics object.
Sourcepub fn stroke(&mut self)
pub fn stroke(&mut self)
Strokes {outlines} the current or given path with the current stroke style.
Sourcepub fn begin_path(&mut self)
pub fn begin_path(&mut self)
Starts a new path by emptying the list of sub-paths. Call this when you want to create a new path.
Sourcepub fn close_path(&mut self)
pub fn close_path(&mut self)
Attempts to add a straight line from the current point to the start of the current sub-path. If the shape has already been closed or has only one point, this function does nothing.
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 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 radius. The path starts at startAngle and ends at endAngle.
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 the point specified by the given {x, y} coordinates.
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 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 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.
pub fn draw_render_target( &mut self, render_target: &RenderTarget, x: f64, y: f64, )
Sourcepub fn draw_image(&mut self, image: &mut Image, x: f64, y: f64)
pub fn draw_image(&mut self, image: &mut Image, x: f64, y: f64)
Draws the image.
Sourcepub fn draw_image_with_clip(
&mut self,
image: &mut Image,
clip: Rectangle,
x: f64,
y: f64,
)
pub fn draw_image_with_clip( &mut self, image: &mut Image, clip: Rectangle, x: f64, y: f64, )
Draws the given part of the image.
pub fn draw_pipeline( &mut self, x: f64, y: f64, width: f64, height: f64, pipeline: Box<dyn PipelineTrait>, )
Sourcepub fn clip(&mut self)
pub fn clip(&mut self)
Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only.
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_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_fill_style(&mut self, fill_style: Brush)
pub fn set_fill_style(&mut self, fill_style: Brush)
Specifies the fill color to use inside shapes.
Sourcepub fn set_stroke_style(&mut self, stroke_style: Brush)
pub fn set_stroke_style(&mut self, stroke_style: Brush)
Specifies the fill stroke to use inside shapes.
Sourcepub fn set_transform(
&mut self,
h_scaling: f64,
h_skewing: f64,
v_skewing: f64,
v_scaling: f64,
h_moving: f64,
v_moving: f64,
)
pub fn set_transform( &mut self, h_scaling: f64, h_skewing: f64, v_skewing: f64, v_scaling: f64, h_moving: f64, v_moving: f64, )
Sets the transformation.
Sourcepub fn save(&mut self)
pub fn save(&mut self)
Saves the entire state of the canvas by pushing the current state onto a stack.
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.
pub fn clear(&mut self, brush: &Brush)
pub fn data(&mut self) -> Option<&[u32]>
pub fn data_mut(&mut self) -> &mut [u32]
pub fn data_u8_mut(&mut self) -> &mut [u8] ⓘ
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RenderContext2D
impl !RefUnwindSafe for RenderContext2D
impl !Send for RenderContext2D
impl !Sync for RenderContext2D
impl Unpin for RenderContext2D
impl !UnwindSafe for RenderContext2D
Blanket Implementations§
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more