Renderer

Trait Renderer 

Source
pub trait Renderer {
    type Font;

    // Required methods
    fn push(&mut self);
    fn pop(&mut self);
    fn translate(&mut self, vec: Vector);
    fn clip(&mut self, rect: Rect);
    fn fill(&mut self, rect: Rect, color: Color, radius: f32);
    fn outline(&mut self, rect: Rect, color: Color, radius: f32, thickness: f32);
    fn line(
        &mut self,
        a: Point,
        b: Point,
        color: Color,
        cap: LineCap,
        thickness: f32,
    );
    fn text(
        &mut self,
        rect: Rect,
        font: &Self::Font,
        text: &str,
        color: Color,
        alignment: Alignment,
    ) -> f32;
}
Expand description

The renderer trait, used for all things drawing-related.

§A note on rendering lines

Renderers should try their best to make lines pixel-perfect. What this means is that lines with a thickness of 1.0 shouldn’t get placed inbetween pixels, as that will make it look blurred out. Some vector graphics renderers do that, and on those renderers stroke points should get moved by half a pixel.

Examples of such renderers include HTML5 canvas, Cairo, Skia.

Required Associated Types§

Source

type Font

The font type used for rendering text. May be () if text rendering isn’t supported.

Required Methods§

Source

fn push(&mut self)

Pushes the current transform matrix and clip region onto a stack.

Source

fn pop(&mut self)

Pops the topmost transform matrix and clip region off the stack and overwrites the current transform matrix with it.

Source

fn translate(&mut self, vec: Vector)

Translates the transform matrix by the given vector.

Source

fn clip(&mut self, rect: Rect)

Updates the clip region to the intersection of the current clip region and the provided rectangle. Initially, the clip region spans the whole window. This only allows for shrinking the clip region in size. The only way to increase its size is to use push() and pop().

The rectangle should be subject to translation.

Source

fn fill(&mut self, rect: Rect, color: Color, radius: f32)

Draws a fill for the provided rectangle, with the given color and corner radius.

Source

fn outline(&mut self, rect: Rect, color: Color, radius: f32, thickness: f32)

Draws an outline for the provided rectangle, with the given color, corner radius, and thickness.

Source

fn line( &mut self, a: Point, b: Point, color: Color, cap: LineCap, thickness: f32, )

Draws a line from point A to point B, with the given color, cap type, and thickness.

Source

fn text( &mut self, rect: Rect, font: &Self::Font, text: &str, color: Color, alignment: Alignment, ) -> f32

Draws text aligned inside of the provided rectangle, with the given color.

Returns the horizontal advance of the text.

Implementors§