-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtext-fonts.rs
More file actions
65 lines (55 loc) · 1.88 KB
/
Copy pathtext-fonts.rs
File metadata and controls
65 lines (55 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! # Example: Fonts
//!
//! Demonstrate some of the available builtin fonts. A full list of fonts can be found in the
//! [embedded-graphics documentation](https://docs.rs/embedded-graphics).
use embedded_graphics::{
mono_font::{
ascii::{FONT_10X20, FONT_5X8, FONT_6X12, FONT_9X15},
MonoTextStyle, MonoTextStyleBuilder,
},
pixelcolor::BinaryColor,
prelude::*,
text::Text,
};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
fn main() -> Result<(), core::convert::Infallible> {
let mut display: SimulatorDisplay<BinaryColor> = SimulatorDisplay::new(Size::new(350, 200));
// Show smallest font with black font on white background (default value for fonts)
Text::new(
"Hello World! - default style 5x8",
Point::new(15, 15),
MonoTextStyle::new(&FONT_5X8, BinaryColor::On),
)
.draw(&mut display)?;
// Show smallest font with white font on black background
let style = MonoTextStyleBuilder::new()
.font(&FONT_5X8)
.text_color(BinaryColor::Off)
.background_color(BinaryColor::On)
.build();
Text::new("Hello World! - inverse 5x8", Point::new(15, 30), style).draw(&mut display)?;
// Show 6x12 Font
Text::new(
"Hello 6x12!",
Point::new(15, 45),
MonoTextStyle::new(&FONT_6X12, BinaryColor::On),
)
.draw(&mut display)?;
// Show 9x15 Font
Text::new(
"Hello 9x15!",
Point::new(15, 70),
MonoTextStyle::new(&FONT_9X15, BinaryColor::On),
)
.draw(&mut display)?;
// Show 10x20 Font
Text::new(
"Hello 10x20!",
Point::new(15, 95),
MonoTextStyle::new(&FONT_10X20, BinaryColor::On),
)
.draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new().scale(2).build();
Window::new("Fonts", &output_settings).show_static(&display);
Ok(())
}