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§
Sourcefn format(&self) -> PixelFormat
fn format(&self) -> PixelFormat
Word layout of the target.
Sourcefn push_clip(&mut self, rect: Rect) -> ClipToken
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.
Sourcefn fill_rounded_rect(&mut self, rect: Rect, radius: i32, paint: Paint)
fn fill_rounded_rect(&mut self, rect: Rect, radius: i32, paint: Paint)
Fills a rectangle with rounded corners.
Sourcefn stroke_rounded_rect(
&mut self,
rect: Rect,
radius: i32,
thickness: i32,
paint: Paint,
)
fn stroke_rounded_rect( &mut self, rect: Rect, radius: i32, thickness: i32, paint: Paint, )
Strokes a rounded rectangle inside its bounds.
Sourcefn fill_circle(&mut self, centre: Point, radius: i32, paint: Paint)
fn fill_circle(&mut self, centre: Point, radius: i32, paint: Paint)
Fills a circle.
Sourcefn stroke_circle(
&mut self,
centre: Point,
radius: i32,
thickness: i32,
paint: Paint,
)
fn stroke_circle( &mut self, centre: Point, radius: i32, thickness: i32, paint: Paint, )
Strokes a circle inside its bounds.
Sourcefn stroke_arc(
&mut self,
centre: Point,
radius: i32,
thickness: i32,
start: i32,
sweep: i32,
paint: Paint,
)
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.
Sourcefn fill_polygon_fx(&mut self, points: &[(i32, i32)], paint: Paint)
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.
Sourcefn blit_mask(&mut self, at: Point, mask: &Mask<'_>, paint: Paint)
fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, paint: Paint)
Composites an 8-bit coverage mask. How glyphs arrive.
Sourcefn blit(&mut self, src: &PixelView<'_>, at: Point)
fn blit(&mut self, src: &PixelView<'_>, at: Point)
Copies a premultiplied source over the target at at.
Sourcefn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect)
fn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect)
Copies a premultiplied source, scaled to dest.
Provided Methods§
Sourcefn scroll_rows(&mut self, rect: Rect, dy: i32) -> bool
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.
Sourcefn blit_glyph(
&mut self,
at: Point,
page: &AtlasPage<'_>,
rect: Rect,
paint: Paint,
)
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.
Sourcefn blit_image(&mut self, src: &ImageRef<'_>, dest: Rect)
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.
Sourcefn blit_image_rounded(
&mut self,
src: &ImageRef<'_>,
dest: Rect,
shape: Rect,
radius: i32,
)
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.
Sourcefn is_clipped_out(&self) -> bool
fn is_clipped_out(&self) -> bool
Returns true if the clip admits no pixels, so drawing can be skipped.
Sourcefn fill_rects(&mut self, rects: &[Rect], paint: Paint)
fn fill_rects(&mut self, rects: &[Rect], paint: Paint)
Fills several rectangles in one colour.
Sourcefn stroke_rect(&mut self, rect: Rect, thickness: i32, paint: Paint)
fn stroke_rect(&mut self, rect: Rect, thickness: i32, paint: Paint)
Strokes a rectangle inside its bounds.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".