[][src]Struct embedded_graphics::primitives::rectangle::Rectangle

pub struct Rectangle {
    pub top_left: Point,
    pub bottom_right: Point,
}

Rectangle primitive

Examples

The macro examples make for more concise code.

Create some rectangles with different styles

use embedded_graphics::{
    pixelcolor::Rgb565, prelude::*, primitives::Rectangle, style::PrimitiveStyleBuilder,
};

// Rectangle with red 3 pixel wide stroke and green fill from (50, 20) to (60, 35)
let style = PrimitiveStyleBuilder::new()
    .stroke_color(Rgb565::RED)
    .stroke_width(3)
    .fill_color(Rgb565::GREEN)
    .build();

Rectangle::new(Point::new(50, 20), Point::new(60, 35))
    .into_styled(style)
    .draw(&mut display)?;

// Rectangle with translation applied
Rectangle::new(Point::new(50, 20), Point::new(60, 35))
    .translate(Point::new(65, 35))
    .into_styled(style)
    .draw(&mut display)?;

Fields

top_left: Point

Top left point of the rect

bottom_right: Point

Bottom right point of the rect

Methods

impl Rectangle[src]

pub const fn new(top_left: Point, bottom_right: Point) -> Self[src]

Create a new rectangle from the top left point to the bottom right point with a given style

Trait Implementations

impl Clone for Rectangle[src]

impl Copy for Rectangle[src]

impl Debug for Rectangle[src]

impl Default for Rectangle[src]

impl Dimensions for Rectangle[src]

impl Eq for Rectangle[src]

impl Hash for Rectangle[src]

impl Ord for Rectangle[src]

impl PartialEq<Rectangle> for Rectangle[src]

impl PartialOrd<Rectangle> for Rectangle[src]

impl Primitive for Rectangle[src]

impl StructuralEq for Rectangle[src]

impl StructuralPartialEq for Rectangle[src]

impl Transform for Rectangle[src]

fn translate(&self, by: Point) -> Self[src]

Translate the rect from its current position to a new position by (x, y) pixels, returning a new Rectangle. For a mutating transform, see translate_mut.

let rect = Rectangle::new(Point::new(5, 10), Point::new(15, 20));
let moved = rect.translate(Point::new(10, 10));

assert_eq!(moved.top_left, Point::new(15, 20));
assert_eq!(moved.bottom_right, Point::new(25, 30));

fn translate_mut(&mut self, by: Point) -> &mut Self[src]

Translate the rect from its current position to a new position by (x, y) pixels.

let mut rect = Rectangle::new(Point::new(5, 10), Point::new(15, 20));
rect.translate_mut(Point::new(10, 10));

assert_eq!(rect.top_left, Point::new(15, 20));
assert_eq!(rect.bottom_right, Point::new(25, 30));

Auto Trait Implementations

impl Send for Rectangle

impl Sync for Rectangle

impl Unpin for Rectangle

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,