[][src]Macro embedded_graphics::rect

macro_rules! rect {
    (($x1:expr, $y1:expr), ($x2:expr, $y2:expr) $(, $style_key:ident = $style_value:expr )* $(,)?) => { ... };
}

Create a Rect with optional styling using a convenient macro.

use embedded_graphics::{rect, style::Style, primitives::Rect};

let empty_rect: Rect<u8> = rect!((10, 20), (30, 40));
let filled_rect: Rect<u8> = rect!((10, 20), (30, 40), stroke = Some(5u8), fill = Some(10u8));
let rect_default_style: Rect<u8> = rect!((10, 20), (30, 40), style = Style::default());

Style properties like stroke map to the method calls on the WithStyle trait. For example, the following code makes two identical rectangles:

use embedded_graphics::prelude::*;
use embedded_graphics::{rect, style::Style, primitives::Rect};

let Rect: Rect<u8> = rect!((10, 20), (30, 40), stroke = Some(5u8), fill = Some(10u8));
let Rect: Rect<u8> = Rect::new(Coord::new(10, 20), Coord::new(30, 40))
    .stroke(Some(5u8))
    .fill(Some(10u8));