[−][src]Struct sensehat_screen::frame::clip::Clip
A clip made of two PixelFrame
s.
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); }
Implementations
impl Clip
[src]
pub fn new(first: PixelFrame, second: PixelFrame) -> Self
[src]
Create a new Clip
from two PixelFrame
s.
pub fn offset(&self, offset: Offset) -> PixelFrame
[src]
Offset position for which to create the clipped PixelFrame
.
Trait Implementations
impl Clone for Clip
[src]
impl Copy for Clip
[src]
impl Debug for Clip
[src]
impl Default for Clip
[src]
impl PartialEq<Clip> for Clip
[src]
impl StructuralPartialEq for Clip
[src]
Auto Trait Implementations
impl RefUnwindSafe for Clip
impl Send for Clip
impl Sync for Clip
impl Unpin for Clip
impl UnwindSafe for Clip
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,