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
sourceimpl<P: Pixel> Rectangle<P>
impl<P: Pixel> Rectangle<P>
sourcepub fn new() -> Self
pub fn new() -> Self
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.
sourcepub fn from_bounding_box(x1: u32, y1: u32, x2: u32, y2: u32) -> Self
pub fn from_bounding_box(x1: u32, y1: u32, x2: u32, y2: u32) -> Self
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.
sourcepub const fn with_position(self, x: u32, y: u32) -> Self
pub const fn with_position(self, x: u32, y: u32) -> Self
Sets the position of the rectangle.
sourcepub const fn with_size(self, width: u32, height: u32) -> Self
pub const fn with_size(self, width: u32, height: u32) -> Self
Sets the size of the rectangle in pixels.
sourcepub const fn with_border(self, border: Border<P>) -> Self
pub const fn with_border(self, border: Border<P>) -> Self
sourcepub const fn with_overlay_mode(self, mode: OverlayMode) -> Self
pub const fn with_overlay_mode(self, mode: OverlayMode) -> Self
Sets the overlay mode of the rectangle.
Trait Implementations
Auto Trait Implementations
impl<P> RefUnwindSafe for Rectangle<P> where
P: RefUnwindSafe,
impl<P> Send for Rectangle<P> where
P: Send,
impl<P> Sync for Rectangle<P> where
P: Sync,
impl<P> Unpin for Rectangle<P> where
P: Unpin,
impl<P> UnwindSafe for Rectangle<P> where
P: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more