pub struct Rectangle<P: Pixel> {
    pub position: (u32, u32),
    pub size: (u32, u32),
    pub border: Option<Border<P>>,
    pub fill: Option<P>,
    pub overlay: Option<OverlayMode>,
}
Expand description

A rectangle.

Using any of the predefined construction methods will automatically set the position to (0, 0). If you want to specify a different position, use the with_position method.

Note

You must specify a width and height for the rectangle with something such as [with_size]. If you don’t, a panic will be raised during drawing. You can also try using [from_bounding_box] to create a rectangle from a bounding box, which automatically fills in the size.

Additionally, a panic will be raised during drawing if you do not specify either a fill color or a border. these can be set with [with_fill] and [with_border] respectively.

Fields

position: (u32, u32)

The position of the rectangle. The top-left corner of the rectangle will be rendered at this position.

size: (u32, u32)

The dimensions of the rectangle, in pixels.

border: Option<Border<P>>

The border data of the rectangle, or None if there is no border.

fill: Option<P>

The fill color of the rectangle, or None if there is no fill.

overlay: Option<OverlayMode>

The overlay mode of the rectangle, or None to inherit from the overlay mode of the image.

Implementations

Creates a new rectangle with default values.

This immediately sets the position to (0, 0) and you must explicitly set the size of the rectangle with [with_size] in order to set a size for the rectangle. If no size is set before drawing, you will receive a panic.

This also does not set any border or fill for the rectangle, you must explicitly set either one of them with [with_fill] or [with_border] respectively or else you will receive a panic at draw-time.

Creates a new rectangle from two coordinates specified as 4 parameters.

The first coordinate is the top-left corner of the rectangle, and the second coordinate is the bottom-right corner of the rectangle.

Panics
  • Panics if the bounding box is invalid.

Sets the position of the rectangle.

Sets the size of the rectangle in pixels.

Sets the border information of the rectangle.

See Also

Sets the fill color of the rectangle.

Sets the overlay mode of the rectangle.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Draws the object to the given image.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.