[−][src]Macro embedded_graphics::egline
Create a Line
with optional styling using a
convenient macro.
Note that only the stroke
property has any effect on lines currently.
use embedded_graphics::{ egline, pixelcolor::Rgb565, prelude::*, primitive_style, primitives::Line, style::{PrimitiveStyle, Styled}, }; let line: Styled<Line, PrimitiveStyle<Rgb565>> = egline!(start = (10, 20), end = (30, 40)); let stroke_line: Styled<Line, PrimitiveStyle<Rgb565>> = egline!( start = (10, 20), end = (30, 40), style = primitive_style!(stroke_color = Rgb565::BLUE) );
Style properties like stroke_color
map to methods on the PrimitiveStyleBuilder
struct.
For example, the following code makes two identical lines:
use embedded_graphics::{ egline, pixelcolor::Rgb565, prelude::*, primitive_style, primitives::Line, style::{PrimitiveStyle, PrimitiveStyleBuilder, Styled}, }; let line_1: Styled<Line, PrimitiveStyle<Rgb565>> = egline!( start = (10, 20), end = (30, 40), style = primitive_style!( stroke_color = Rgb565::BLUE, fill_color = Rgb565::YELLOW, stroke_width = 1 ) ); let style = PrimitiveStyleBuilder::new() .fill_color(Rgb565::YELLOW) .stroke_color(Rgb565::BLUE) .stroke_width(1) .build(); let line_2: Styled<Line, PrimitiveStyle<Rgb565>> = Line::new(Point::new(10, 20), Point::new(30, 40)).into_styled(style); assert_eq!(line_1, line_2);