pub struct Pen<'a> { /* private fields */ }Expand description
The pen widgets draw with: a &mut dyn Painter wearing the ergonomics the
trait cannot have.
Painter must be object-safe, so its methods take a premultiplied
Paint and it cannot hand out a re-borrow of itself for a tighter clip.
Those are exactly the two things widget code wants back. Pen restores them
as inherent methods, which need no import and never compete with the
trait’s for resolution – so a widget body written against a rasteriser reads
identically written against a pen, and a backend still only implements the
small trait.
Implementations§
Source§impl<'a> Pen<'a>
impl<'a> Pen<'a>
Sourcepub fn painter(&mut self) -> &mut dyn Painter
pub fn painter(&mut self) -> &mut dyn Painter
The painter underneath, for code that wants the raw contract.
Sourcepub fn with_clip(&mut self, rect: Rect) -> Pen<'_>
pub fn with_clip(&mut self, rect: Rect) -> Pen<'_>
A pen on the same target with a tighter clip.
The clip is restored when the returned pen is dropped, and the borrow
stops the parent drawing until then: a child cannot escape the region it
was given, exactly as with a canvas’s own with_clip.
Sourcepub fn format(&self) -> PixelFormat
pub fn format(&self) -> PixelFormat
Word layout of the target.
Sourcepub fn is_clipped_out(&self) -> bool
pub fn is_clipped_out(&self) -> bool
Returns true if the clip admits no pixels, so drawing can be skipped.
Sourcepub fn fill_rect(&mut self, rect: Rect, color: impl Into<Paint>)
pub fn fill_rect(&mut self, rect: Rect, color: impl Into<Paint>)
Fills rect, compositing with the destination if the paint has alpha.
Sourcepub fn fill_rects(&mut self, rects: &[Rect], color: impl Into<Paint>)
pub fn fill_rects(&mut self, rects: &[Rect], color: impl Into<Paint>)
Fills every rectangle. Overlapping rectangles composite twice.
Sourcepub fn stroke_rect(
&mut self,
rect: Rect,
thickness: i32,
color: impl Into<Paint>,
)
pub fn stroke_rect( &mut self, rect: Rect, thickness: i32, color: impl Into<Paint>, )
Draws a border of thickness pixels inside rect.
Sourcepub fn fill_rounded_rect(
&mut self,
rect: Rect,
radius: i32,
color: impl Into<Paint>,
)
pub fn fill_rounded_rect( &mut self, rect: Rect, radius: i32, color: impl Into<Paint>, )
Fills a rectangle with rounded corners.
Sourcepub fn stroke_rounded_rect(
&mut self,
rect: Rect,
radius: i32,
thickness: i32,
color: impl Into<Paint>,
)
pub fn stroke_rounded_rect( &mut self, rect: Rect, radius: i32, thickness: i32, color: impl Into<Paint>, )
Strokes a rounded rectangle inside its bounds.
Sourcepub fn fill_circle(
&mut self,
centre: Point,
radius: i32,
color: impl Into<Paint>,
)
pub fn fill_circle( &mut self, centre: Point, radius: i32, color: impl Into<Paint>, )
Fills a circle.
Sourcepub fn stroke_circle(
&mut self,
centre: Point,
radius: i32,
thickness: i32,
color: impl Into<Paint>,
)
pub fn stroke_circle( &mut self, centre: Point, radius: i32, thickness: i32, color: impl Into<Paint>, )
Strokes a circle inside its bounds.
Sourcepub fn stroke_arc(
&mut self,
centre: Point,
radius: i32,
thickness: i32,
start: i32,
sweep: i32,
color: impl Into<Paint>,
)
pub fn stroke_arc( &mut self, centre: Point, radius: i32, thickness: i32, start: i32, sweep: i32, color: impl Into<Paint>, )
Strokes part of a circle, from start through sweep binary turns.
Sourcepub fn draw_line(&mut self, a: Point, b: Point, color: impl Into<Paint>)
pub fn draw_line(&mut self, a: Point, b: Point, color: impl Into<Paint>)
Draws a one-pixel line.
Sourcepub fn fill_star(
&mut self,
centre: Point,
outer_radius: i32,
inner_radius: i32,
points: u32,
rotation: i32,
color: impl Into<Paint>,
)
pub fn fill_star( &mut self, centre: Point, outer_radius: i32, inner_radius: i32, points: u32, rotation: i32, color: impl Into<Paint>, )
Fills a star with points points.
Sourcepub fn fill_polygon_fx(
&mut self,
points: &[(i32, i32)],
color: impl Into<Paint>,
)
pub fn fill_polygon_fx( &mut self, points: &[(i32, i32)], color: impl Into<Paint>, )
Fills a polygon whose vertices are in the rasteriser’s 8.8 fixed point.
Sourcepub fn draw_icon(&mut self, icon: &Icon, rect: Rect, fore: Color, back: Color)
pub fn draw_icon(&mut self, icon: &Icon, rect: Rect, fore: Color, back: Color)
Draws an icon scaled to rect, in two inks.
Sourcepub fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, color: impl Into<Paint>)
pub fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, color: impl Into<Paint>)
Composites an 8-bit coverage mask. How glyphs arrive.
Sourcepub fn blit_glyph(
&mut self,
at: Point,
page: &AtlasPage<'_>,
rect: Rect,
color: impl Into<Paint>,
)
pub fn blit_glyph( &mut self, at: Point, page: &AtlasPage<'_>, rect: Rect, color: impl Into<Paint>, )
Composites the glyph at rect of an atlas page.
Sourcepub fn blit(&mut self, src: &PixelView<'_>, at: Point)
pub fn blit(&mut self, src: &PixelView<'_>, at: Point)
Copies a premultiplied source over the target at at.
Sourcepub fn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect)
pub fn blit_scaled(&mut self, src: &PixelView<'_>, dest: Rect)
Copies a premultiplied source, scaled to dest.
Sourcepub fn blit_rounded(
&mut self,
src: &PixelView<'_>,
dest: Rect,
shape: Rect,
radius: i32,
)
pub 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.
Sourcepub fn blit_image(&mut self, src: &ImageRef<'_>, dest: Rect)
pub fn blit_image(&mut self, src: &ImageRef<'_>, dest: Rect)
Draws an image, scaled to dest.
Sourcepub fn blit_image_rounded(
&mut self,
src: &ImageRef<'_>,
dest: Rect,
shape: Rect,
radius: i32,
)
pub 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.
Sourcepub fn scroll_rows(&mut self, rect: Rect, dy: i32) -> bool
pub fn scroll_rows(&mut self, rect: Rect, dy: i32) -> bool
Moves the pixels inside rect up by dy rows, down when negative, or
answers false when the painter cannot. See Painter::scroll_rows.