orbtk_render::platform

Struct RenderContext2D

Source
pub struct RenderContext2D { /* private fields */ }
Expand description

The RenderContext2D trait, provides the rendering 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 render ctx 2d.

Source

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

Set the background of the render context.

Source

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

Source

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

Registers a new font file.

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 fill_text(&mut self, text: &str, x: f64, y: f64)

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

Source

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

Returns a TextMetrics object.

Source

pub fn fill(&mut self)

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

Source

pub fn stroke(&mut self)

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

Source

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.

Source

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.

Source

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

Adds a rectangle to the current path.

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 radius. The path starts at startAngle and ends at endAngle.

Source

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.

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 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 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 draw_render_target( &mut self, render_target: &RenderTarget, x: f64, y: f64, )

Draws a render target.

Source

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

Draws the image.

Source

pub fn draw_image_with_clip( &mut self, image: &Image, clip: Rectangle, x: f64, y: f64, )

Draws the given part of the image.

Source

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

Source

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.

Source

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

Sets the thickness of lines.

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_fill_style(&mut self, fill_style: Brush)

Specifies the fill color to use inside shapes.

Source

pub fn set_stroke_style(&mut self, stroke_style: Brush)

Specifies the fill stroke to use inside shapes.

Source

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.

Source

pub fn save(&mut self)

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

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 clear(&mut self, brush: &Brush)

Source

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

Source

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

Source

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

Source

pub fn start(&mut self)

Source

pub fn finish(&mut self)

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.