@@ -20,13 +20,16 @@ const BUF_SIZE: usize = 96 * 64 * 2;
20
20
///
21
21
/// ```rust
22
22
/// use embedded_graphics::{
23
- /// fonts::{Font6x8, Text},
24
23
/// geometry::Point,
25
24
/// image::{Image, ImageRawLE},
25
+ /// mono_font::{
26
+ /// ascii::{FONT_6X10, FONT_9X18},
27
+ /// MonoTextStyleBuilder,
28
+ /// },
26
29
/// pixelcolor::Rgb565,
27
30
/// prelude::*,
28
- /// primitives::{Circle, Line, Rectangle},
29
- /// style ::{PrimitiveStyleBuilder, TextStyleBuilder },
31
+ /// primitives::{Circle, Line, PrimitiveStyle, Rectangle, Triangle },
32
+ /// text ::{Baseline, Text },
30
33
/// };
31
34
/// use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
32
35
/// # use ssd1331::test_helpers::{Pin, Spi};
@@ -36,50 +39,44 @@ const BUF_SIZE: usize = 96 * 64 * 2;
36
39
/// let dc = Pin;
37
40
///
38
41
/// let mut display = Ssd1331::new(spi, dc, Rotate0);
39
- /// let raw = ImageRawLE::new(include_bytes!("../examples/ferris.raw"), 86, 64 );
42
+ /// let raw = ImageRawLE::new(include_bytes!("../examples/ferris.raw"), 86);
40
43
///
41
- /// let image: Image<ImageRawLE<Rgb565>, Rgb565 > = Image::new(&raw, Point::zero());
44
+ /// let image: Image<ImageRawLE<Rgb565>> = Image::new(&raw, Point::zero());
42
45
///
43
46
/// // Initialise and clear the display
44
47
/// display.init().unwrap();
45
48
/// display.flush().unwrap();
46
49
///
47
- /// Line ::new(Point::new(0, 0), Point::new(16, 16))
48
- /// .into_styled(
49
- /// PrimitiveStyleBuilder ::new()
50
- /// .stroke_color(Rgb565::RED)
51
- /// .stroke_width(1 )
52
- /// .build(),
53
- /// )
54
- /// .draw(&mut display );
50
+ /// Triangle ::new(
51
+ /// Point::new(8, 16 + 16),
52
+ /// Point ::new(8 + 16, 16 + 16),
53
+ /// Point::new(8 + 8, 16),
54
+ /// )
55
+ /// .into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
56
+ /// .draw(&mut display )
57
+ /// .unwrap( );
55
58
///
56
- /// Rectangle::new(Point::new(24, 0), Point::new(40, 16))
57
- /// .into_styled(
58
- /// PrimitiveStyleBuilder::new()
59
- /// .stroke_color(Rgb565::new(255, 127, 0))
60
- /// .stroke_width(1)
61
- /// .build(),
62
- /// )
63
- /// .draw(&mut display);
59
+ /// Rectangle::with_corners(Point::new(36, 16), Point::new(36 + 16, 16 + 16))
60
+ /// .into_styled(PrimitiveStyle::with_stroke(Rgb565::GREEN, 1))
61
+ /// .draw(&mut display)
62
+ /// .unwrap();
64
63
///
65
- /// Circle::new(Point::new(64, 8), 8)
66
- /// .into_styled(
67
- /// PrimitiveStyleBuilder::new()
68
- /// .stroke_color(Rgb565::GREEN)
69
- /// .stroke_width(1)
70
- /// .build(),
71
- /// )
72
- /// .draw(&mut display);
64
+ /// Circle::new(Point::new(72, 16 + 8), 8)
65
+ /// .into_styled(PrimitiveStyle::with_stroke(Rgb565::BLUE, 1))
66
+ /// .draw(&mut display)
67
+ /// .unwrap();
73
68
///
74
69
/// image.draw(&mut display);
75
70
///
76
- /// Text::new("Hello Rust!", Point::new(24, 24))
77
- /// .into_styled(
78
- /// TextStyleBuilder::new(Font6x8)
79
- /// .text_color(Rgb565::RED)
80
- /// .build(),
81
- /// )
82
- /// .draw(&mut display);
71
+ /// // Red with a small amount of green creates a deep orange colour
72
+ /// let rust_style = MonoTextStyleBuilder::new()
73
+ /// .font(&FONT_9X18)
74
+ /// .text_color(Rgb565::RED)
75
+ /// .build();
76
+ ///
77
+ /// Text::with_baseline("Hello Rust!", Point::new(0, 0), rust_style, Baseline::Top)
78
+ /// .draw(&mut display)
79
+ /// .unwrap();
83
80
///
84
81
/// // Render graphics objects to the screen
85
82
/// display.flush().unwrap();
@@ -202,8 +199,7 @@ where
202
199
Ok ( ( ) )
203
200
}
204
201
205
- /// Turn a pixel on or off. A non-zero `value` is treated as on, `0` as off. If the X and Y
206
- /// coordinates are out of the bounds of the display, this method call is a noop.
202
+ /// Set the value for an individual pixel.
207
203
pub fn set_pixel ( & mut self , x : u32 , y : u32 , value : u16 ) {
208
204
let idx = match self . display_rotation {
209
205
DisplayRotation :: Rotate0 | DisplayRotation :: Rotate180 => {
@@ -363,47 +359,52 @@ where
363
359
}
364
360
365
361
#[ cfg( feature = "graphics" ) ]
366
- use core:: convert:: TryInto ;
367
- #[ cfg( feature = "graphics" ) ]
368
- use embedded_graphics:: {
369
- drawable,
362
+ use embedded_graphics_core:: {
363
+ draw_target:: DrawTarget ,
370
364
geometry:: Size ,
365
+ geometry:: { Dimensions , OriginDimensions } ,
371
366
pixelcolor:: {
372
367
raw:: { RawData , RawU16 } ,
373
368
Rgb565 ,
374
369
} ,
375
- DrawTarget ,
370
+ Pixel ,
376
371
} ;
377
372
378
373
#[ cfg( feature = "graphics" ) ]
379
- impl < SPI , DC > DrawTarget < Rgb565 > for Ssd1331 < SPI , DC >
374
+ impl < SPI , DC > DrawTarget for Ssd1331 < SPI , DC >
380
375
where
381
376
SPI : hal:: blocking:: spi:: Write < u8 > ,
382
377
DC : OutputPin ,
383
378
{
379
+ type Color = Rgb565 ;
384
380
type Error = core:: convert:: Infallible ;
385
381
386
- fn draw_pixel ( & mut self , pixel : drawable:: Pixel < Rgb565 > ) -> Result < ( ) , Self :: Error > {
387
- let drawable:: Pixel ( pos, color) = pixel;
388
-
389
- // Guard against negative values. All positive i32 values from `pos` can be represented in
390
- // the `u32`s that `set_pixel()` accepts.
391
- if pos. x < 0 || pos. y < 0 {
392
- return Ok ( ( ) ) ;
393
- }
382
+ fn draw_iter < I > ( & mut self , pixels : I ) -> Result < ( ) , Self :: Error >
383
+ where
384
+ I : IntoIterator < Item = Pixel < Self :: Color > > ,
385
+ {
386
+ let bb = self . bounding_box ( ) ;
394
387
395
- self . set_pixel (
396
- ( pos. x ) . try_into ( ) . unwrap ( ) ,
397
- ( pos. y ) . try_into ( ) . unwrap ( ) ,
398
- RawU16 :: from ( color) . into_inner ( ) ,
399
- ) ;
388
+ pixels
389
+ . into_iter ( )
390
+ . filter ( |Pixel ( pos, _color) | bb. contains ( * pos) )
391
+ . for_each ( |Pixel ( pos, color) | {
392
+ self . set_pixel ( pos. x as u32 , pos. y as u32 , RawU16 :: from ( color) . into_inner ( ) )
393
+ } ) ;
400
394
401
395
Ok ( ( ) )
402
396
}
397
+ }
403
398
399
+ #[ cfg( feature = "graphics" ) ]
400
+ impl < SPI , DC > OriginDimensions for Ssd1331 < SPI , DC >
401
+ where
402
+ SPI : hal:: blocking:: spi:: Write < u8 > ,
403
+ DC : OutputPin ,
404
+ {
404
405
fn size ( & self ) -> Size {
405
406
let ( w, h) = self . dimensions ( ) ;
406
407
407
- Size :: new ( w as u32 , h as u32 )
408
+ Size :: new ( w. into ( ) , h. into ( ) )
408
409
}
409
410
}
0 commit comments