orbtk_tinyskia::tinyskia

Struct RenderContext2D

Source
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

Source

pub fn new(width: f64, height: f64) -> Self

Creates a new 2d render context.

Source

pub fn register_font(&mut self, family: &str, font_file: &'static [u8])

Registers a new font file.

Source

pub fn resize(&mut self, width: f64, height: f64)

Resizes pixmap with new height and width

Source

pub fn set_background(&mut self, background: Color)

Set the background of the render context.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn draw_image(&mut self, image: &Image, x: f64, y: f64)

Draws the image.

Source

pub fn draw_pipeline( &mut self, x: f64, y: f64, width: f64, height: f64, pipeline: Box<dyn PipelineTrait>, )

Draws the pipeline.

Source

pub fn draw_render_target( &mut self, render_target: &RenderTarget, x: f64, y: f64, )

Draws a render target.

Source

pub fn fill(&mut self)

Fills the current or given path with the current file style.

Source

pub fn fill_text(&mut self, text: &str, x: f64, y: f64)

Draws (fills) a given text at the given (x, y) position.

Source

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.

Source

pub fn measure( &mut self, text: &str, font_size: f64, family: impl Into<String>, ) -> TextMetrics

Returns a TextMetrics object.

Source

pub fn measure_text(&mut self, text: &str) -> TextMetrics

Returns a TextMetrics object.

Source

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.

Source

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.

Source

pub fn stroke(&mut self)

Strokes {outlines} the current or given path with the current stroke style.

Source

pub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64)

Adds a rectangle to the current path.

Source

pub fn set_alpha(&mut self, alpha: f32)

Sets the alpha value,

Source

pub fn set_font_family(&mut self, family: impl Into<String>)

Specifies the font family.

Source

pub fn set_font_size(&mut self, size: f64)

Specifies the font size.

Source

pub fn set_line_width(&mut self, line_width: f64)

Sets the thickness of lines.

Source

pub fn set_fill_style(&mut self, fill_style: impl Into<Brush>)

Specifies the fill color to use inside shapes.

Source

pub fn set_stroke_style(&mut self, stroke_style: impl Into<Brush>)

Specifies the fill stroke to use inside shapes.

Source

pub fn clear(&mut self, brush: &Brush)

Clear the given brush.

Source

pub fn data(&self) -> &[u8]

Return the pixmap data lenght as an u8 reference value.

Byteorder: RGBA

Source

pub fn data_mut(&mut self) -> &mut [u8]

Return the pixmap data lenght as a mutable u8 reference value.

Byteorder: RGBA

Source

pub fn data_u8_mut(&mut self) -> &mut [u8]

Return the pixmap data lenght as a mutable u8 reference value.

Byteorder: RGBA

Source

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.

Source

pub fn save(&mut self)

Saves the entire state of the pixmap by pushing the current state onto a stack.

Source

pub fn start(&mut self)

Fill the background pixmap colors using their rgba8 values.

Source

pub fn finish(&mut self)

Cleanup, once we are finished.

Auto Trait Implementations§

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.