Struct sensehat_screen::frame::clip::Clip[][src]

pub struct Clip { /* fields omitted */ }

A clip made of two PixelFrames.

Horizontal Clip

In horizontal clips, frames are placed side-by-side, and a Clip is specified using either Offset::Right(_), or Offset::Left(_) with the Clip::offset method.

Offset::Right(_)

                |---------------|
                |    Right(8)   |
                |---------------|
              |---------------| |
              |    Right(7)   | |
              |---------------| |
            |---------------| | |
            |    Right(6)   | | |
            |---------------| | |
          |---------------| | | |
          |    Right(5)   | | | |
          |---------------| | | |
        |---------------| | | | |
        |    Right(4)   | | | | |
        |---------------| | | | |
      |---------------| | | | | |
      |    Right(3)   | | | | | |
      |---------------| | | | | |
    |---------------| | | | | | |
    |    Right(2)   | | | | | | |
    |---------------| | | | | | |
  |---------------| | | | | | | |
  |    Right(1)   | | | | | | | |
  |---------------| | | | | | | |
|---------------| | | | | | | | |
|    Right(0)   | | | | | | | | |
|---------------| | | | | | | | |
                | | | | | | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|  <- individual frame COLUMN index
|---------------|---------------|
|    frame 1    |    frame 2    |
|---------------|---------------|

Example

extern crate sensehat_screen;
use sensehat_screen::{Clip, PixelColor, PixelFrame};
use sensehat_screen::Offset;

fn main() {
    let frame_1 = PixelFrame::new(&[PixelColor::YELLOW; 64]);
    let frame_2 = PixelFrame::new(&[PixelColor::BLUE; 64]);
    let clip = Clip::new(frame_1, frame_2);
    // Offset of `0`, shows the first frame.
    assert_eq!(clip.offset(Offset::Right(0)), frame_1);

    let offset_2_cols = clip.offset(Offset::Right(2)).as_columns();


    let expected_cols = &[
        [PixelColor::BLUE; 8],
        [PixelColor::BLUE; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
    ];
    assert_eq!(&offset_2_cols, expected_cols);

    // Offset of `8`, shows the second frame.
    assert_eq!(clip.offset(Offset::Right(8)), frame_2);
}

Offset::Left(_)

                |---------------|
                |    Left(0)    |
                |---------------|
              |---------------| |
              |    Left(1)    | |
              |---------------| |
            |---------------| | |
            |    Left(2)    | | |
            |---------------| | |
          |---------------| | | |
          |    Left(3)    | | | |
          |---------------| | | |
        |---------------| | | | |
        |    Left(4)    | | | | |
        |---------------| | | | |
      |---------------| | | | | |
      |    Left(5)    | | | | | |
      |---------------| | | | | |
    |---------------| | | | | | |
    |    Left(6)    | | | | | | |
    |---------------| | | | | | |
  |---------------| | | | | | | |
  |    Left(7)    | | | | | | | |
  |---------------| | | | | | | |
|---------------| | | | | | | | |
|    Left(8)    | | | | | | | | |
|---------------| | | | | | | | |
                | | | | | | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|  <- individual frame COLUMN index
|---------------|---------------|
|      frame 2  |      frame 1  |
|---------------|---------------|

Example

extern crate sensehat_screen;
use sensehat_screen::{Clip, PixelColor, PixelFrame};
use sensehat_screen::Offset;

fn main() {
    let frame_1 = PixelFrame::new(&[PixelColor::YELLOW; 64]);
    let frame_2 = PixelFrame::new(&[PixelColor::BLUE; 64]);
    let clip = Clip::new(frame_1, frame_2);
    // Offset of `0`, shows the first frame.
    assert_eq!(clip.offset(Offset::Left(0)), frame_1);

    let offset_4_cols = clip.offset(Offset::Left(4)).as_columns();

    let expected_cols = &[
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::YELLOW; 8],
        [PixelColor::BLUE; 8],
        [PixelColor::BLUE; 8],
        [PixelColor::BLUE; 8],
        [PixelColor::BLUE; 8],
    ];
    assert_eq!(&offset_4_cols, expected_cols);

    // Offset of `8`, shows the second frame.
    assert_eq!(clip.offset(Offset::Left(8)), frame_2);
}

Vertical Clip

In vertical clips, frames are placed above-and-belowe each other, and a Clip is specified using either Offset::Bottom(_), or Offset::Top(_) with the Clip::offset method.

Offset::Bottom(_)

                |---------------|
                |   Bottom(0)   |
                |---------------|
              |---------------| |
              |   Bottom(1)   | |
              |---------------| |
            |---------------| | |
            |   Bottom(2)   | | |
            |---------------| | |
          |---------------| | | |
          |   Bottom(3)   | | | |
          |---------------| | | |
        |---------------| | | | |
        |   Bottom(4)   | | | | |
        |---------------| | | | |
      |---------------| | | | | |
      |   Bottom(5)   | | | | | |
      |---------------| | | | | |
    |---------------| | | | | | |
    |   Bottom(6)   | | | | | | |
    |---------------| | | | | | |
  |---------------| | | | | | | |
  |   Bottom(7)   | | | | | | | |
  |---------------| | | | | | | |
|---------------| | | | | | | | |
|   Bottom(8)   | | | | | | | | |
|---------------| | | | | | | | |
                | | | | | | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|  <- individual frame ROW index
|---------------|---------------|
|      frame 2  |      frame 1  |
|---------------|---------------|

Example

extern crate sensehat_screen;
use sensehat_screen::{Clip, PixelColor, PixelFrame};
use sensehat_screen::Offset;

fn main() {
    let frame_1 = PixelFrame::new(&[PixelColor::MAGENTA; 64]);
    let frame_2 = PixelFrame::new(&[PixelColor::WHITE; 64]);
    let clip = Clip::new(frame_1, frame_2);
    // Offset of `0`, shows the first frame.
    assert_eq!(clip.offset(Offset::Bottom(0)), frame_1);

    let offset_2_rows = clip.offset(Offset::Bottom(2)).as_rows();

    let expected_rows = &[
        [PixelColor::WHITE; 8],
        [PixelColor::WHITE; 8],
        [PixelColor::MAGENTA; 8],
        [PixelColor::MAGENTA; 8],
        [PixelColor::MAGENTA; 8],
        [PixelColor::MAGENTA; 8],
        [PixelColor::MAGENTA; 8],
        [PixelColor::MAGENTA; 8],
    ];
    assert_eq!(&offset_2_rows, expected_rows);

    // Offset of `8`, shows the second frame.
    assert_eq!(clip.offset(Offset::Bottom(8)), frame_2);
}

Offset::Top(_)

                |---------------|
                |    Top(8)     |
                |---------------|
              |---------------| |
              |    Top(7)     | |
              |---------------| |
            |---------------| | |
            |    Top(6)     | | |
            |---------------| | |
          |---------------| | | |
          |    Top(5)     | | | |
          |---------------| | | |
        |---------------| | | | |
        |    Top(4)     | | | | |
        |---------------| | | | |
      |---------------| | | | | |
      |    Top(3)     | | | | | |
      |---------------| | | | | |
    |---------------| | | | | | |
    |    Top(2)     | | | | | | |
    |---------------| | | | | | |
  |---------------| | | | | | | |
  |    Top(1)     | | | | | | | |
  |---------------| | | | | | | |
|---------------| | | | | | | | |
|    Top(0)     | | | | | | | | |
|---------------| | | | | | | | |
                | | | | | | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|  <- individual frame ROW index
|---------------|---------------|
|    frame 1    |    frame 2    |
|---------------|---------------|

Example

extern crate sensehat_screen;
use sensehat_screen::{Clip, PixelColor, PixelFrame};
use sensehat_screen::Offset;

fn main() {
    let frame_1 = PixelFrame::new(&[PixelColor::GREEN; 64]);
    let frame_2 = PixelFrame::new(&[PixelColor::BLACK; 64]);
    let clip = Clip::new(frame_1, frame_2);
    // Offset of `0`, shows the first frame.
    assert_eq!(clip.offset(Offset::Top(0)), frame_1);

    let offset_7_rows = clip.offset(Offset::Top(7)).as_rows();

    let expected_rows = &[
        [PixelColor::GREEN; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
        [PixelColor::BLACK; 8],
    ];

    assert_eq!(&offset_7_rows, expected_rows);

    // Offset of `8`, shows the second frame.
    assert_eq!(clip.offset(Offset::Left(8)), frame_2);
}

Methods

impl Clip
[src]

Create a new Clip from two PixelFrames.

Offset position for which to create the clipped PixelFrame.

Trait Implementations

impl Copy for Clip
[src]

impl Clone for Clip
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Clip
[src]

Formats the value using the given formatter. Read more

impl Default for Clip
[src]

Returns the "default value" for a type. Read more

impl PartialEq for Clip
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl Send for Clip

impl Sync for Clip