Skip to main content

Painter

Trait Painter 

Source
pub trait Painter {
Show 28 methods // Required methods fn size(&self) -> Size; fn format(&self) -> PixelFormat; fn clip(&self) -> Rect; fn push_clip(&mut self, rect: Rect) -> ClipToken; fn pop_clip(&mut self, token: ClipToken); fn clear(&mut self, color: Color); fn fill_rect(&mut self, rect: Rect, paint: Paint); fn fill_rounded_rect(&mut self, rect: Rect, radius: i32, paint: Paint); fn stroke_rounded_rect( &mut self, rect: Rect, radius: i32, thickness: i32, paint: Paint, ); fn fill_circle(&mut self, centre: Point, radius: i32, paint: Paint); fn stroke_circle( &mut self, centre: Point, radius: i32, thickness: i32, paint: Paint, ); fn stroke_arc( &mut self, centre: Point, radius: i32, thickness: i32, start: i32, sweep: i32, paint: Paint, ); fn draw_line(&mut self, a: Point, b: Point, paint: Paint); fn fill_polygon_fx(&mut self, points: &[(i32, i32)], paint: Paint); fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, paint: Paint); fn blit(&mut self, src: &PixelView<'_>, at: Point); fn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect); fn blit_rounded( &mut self, src: &PixelView<'_>, dest: Rect, shape: Rect, radius: i32, ); // Provided methods fn scroll_rows(&mut self, rect: Rect, dy: i32) -> bool { ... } fn blit_glyph( &mut self, at: Point, page: &AtlasPage<'_>, rect: Rect, paint: Paint, ) { ... } fn blit_image(&mut self, src: &ImageRef<'_>, dest: Rect) { ... } fn blit_image_rounded( &mut self, src: &ImageRef<'_>, dest: Rect, shape: Rect, radius: i32, ) { ... } fn is_clipped_out(&self) -> bool { ... } fn visible(&self, rect: Rect) -> Option<Rect> { ... } fn fill_rects(&mut self, rects: &[Rect], paint: Paint) { ... } fn stroke_rect(&mut self, rect: Rect, thickness: i32, paint: Paint) { ... } fn fill_star( &mut self, centre: Point, outer_radius: i32, inner_radius: i32, points: u32, rotation: i32, paint: Paint, ) { ... } fn draw_icon(&mut self, icon: &Icon, rect: Rect, fore: Color, back: Color) { ... }
}
Expand description

A clipped drawing target.

Coordinates are physical pixels relative to the target origin, never relative to the clip. Angles are binary turns, as everywhere else in this crate: 0 is twelve o’clock, clockwise positive, TURN is a full circle.

Clipping is rectangular. That covers scrolling regions, damage-restricted repaint and nested panels, which is all a UI actually needs; arbitrary clip shapes are not planned, and their absence is what keeps this trait small enough for a backend to implement in an afternoon.

Required Methods§

Source

fn size(&self) -> Size

Full extent of the target.

Source

fn format(&self) -> PixelFormat

Word layout of the target.

Source

fn clip(&self) -> Rect

The region operations are currently restricted to.

Source

fn push_clip(&mut self, rect: Rect) -> ClipToken

Narrows the clip to its intersection with rect, returning the old one.

Never widens. Prefer PainterExt::with_clip, which pairs this with its pop_clip for you.

Source

fn pop_clip(&mut self, token: ClipToken)

Restores the clip a push_clip replaced.

Source

fn clear(&mut self, color: Color)

Fills the entire clip with an opaque colour.

Source

fn fill_rect(&mut self, rect: Rect, paint: Paint)

Fills a rectangle.

Source

fn fill_rounded_rect(&mut self, rect: Rect, radius: i32, paint: Paint)

Fills a rectangle with rounded corners.

Source

fn stroke_rounded_rect( &mut self, rect: Rect, radius: i32, thickness: i32, paint: Paint, )

Strokes a rounded rectangle inside its bounds.

Source

fn fill_circle(&mut self, centre: Point, radius: i32, paint: Paint)

Fills a circle.

Source

fn stroke_circle( &mut self, centre: Point, radius: i32, thickness: i32, paint: Paint, )

Strokes a circle inside its bounds.

Source

fn stroke_arc( &mut self, centre: Point, radius: i32, thickness: i32, start: i32, sweep: i32, paint: Paint, )

Strokes part of a circle, from start through sweep binary turns.

Source

fn draw_line(&mut self, a: Point, b: Point, paint: Paint)

Draws a one-pixel line.

Source

fn fill_polygon_fx(&mut self, points: &[(i32, i32)], paint: Paint)

Fills a polygon whose vertices are in the rasteriser’s 8.8 fixed point.

The primitive icons and stars are made of, which is why it is on the trait rather than private to the software backend: a GPU answers it with a triangle fan and gets both for free.

Source

fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, paint: Paint)

Composites an 8-bit coverage mask. How glyphs arrive.

Source

fn blit(&mut self, src: &PixelView<'_>, at: Point)

Copies a premultiplied source over the target at at.

Source

fn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect)

Copies a premultiplied source, scaled to dest.

Source

fn blit_rounded( &mut self, src: &PixelView<'_>, dest: Rect, shape: Rect, radius: i32, )

Copies a premultiplied source, scaled to dest and masked to a rounded shape.

Provided Methods§

Source

fn scroll_rows(&mut self, rect: Rect, dy: i32) -> bool

Moves the pixels inside rect up by dy rows, or down by -dy rows when dy is negative, within the clip. The dy rows that come into view at the trailing edge are left as they were, for the caller to paint. Answers false when this target cannot move its own pixels, in which case nothing has changed and the caller repaints the lot.

What a scrolled viewport is made of: most of its rows are the previous frame’s, one strip higher or lower, and a backend that can shift them in place turns a repaint of the viewport into a repaint of the strip. The default is honest rather than helpful — a compositor that draws every frame whole has nothing to gain from it — and a rasteriser with a buffer of words answers with the copy.

Source

fn blit_glyph( &mut self, at: Point, page: &AtlasPage<'_>, rect: Rect, paint: Paint, )

Composites the glyph at rect of an atlas page.

Provided as “cut the rectangle out and blit_mask it”, which is all the software rasteriser wants. A backend that keeps textures overrides it to upload the page once per version and draw rectangles of it from then on, which is the difference between a glyph costing an upload and costing six vertices.

Source

fn blit_image(&mut self, src: &ImageRef<'_>, dest: Rect)

Draws an image, scaled to dest.

Provided as blit_scaled of the pixels, which is all the software rasteriser wants. A backend that keeps textures overrides it to upload the image once per version and draw a quad from then on.

Source

fn blit_image_rounded( &mut self, src: &ImageRef<'_>, dest: Rect, shape: Rect, radius: i32, )

Draws an image, scaled to dest and masked to a rounded shape.

The rounded counterpart of blit_image, provided as blit_rounded of the pixels.

Source

fn is_clipped_out(&self) -> bool

Returns true if the clip admits no pixels, so drawing can be skipped.

Source

fn visible(&self, rect: Rect) -> Option<Rect>

The clipped, visible part of rect.

Source

fn fill_rects(&mut self, rects: &[Rect], paint: Paint)

Fills several rectangles in one colour.

Source

fn stroke_rect(&mut self, rect: Rect, thickness: i32, paint: Paint)

Strokes a rectangle inside its bounds.

Source

fn fill_star( &mut self, centre: Point, outer_radius: i32, inner_radius: i32, points: u32, rotation: i32, paint: Paint, )

Fills a star with points points.

See denise-render for what the binary-turn rounding costs.

Source

fn draw_icon(&mut self, icon: &Icon, rect: Rect, fore: Color, back: Color)

Draws an icon scaled to rect, in two inks.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Painter for Canvas<'_>