Scroll

Struct Scroll 

Source
pub struct Scroll(/* private fields */);
Expand description

A type representing a collection of PixelFrames that may be scrolled.

Implementations§

Source§

impl Scroll

Source

pub fn new(frames: &[PixelFrame]) -> Self

Creates a new scroll from a slice of PixelFrames.

§Panics

The scroll needs at least 2 PixelFrames to be created.

Examples found in repository?
examples/scroll-bottom-top.rs (line 26)
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
Hide additional examples
examples/scroll-left-right.rs (line 26)
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 26)
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 26)
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}
Source

pub fn frames(&self) -> &[PixelFrame]

Returns &[PixelFrame] with the pixel frames that constitute this scroll.

Source

pub fn clips(&self) -> Vec<Clip>

Returns Vec<Clip> with the pixel frames clips that may be rendered.

Source

pub fn reverse(&mut self)

Reverse the order of the inner pixel frames.

Source

pub fn len(&self) -> usize

Return the number of pixel frames in the scroll.

Source

pub fn is_empty(&self) -> bool

Returns true if the scroll has no pixel frames.

Source

pub fn right_to_left(&self) -> FrameSequence

Returns a FrameSequence iterator that moves the frames from the right to the left.

Examples found in repository?
examples/scroll-right-left.rs (line 29)
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}
Source

pub fn left_to_right(&self) -> FrameSequence

Returns a FrameSequence iterator that moves the frames from the left to the right.

Examples found in repository?
examples/scroll-left-right.rs (line 29)
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}
Source

pub fn top_to_bottom(&self) -> FrameSequence

Returns a FrameSequence iterator that moves the frames from the top to the bottom.

Examples found in repository?
examples/scroll-top-bottom.rs (line 29)
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}
Source

pub fn bottom_to_top(&self) -> FrameSequence

Returns a FrameSequence iterator that moves the frames from the bottom to the bottom.

Examples found in repository?
examples/scroll-bottom-top.rs (line 29)
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}

Trait Implementations§

Source§

impl Debug for Scroll

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<usize> for Scroll

Source§

type Output = PixelFrame

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &PixelFrame

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Scroll

Source§

fn eq(&self, other: &Scroll) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Scroll

Auto Trait Implementations§

§

impl Freeze for Scroll

§

impl RefUnwindSafe for Scroll

§

impl Send for Scroll

§

impl Sync for Scroll

§

impl Unpin for Scroll

§

impl UnwindSafe for Scroll

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.