Skip to content

Commit 8397e45

Browse files
committed
Upgrade examples/readme to e-g 0.7
1 parent 6507266 commit 8397e45

File tree

7 files changed

+45
-66
lines changed

7 files changed

+45
-66
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ fn main() -> ! {
8484

8585
let (w, h) = disp.dimensions();
8686

87-
let bmp = Bmp::from_slice(include_bytes!("./rust-pride.bmp")).unwrap();
87+
let bmp =
88+
Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image");
8889

89-
let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero());
90+
let im: Image<Bmp<Rgb565>> = Image::new(&bmp, Point::zero());
9091

9192
// Position image in the center of the display
9293
let moved = im.translate(Point::new(
93-
(w as u32 - bmp.width()) as i32 / 2,
94-
(h as u32 - bmp.height()) as i32 / 2,
94+
(w as u32 - bmp.size().width) as i32 / 2,
95+
(h as u32 - bmp.size().height) as i32 / 2,
9596
));
9697

9798
moved.draw(&mut disp).unwrap();

examples/bmp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ fn main() -> ! {
8080

8181
let (w, h) = disp.dimensions();
8282

83-
let bmp = Bmp::from_slice(include_bytes!("./rust-pride.bmp")).unwrap();
83+
let bmp =
84+
Bmp::from_slice(include_bytes!("./rust-pride.bmp")).expect("Failed to load BMP image");
8485

85-
let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero());
86+
let im: Image<Bmp<Rgb565>> = Image::new(&bmp, Point::zero());
8687

8788
// Position image in the center of the display
8889
let moved = im.translate(Point::new(
89-
(w as u32 - bmp.width()) as i32 / 2,
90-
(h as u32 - bmp.height()) as i32 / 2,
90+
(w as u32 - bmp.size().width) as i32 / 2,
91+
(h as u32 - bmp.size().height) as i32 / 2,
9192
));
9293

9394
moved.draw(&mut disp).unwrap();

examples/graphics.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use embedded_graphics::{
2525
geometry::Point,
2626
pixelcolor::Rgb565,
2727
prelude::*,
28-
primitives::{Circle, Rectangle, Triangle},
29-
style::PrimitiveStyleBuilder,
28+
primitives::{Circle, PrimitiveStyle, Rectangle, Triangle},
3029
};
3130
use panic_semihosting as _;
3231
use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
@@ -86,32 +85,17 @@ fn main() -> ! {
8685
Point::new(8 + 16, 16 + 16),
8786
Point::new(8 + 8, 16),
8887
)
89-
.into_styled(
90-
PrimitiveStyleBuilder::new()
91-
.stroke_color(Rgb565::RED)
92-
.stroke_width(1)
93-
.build(),
94-
)
88+
.into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
9589
.draw(&mut disp)
9690
.unwrap();
9791

98-
Rectangle::new(Point::new(36, 16), Point::new(36 + 16, 16 + 16))
99-
.into_styled(
100-
PrimitiveStyleBuilder::new()
101-
.stroke_color(Rgb565::GREEN)
102-
.stroke_width(1)
103-
.build(),
104-
)
92+
Rectangle::with_corners(Point::new(36, 16), Point::new(36 + 16, 16 + 16))
93+
.into_styled(PrimitiveStyle::with_stroke(Rgb565::GREEN, 1))
10594
.draw(&mut disp)
10695
.unwrap();
10796

108-
Circle::new(Point::new(72, 16 + 8), 8)
109-
.into_styled(
110-
PrimitiveStyleBuilder::new()
111-
.stroke_color(Rgb565::BLUE)
112-
.stroke_width(1)
113-
.build(),
114-
)
97+
Circle::new(Point::new(64, 16), 16)
98+
.into_styled(PrimitiveStyle::with_stroke(Rgb565::BLUE, 1))
11599
.draw(&mut disp)
116100
.unwrap();
117101

examples/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn main() -> ! {
8585

8686
// Loads an 86x64px image encoded in LE (Little Endian) format. This image is a 16BPP image of
8787
// the Rust mascot, Ferris.
88-
let im = ImageRawLE::new(include_bytes!("./ferris.raw"), 86, 64);
88+
let im = ImageRawLE::new(include_bytes!("./ferris.raw"), 86);
8989

9090
Image::new(&im, Point::new((96 - 86) / 2, 0))
9191
.draw(&mut disp)

examples/rotation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ fn main() -> ! {
8686

8787
// Load a 1BPP 64x64px image with LE (Little Endian) encoding of the Rust logo, white foreground
8888
// black background
89-
let im = ImageRawLE::<BinaryColor>::new(include_bytes!("./rust.raw"), 64, 64);
89+
let im = ImageRawLE::<BinaryColor>::new(include_bytes!("./rust.raw"), 64);
9090

91-
// Map on/off image colours to Rgb565::BLACK/Rgb565::WHITE
92-
im.into_iter()
93-
.map(|p| Pixel(p.0, p.1.into()))
94-
.draw(&mut disp)
95-
.unwrap();
91+
// Use `color_converted` to create a wrapper that converts BinaryColors to Rgb565 colors to send
92+
// to the display.
93+
im.draw(&mut disp.color_converted()).unwrap();
9694

9795
disp.flush().unwrap();
9896

examples/text.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Print "Hello world!" with "Hello rust!" underneath. Uses the `embedded_graphics` crate to draw
2-
//! the text with a 6x8 pixel font.
2+
//! the text with a 6x10 and 9x18 pixel monospace font.
33
//!
44
//! This example is for the STM32F103 "Blue Pill" board using a 4 wire interface to the display on
55
//! SPI1.
@@ -22,13 +22,14 @@
2222

2323
use cortex_m_rt::{entry, exception, ExceptionFrame};
2424
use embedded_graphics::{
25-
egtext,
26-
fonts::{Font6x8, Text},
2725
geometry::Point,
26+
mono_font::{
27+
ascii::{FONT_6X10, FONT_9X18},
28+
MonoTextStyleBuilder,
29+
},
2830
pixelcolor::Rgb565,
2931
prelude::*,
30-
style::TextStyleBuilder,
31-
text_style,
32+
text::{Baseline, Text},
3233
};
3334
use panic_semihosting as _;
3435
use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
@@ -83,34 +84,28 @@ fn main() -> ! {
8384
disp.init().unwrap();
8485
disp.flush().unwrap();
8586

86-
// Red with a small amount of green creates a deep orange colour
87-
let rust = Rgb565::new(0xff, 0x07, 0x00);
88-
89-
Text::new("Hello world!", Point::zero())
90-
.into_styled(
91-
TextStyleBuilder::new(Font6x8)
92-
.text_color(Rgb565::WHITE)
93-
.build(),
94-
)
95-
.draw(&mut disp)
96-
.unwrap();
87+
let white_style = MonoTextStyleBuilder::new()
88+
.font(&FONT_6X10)
89+
.text_color(Rgb565::WHITE)
90+
.build();
9791

98-
Text::new("Hello Rust!", Point::new(0, 16))
99-
.into_styled(TextStyleBuilder::new(Font6x8).text_color(rust).build())
92+
Text::with_baseline("Hello world!", Point::zero(), white_style, Baseline::Top)
10093
.draw(&mut disp)
10194
.unwrap();
10295

103-
// Macros can also be used
104-
egtext!(
105-
text = "Hello macros!",
106-
top_left = (0, 0),
107-
style = text_style!(
108-
font = Font6x8,
109-
text_color = Rgb565::RED,
110-
background_color = Rgb565::GREEN
111-
)
96+
// Red with a small amount of green creates a deep orange colour
97+
let rust_style = MonoTextStyleBuilder::new()
98+
.font(&FONT_9X18)
99+
.text_color(Rgb565::new(0xff, 0x07, 0x00))
100+
.build();
101+
102+
Text::with_baseline(
103+
"Hello Rust!",
104+
// Position this text below "Hello world!", using the previous font's height
105+
Point::new(0, white_style.font.character_size.height as i32),
106+
rust_style,
107+
Baseline::Top,
112108
)
113-
.translate(Point::new(0, 24))
114109
.draw(&mut disp)
115110
.unwrap();
116111

src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const BUF_SIZE: usize = 96 * 64 * 2;
6161
/// .draw(&mut display)
6262
/// .unwrap();
6363
///
64-
/// Circle::new(Point::new(72, 16 + 8), 8)
64+
/// Circle::new(Point::new(64, 16), 16)
6565
/// .into_styled(PrimitiveStyle::with_stroke(Rgb565::BLUE, 1))
6666
/// .draw(&mut display)
6767
/// .unwrap();

0 commit comments

Comments
 (0)