pub struct FontString(/* private fields */);Expand description
A FontString is a collection of FontUnicode which can be rendered to frames for the LED
Matrix.
Implementations§
Source§impl FontString
impl FontString
Sourcepub fn chars(&self) -> Vec<char>
pub fn chars(&self) -> Vec<char>
Render the font string as a collection of unicode value points, Vec<char>.
Examples found in repository?
examples/letter.rs (line 25)
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}Sourcepub fn font_frames(&self, stroke: PixelColor, bg: PixelColor) -> Vec<FontFrame>
pub fn font_frames(&self, stroke: PixelColor, bg: PixelColor) -> Vec<FontFrame>
Returns a Vec<FontFrame> for each inner font.
Sourcepub fn pixel_frames(
&self,
stroke: PixelColor,
bg: PixelColor,
) -> Vec<PixelFrame>
pub fn pixel_frames( &self, stroke: PixelColor, bg: PixelColor, ) -> Vec<PixelFrame>
Returns a Vec<PixelFrame> for each inner font.
Examples found in repository?
examples/scroll-bottom-top.rs (line 23)
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 23)
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 23)
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 23)
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 FontString
impl Clone for FontString
Source§fn clone(&self) -> FontString
fn clone(&self) -> FontString
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 FontString
impl Debug for FontString
Source§impl Default for FontString
impl Default for FontString
Source§fn default() -> FontString
fn default() -> FontString
Returns the “default value” for a type. Read more
Source§impl Display for FontString
impl Display for FontString
Source§impl PartialEq for FontString
impl PartialEq for FontString
impl StructuralPartialEq for FontString
Auto Trait Implementations§
impl Freeze for FontString
impl RefUnwindSafe for FontString
impl Send for FontString
impl Sync for FontString
impl Unpin for FontString
impl UnwindSafe for FontString
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