Skip to main content

Pen

Struct Pen 

Source
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>

Source

pub fn new(painter: &'a mut dyn Painter) -> Pen<'a>

Borrows a painter to draw through.

Source

pub fn painter(&mut self) -> &mut dyn Painter

The painter underneath, for code that wants the raw contract.

Source

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.

Source

pub fn size(&self) -> Size

Full extent of the target.

Source

pub fn format(&self) -> PixelFormat

Word layout of the target.

Source

pub fn clip(&self) -> Rect

The region operations are currently restricted to.

Source

pub fn is_clipped_out(&self) -> bool

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

Source

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

The clipped, visible part of rect.

Source

pub fn clear(&mut self, color: Color)

Fills the entire clip with an opaque colour.

Source

pub fn fill_rect(&mut self, rect: Rect, color: impl Into<Paint>)

Fills rect, compositing with the destination if the paint has alpha.

Source

pub fn fill_rects(&mut self, rects: &[Rect], color: impl Into<Paint>)

Fills every rectangle. Overlapping rectangles composite twice.

Source

pub fn stroke_rect( &mut self, rect: Rect, thickness: i32, color: impl Into<Paint>, )

Draws a border of thickness pixels inside rect.

Source

pub fn fill_rounded_rect( &mut self, rect: Rect, radius: i32, color: impl Into<Paint>, )

Fills a rectangle with rounded corners.

Source

pub fn stroke_rounded_rect( &mut self, rect: Rect, radius: i32, thickness: i32, color: impl Into<Paint>, )

Strokes a rounded rectangle inside its bounds.

Source

pub fn fill_circle( &mut self, centre: Point, radius: i32, color: impl Into<Paint>, )

Fills a circle.

Source

pub fn stroke_circle( &mut self, centre: Point, radius: i32, thickness: i32, color: impl Into<Paint>, )

Strokes a circle inside its bounds.

Source

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.

Source

pub fn draw_line(&mut self, a: Point, b: Point, color: impl Into<Paint>)

Draws a one-pixel line.

Source

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.

Source

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.

Source

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

Draws an icon scaled to rect, in two inks.

Source

pub fn blit_mask(&mut self, at: Point, mask: &Mask<'_>, color: impl Into<Paint>)

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

Source

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.

Source

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

Copies a premultiplied source over the target at at.

Source

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

Copies a premultiplied source, scaled to dest.

Source

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.

Source

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

Draws an image, scaled to dest.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Pen<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Drop for Pen<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Pen<'a>

§

impl<'a> !Send for Pen<'a>

§

impl<'a> !Sync for Pen<'a>

§

impl<'a> !UnwindSafe for Pen<'a>

§

impl<'a> Freeze for Pen<'a>

§

impl<'a> Unpin for Pen<'a>

§

impl<'a> UnsafeUnpin for Pen<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.