pub struct FontCollection(/* private fields */);Implementations§
Source§impl FontCollection
impl FontCollection
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a default FontCollection, containing the Unicode constants
from the font8x8 crate, except for
MISC_FONTS, and SGA_FONTS (which are non-standard).
Examples found in repository?
examples/scroll-bottom-top.rs (line 18)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" ^^^123^^^ ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of CYAN and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::CYAN, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `bottom_to_top` method.
29 scroll.bottom_to_top().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}More examples
examples/scroll-left-right.rs (line 18)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" >>>123>>> ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of YELLOW and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::YELLOW, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `left_to_right` method.
29 scroll.left_to_right().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/scroll-top-bottom.rs (line 18)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" vvv123vvv ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of YELLOW and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::YELLOW, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `top_to_bottom` method.
29 scroll.top_to_bottom().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/scroll-right-left.rs (line 18)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" «««123««« ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of GREEN and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::GREEN, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `right_to_left` method.
29 scroll.right_to_left().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/rotate.rs (line 16)
14fn main() {
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16 let fonts = FontCollection::new();
17
18 for &(sym, color) in &[('Ñ', PixelColor::YELLOW), ('ó', PixelColor::MAGENTA)] {
19 let font = fonts.get(sym).unwrap();
20 let symbol = font_to_pixel_frame(font.byte_array(), color);
21 let symbol_90 = symbol.rotate(Rotate::Ccw90);
22 let symbol_180 = symbol.rotate(Rotate::Ccw180);
23 let symbol_270 = symbol.rotate(Rotate::Ccw270);
24 for _ in 0..=4 {
25 screen.write_frame(&symbol.frame_line());
26 ::std::thread::sleep(::std::time::Duration::from_millis(500));
27 screen.write_frame(&symbol_90.frame_line());
28 ::std::thread::sleep(::std::time::Duration::from_millis(500));
29 screen.write_frame(&symbol_180.frame_line());
30 ::std::thread::sleep(::std::time::Duration::from_millis(500));
31 screen.write_frame(&symbol_270.frame_line());
32 ::std::thread::sleep(::std::time::Duration::from_millis(500));
33 }
34 screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
35 }
36}examples/offset.rs (line 16)
14fn main() {
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16 let fonts = FontCollection::new();
17
18 for &(sym, color) in &[('þ', PixelColor::CYAN), ('ß', PixelColor::WHITE.dim(0.5))] {
19 let font = fonts.get(sym).unwrap();
20 let symbol = font_to_pixel_frame(font.byte_array(), color);
21
22 // Starts with an empty screen, then the symbol slides from the left,
23 // reaching the offset = 0 position, which renders the entire symbol on
24 // the screen.
25 for i in 0..=8 {
26 screen.write_frame(&symbol.offset(Offset::left(8 - i)).frame_line());
27 ::std::thread::sleep(::std::time::Duration::from_millis(500));
28 }
29 // Slides the displayed symbol to the right until it disappears.
30 for i in 0..=8 {
31 screen.write_frame(&symbol.offset(Offset::right(i)).frame_line());
32 ::std::thread::sleep(::std::time::Duration::from_millis(500));
33 }
34
35 // Starts with an empty screen, then the symbol slides from the top,
36 // reaching the offset = 0 position, which renders the entire symbol on
37 // the screen.
38 for i in 0..=8 {
39 screen.write_frame(&symbol.offset(Offset::top(8 - i)).frame_line());
40 ::std::thread::sleep(::std::time::Duration::from_millis(500));
41 }
42 // Slides the displayed symbol to the bottom until it disappears.
43 for i in 0..=8 {
44 screen.write_frame(&symbol.offset(Offset::bottom(i)).frame_line());
45 ::std::thread::sleep(::std::time::Duration::from_millis(500));
46 }
47 }
48 screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
49}Sourcepub fn from_hashmap(hashmap: HashMap<char, FontUnicode>) -> Self
pub fn from_hashmap(hashmap: HashMap<char, FontUnicode>) -> Self
Create a FontCollection with a custom HashMap of font symbols.
Sourcepub fn get(&self, symbol: char) -> Option<&FontUnicode>
pub fn get(&self, symbol: char) -> Option<&FontUnicode>
Get an Option with the symbol’s byte rendering.
Examples found in repository?
examples/letter.rs (line 26)
16fn main() {
17 let mut screen = Screen::open("/dev/fb1").unwrap();
18
19 let white_50_pct = PixelColor::WHITE.dim(0.5);
20
21 let letter = "Dear Toño, I am well. Thank you. Bye. - ゆにち";
22
23 let screen_text = FONT_COLLECTION.sanitize_str(letter).unwrap();
24
25 for unicode in screen_text.chars() {
26 if let Some(symbol) = FONT_COLLECTION.get(unicode) {
27 let frame = font_to_frame(symbol.byte_array(), white_50_pct);
28 screen.write_frame(&frame);
29 }
30 thread::sleep(Duration::from_millis(800));
31 }
32}More examples
examples/clip.rs (line 24)
15fn main() {
16 let mut screen = Screen::open("/dev/fb1").unwrap();
17
18 let letters = "a e i o u ";
19 let letter_color = PixelColor::YELLOW.dim(0.5);
20
21 let frames = letters
22 .chars()
23 .map(|sym| {
24 let font = FONT_COLLECTION.get(sym).unwrap();
25 font_to_pixel_frame(font.byte_array(), letter_color)
26 })
27 .collect::<Vec<PixelFrame>>();
28
29 // create a sequence of clips that will scroll each character-whitespace pair
30 // from appearing to move from right to left.
31 let frame_reel: Vec<PixelFrame> = frames.chunks(2).fold(Vec::new(), |mut v, chunk| match chunk
32 .len()
33 {
34 2 => {
35 let clip = chunk[0].build_clip(&chunk[1]);
36 for i in 0..=8 {
37 v.push(clip.offset(Offset::left(i)));
38 }
39 v
40 }
41 _ => panic!("this frame reel will only display &str of even length (divisible by 2)"),
42 });
43
44 for frame in &frame_reel {
45 screen.write_frame(&frame.frame_line());
46 ::std::thread::sleep(::std::time::Duration::from_millis(750));
47 }
48}examples/rotate.rs (line 19)
14fn main() {
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16 let fonts = FontCollection::new();
17
18 for &(sym, color) in &[('Ñ', PixelColor::YELLOW), ('ó', PixelColor::MAGENTA)] {
19 let font = fonts.get(sym).unwrap();
20 let symbol = font_to_pixel_frame(font.byte_array(), color);
21 let symbol_90 = symbol.rotate(Rotate::Ccw90);
22 let symbol_180 = symbol.rotate(Rotate::Ccw180);
23 let symbol_270 = symbol.rotate(Rotate::Ccw270);
24 for _ in 0..=4 {
25 screen.write_frame(&symbol.frame_line());
26 ::std::thread::sleep(::std::time::Duration::from_millis(500));
27 screen.write_frame(&symbol_90.frame_line());
28 ::std::thread::sleep(::std::time::Duration::from_millis(500));
29 screen.write_frame(&symbol_180.frame_line());
30 ::std::thread::sleep(::std::time::Duration::from_millis(500));
31 screen.write_frame(&symbol_270.frame_line());
32 ::std::thread::sleep(::std::time::Duration::from_millis(500));
33 }
34 screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
35 }
36}examples/offset.rs (line 19)
14fn main() {
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16 let fonts = FontCollection::new();
17
18 for &(sym, color) in &[('þ', PixelColor::CYAN), ('ß', PixelColor::WHITE.dim(0.5))] {
19 let font = fonts.get(sym).unwrap();
20 let symbol = font_to_pixel_frame(font.byte_array(), color);
21
22 // Starts with an empty screen, then the symbol slides from the left,
23 // reaching the offset = 0 position, which renders the entire symbol on
24 // the screen.
25 for i in 0..=8 {
26 screen.write_frame(&symbol.offset(Offset::left(8 - i)).frame_line());
27 ::std::thread::sleep(::std::time::Duration::from_millis(500));
28 }
29 // Slides the displayed symbol to the right until it disappears.
30 for i in 0..=8 {
31 screen.write_frame(&symbol.offset(Offset::right(i)).frame_line());
32 ::std::thread::sleep(::std::time::Duration::from_millis(500));
33 }
34
35 // Starts with an empty screen, then the symbol slides from the top,
36 // reaching the offset = 0 position, which renders the entire symbol on
37 // the screen.
38 for i in 0..=8 {
39 screen.write_frame(&symbol.offset(Offset::top(8 - i)).frame_line());
40 ::std::thread::sleep(::std::time::Duration::from_millis(500));
41 }
42 // Slides the displayed symbol to the bottom until it disappears.
43 for i in 0..=8 {
44 screen.write_frame(&symbol.offset(Offset::bottom(i)).frame_line());
45 ::std::thread::sleep(::std::time::Duration::from_millis(500));
46 }
47 }
48 screen.write_frame(&PixelFrame::new(&[PixelColor::BLACK; 64]).frame_line());
49}Sourcepub fn contains_key(&self, symbol: char) -> bool
pub fn contains_key(&self, symbol: char) -> bool
Search if collection has a symbol by its unicode key.
Sourcepub fn sanitize_str(&self, s: &str) -> Result<FontString, ScreenError>
pub fn sanitize_str(&self, s: &str) -> Result<FontString, ScreenError>
Sanitize a &str and create a new FontString.
Examples found in repository?
examples/letter.rs (line 23)
16fn main() {
17 let mut screen = Screen::open("/dev/fb1").unwrap();
18
19 let white_50_pct = PixelColor::WHITE.dim(0.5);
20
21 let letter = "Dear Toño, I am well. Thank you. Bye. - ゆにち";
22
23 let screen_text = FONT_COLLECTION.sanitize_str(letter).unwrap();
24
25 for unicode in screen_text.chars() {
26 if let Some(symbol) = FONT_COLLECTION.get(unicode) {
27 let frame = font_to_frame(symbol.byte_array(), white_50_pct);
28 screen.write_frame(&frame);
29 }
30 thread::sleep(Duration::from_millis(800));
31 }
32}More examples
examples/scroll-bottom-top.rs (line 20)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" ^^^123^^^ ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of CYAN and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::CYAN, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `bottom_to_top` method.
29 scroll.bottom_to_top().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/scroll-left-right.rs (line 20)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" >>>123>>> ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of YELLOW and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::YELLOW, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `left_to_right` method.
29 scroll.left_to_right().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/scroll-top-bottom.rs (line 20)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" vvv123vvv ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of YELLOW and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::YELLOW, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `top_to_bottom` method.
29 scroll.top_to_bottom().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}examples/scroll-right-left.rs (line 20)
13fn main() {
14 // Connect to our LED Matrix screen.
15 let mut screen = Screen::open("/dev/fb1").unwrap();
16
17 // Get the default `FontCollection`.
18 let fonts = FontCollection::new();
19 // Create a sanitized `FontString`.
20 let sanitized = fonts.sanitize_str(" «««123««« ").unwrap();
21 // Render the `FontString` as a vector of pixel frames, with
22 // a stroke color of GREEN and a BLACK background.
23 let pixel_frames = sanitized.pixel_frames(PixelColor::GREEN, PixelColor::BLACK);
24
25 // Create a `Scroll` from the pixel frame vector.
26 let scroll = Scroll::new(&pixel_frames);
27
28 // Consume the `FrameSequence` returned by the `right_to_left` method.
29 scroll.right_to_left().for_each(|frame| {
30 println!("Now printing:");
31 println!("{:?}", frame);
32 screen.write_frame(&frame.frame_line());
33 ::std::thread::sleep(::std::time::Duration::from_millis(250));
34 });
35}Trait Implementations§
Source§impl Clone for FontCollection
impl Clone for FontCollection
Source§fn clone(&self) -> FontCollection
fn clone(&self) -> FontCollection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FontCollection
impl Debug for FontCollection
Source§impl Default for FontCollection
impl Default for FontCollection
Source§impl PartialEq for FontCollection
impl PartialEq for FontCollection
impl StructuralPartialEq for FontCollection
Auto Trait Implementations§
impl Freeze for FontCollection
impl RefUnwindSafe for FontCollection
impl Send for FontCollection
impl Sync for FontCollection
impl Unpin for FontCollection
impl UnwindSafe for FontCollection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more