macro_rules! egcircle {
(center = $center:expr, radius = $r:expr $(,)?) => { ... };
(center = $center:expr, radius = $r:expr, style = $style:expr $(,)?) => { ... };
}
Expand description
Create a Circle
with optional styling using a
convenient macro.
use embedded_graphics::{
egcircle,
pixelcolor::Rgb565,
prelude::*,
primitive_style,
primitives::Circle,
style::{PrimitiveStyle, Styled},
};
// Coordinates can be defined as any type that implements `Into<Point>`
let line_circle: Styled<Circle, PrimitiveStyle<Rgb565>> =
egcircle!(center = (10, 20), radius = 30);
let filled_circle: Styled<Circle, PrimitiveStyle<Rgb565>> = egcircle!(
center = (10, 20),
radius = 30,
style = primitive_style!(stroke_color = Rgb565::RED, fill_color = Rgb565::GREEN)
);
Style properties like stroke_color
map to methods on the PrimitiveStyleBuilder
struct.
For example, the following code makes two identical circles:
use embedded_graphics::{
egcircle,
pixelcolor::Rgb565,
prelude::*,
primitive_style,
primitives::Circle,
style::{PrimitiveStyle, PrimitiveStyleBuilder, Styled},
};
let circle_1: Styled<Circle, PrimitiveStyle<Rgb565>> = egcircle!(
center = (10, 20),
radius = 30,
style = primitive_style!(
stroke_color = Rgb565::RED,
fill_color = Rgb565::GREEN,
stroke_width = 1
)
);
let style = PrimitiveStyleBuilder::new()
.fill_color(Rgb565::GREEN)
.stroke_color(Rgb565::RED)
.stroke_width(1)
.build();
let circle_2: Styled<Circle, PrimitiveStyle<Rgb565>> =
Circle::new(Point::new(10, 20), 30).into_styled(style);
assert_eq!(circle_1, circle_2);