[][src]Struct femtovg::Canvas

pub struct Canvas<T: Renderer> { /* fields omitted */ }

Main 2D drawing context.

Implementations

impl<T> Canvas<T> where
    T: Renderer
[src]

pub fn new(renderer: T) -> Result<Self, ErrorKind>[src]

Creates a new canvas.

pub fn set_size(&mut self, width: u32, height: u32, dpi: f32)[src]

Sets the size of the default framebuffer (screen size)

pub fn clear_rect(
    &mut self,
    x: u32,
    y: u32,
    width: u32,
    height: u32,
    color: Color
)
[src]

Clears the rectangle area defined by left upper corner (x,y), width and height with the provided color.

pub fn width(&self) -> f32[src]

Returns the width of the current render target.

pub fn height(&self) -> f32[src]

Returns the height of the current render target.

pub fn flush(&mut self)[src]

Tells the renderer to execute all drawing commands and clears the current internal state

Call this at the end of each frame.

pub fn screenshot(&mut self) -> Result<ImgVec<RGBA8>, ErrorKind>[src]

pub fn save(&mut self)[src]

Pushes and saves the current render state into a state stack.

A matching restore() must be used to restore the state.

pub fn restore(&mut self)[src]

Restores the previous render state

Restoring the initial/first state will just reset it to the defaults

pub fn reset(&mut self)[src]

Resets current state to default values. Does not affect the state stack.

pub fn save_with(&mut self, mut callback: impl FnMut(&mut Self))[src]

Saves the current state before calling the callback and restores it afterwards

This is less error prone than remembering to match save() -> restore() calls

pub fn set_global_alpha(&mut self, alpha: f32)[src]

Sets the transparency applied to all rendered shapes.

Already transparent paths will get proportionally more transparent as well.

pub fn global_composite_operation(&mut self, op: CompositeOperation)[src]

Sets the composite operation.

pub fn global_composite_blend_func(
    &mut self,
    src_factor: BlendFactor,
    dst_factor: BlendFactor
)
[src]

Sets the composite operation with custom pixel arithmetic.

pub fn global_composite_blend_func_separate(
    &mut self,
    src_rgb: BlendFactor,
    dst_rgb: BlendFactor,
    src_alpha: BlendFactor,
    dst_alpha: BlendFactor
)
[src]

Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately.

pub fn set_render_target(&mut self, target: RenderTarget)[src]

Sets a new render target. All drawing operations after this call will happen on the provided render target

pub fn create_image_empty(
    &mut self,
    width: usize,
    height: usize,
    format: PixelFormat,
    flags: ImageFlags
) -> Result<ImageId, ErrorKind>
[src]

Allocates an empty image with the provided domensions and format.

pub fn create_image<'a, S: Into<ImageSource<'a>>>(
    &mut self,
    src: S,
    flags: ImageFlags
) -> Result<ImageId, ErrorKind>
[src]

Creates image from specified image data.

pub fn get_image(&self, id: ImageId) -> Option<&T::Image>[src]

pub fn get_image_mut(&mut self, id: ImageId) -> Option<&mut T::Image>[src]

pub fn realloc_image(
    &mut self,
    id: ImageId,
    width: usize,
    height: usize,
    format: PixelFormat,
    flags: ImageFlags
) -> Result<(), ErrorKind>
[src]

Resizes an image to the new provided dimensions.

pub fn load_image_file<P: AsRef<FilePath>>(
    &mut self,
    filename: P,
    flags: ImageFlags
) -> Result<ImageId, ErrorKind>
[src]

Decode an image from file

pub fn load_image_mem(
    &mut self,
    data: &[u8],
    flags: ImageFlags
) -> Result<ImageId, ErrorKind>
[src]

Decode an image from memory

pub fn update_image<'a, S: Into<ImageSource<'a>>>(
    &mut self,
    id: ImageId,
    src: S,
    x: usize,
    y: usize
) -> Result<(), ErrorKind>
[src]

Updates image data specified by image handle.

pub fn delete_image(&mut self, id: ImageId)[src]

Deletes created image.

pub fn image_info(&self, id: ImageId) -> Result<ImageInfo, ErrorKind>[src]

Returns image info

pub fn image_size(&self, id: ImageId) -> Result<(usize, usize), ErrorKind>[src]

Returns the size in pixels of the image for the specified id.

pub fn reset_transform(&mut self)[src]

Resets current transform to a identity matrix.

pub fn set_transform(&mut self, a: f32, b: f32, c: f32, d: f32, e: f32, f: f32)[src]

Premultiplies current coordinate system by specified matrix.

The parameters are interpreted as matrix as follows: [a c e] [b d f] [0 0 1]

pub fn translate(&mut self, x: f32, y: f32)[src]

Translates the current coordinate system.

pub fn rotate(&mut self, angle: f32)[src]

Rotates the current coordinate system. Angle is specified in radians.

pub fn skew_x(&mut self, angle: f32)[src]

Skews the current coordinate system along X axis. Angle is specified in radians.

pub fn skew_y(&mut self, angle: f32)[src]

Skews the current coordinate system along Y axis. Angle is specified in radians.

pub fn scale(&mut self, x: f32, y: f32)[src]

Scales the current coordinate system.

pub fn transform(&self) -> Transform2D[src]

Returns the current transformation matrix

TODO: It's not ok that this method returns Transform2D while set_transform accepts 6 floats - make it consistant

pub fn scissor(&mut self, x: f32, y: f32, w: f32, h: f32)[src]

Sets the current scissor rectangle.

The scissor rectangle is transformed by the current transform.

pub fn intersect_scissor(&mut self, x: f32, y: f32, w: f32, h: f32)[src]

Intersects current scissor rectangle with the specified rectangle.

The scissor rectangle is transformed by the current transform. Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.

pub fn reset_scissor(&mut self)[src]

Reset and disables scissoring.

pub fn contains_point(
    &mut self,
    path: &mut Path,
    x: f32,
    y: f32,
    fill_rule: FillRule
) -> bool
[src]

Returns true if the specified point (x,y) is in the provided path, and false otherwise.

pub fn path_bbox(&self, path: &mut Path) -> Bounds[src]

Return the bounding box for a Path

pub fn fill_path(&mut self, path: &mut Path, mut paint: Paint)[src]

Fills the provided Path with the specified Paint.

pub fn stroke_path(&mut self, path: &mut Path, mut paint: Paint)[src]

Strokes the provided Path with the specified Paint.

pub fn add_font<P: AsRef<FilePath>>(
    &mut self,
    file_path: P
) -> Result<FontId, ErrorKind>
[src]

Adds a font file to the canvas

pub fn add_font_mem(&mut self, data: &[u8]) -> Result<FontId, ErrorKind>[src]

Adds a font to the canvas by reading it from the specified chunk of memory.

pub fn add_font_dir<P: AsRef<FilePath>>(
    &mut self,
    dir_path: P
) -> Result<Vec<FontId>, ErrorKind>
[src]

Adds all .ttf files from a directory

pub fn measure_text<S: AsRef<str>>(
    &mut self,
    x: f32,
    y: f32,
    text: S,
    mut paint: Paint
) -> Result<TextMetrics, ErrorKind>
[src]

Returns information on how the provided text will be drawn with the specified paint.

pub fn measure_font(
    &mut self,
    mut paint: Paint
) -> Result<FontMetrics, ErrorKind>
[src]

Returns font metrics for a particular Paint.

pub fn break_text<S: AsRef<str>>(
    &mut self,
    max_width: f32,
    text: S,
    mut paint: Paint
) -> Result<usize, ErrorKind>
[src]

Returns the maximum index-th byte of text that will fit inside max_width.

The retuned index will always lie at the start and/or end of a UTF-8 code point sequence or at the start or end of the text

pub fn break_text_vec<S: AsRef<str>>(
    &mut self,
    max_width: f32,
    text: S,
    paint: Paint
) -> Result<Vec<Range<usize>>, ErrorKind>
[src]

Returnes a list of ranges representing each line of text that will fit inside max_width

pub fn fill_text<S: AsRef<str>>(
    &mut self,
    x: f32,
    y: f32,
    text: S,
    paint: Paint
) -> Result<TextMetrics, ErrorKind>
[src]

Fills the provided string with the specified Paint.

pub fn stroke_text<S: AsRef<str>>(
    &mut self,
    x: f32,
    y: f32,
    text: S,
    paint: Paint
) -> Result<TextMetrics, ErrorKind>
[src]

Strokes the provided string with the specified Paint.

Trait Implementations

impl<T: Renderer> Drop for Canvas<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Canvas<T>[src]

impl<T> !Send for Canvas<T>[src]

impl<T> !Sync for Canvas<T>[src]

impl<T> Unpin for Canvas<T> where
    T: Unpin,
    <T as Renderer>::Image: Unpin
[src]

impl<T> !UnwindSafe for Canvas<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.