Trait Frame

Source
pub trait Frame: Copy + Default {
    type Mtx: Matrix;

    const COLS: usize = <Self::Mtx>::MATRIX_COLS;
    const ROWS: usize = <Self::Mtx>::MATRIX_ROWS;

    // Required methods
    fn row_plan(&self, row: usize) -> &RowPlan;
    fn row_plan_mut(&mut self, row: usize) -> &mut RowPlan;

    // Provided method
    fn set<T>(&mut self, image: &T)
       where T: Render + ?Sized { ... }
}
Expand description

A ‘Compiled’ representation of an image to be displayed.

Frames are populated from images implementing Render, then passed on to Display::set_frame().

§Implementing Frame

Implementations of Frame do two things:

  • specify the Matrix used to convert between image and matrix coordinates
  • act like an array of RowPlans, one for each matrix row.

Note that implementations of Frame must also implement Copy and Default.

§Example implementation

#[derive(Copy, Clone)]
struct SimpleFrame (
    [RowPlan; 3]
);

impl Default for SimpleFrame {
    fn default() -> SimpleFrame {
        SimpleFrame([RowPlan::default(); SimpleFrame::ROWS])
    }
}

impl Frame for SimpleFrame {
    type Mtx = SimpleMatrix;

    fn row_plan(&self, row: usize) -> &RowPlan {
        &self.0[row]
    }

    fn row_plan_mut(&mut self, row: usize) -> &mut RowPlan {
        &mut self.0[row]
    }
}

Provided Associated Constants§

Source

const COLS: usize = <Self::Mtx>::MATRIX_COLS

The number of pins connected to LED columns.

Source

const ROWS: usize = <Self::Mtx>::MATRIX_ROWS

The number of pins connected to LED rows.

Required Associated Types§

Source

type Mtx: Matrix

The Matrix used to convert between image and matrix coordinates.

Required Methods§

Source

fn row_plan(&self, row: usize) -> &RowPlan

Returns a reference to the RowPlan for a row of LEDs.

§Panics

Panics if row is not in the range 0..ROWS

Source

fn row_plan_mut(&mut self, row: usize) -> &mut RowPlan

Returns a mutable reference to the RowPlan for a row of LEDs.

§Panics

Panics if row is not in the range 0..ROWS

Provided Methods§

Source

fn set<T>(&mut self, image: &T)
where T: Render + ?Sized,

Stores a new image into the frame.

Example:

frame.set(GreyscaleImage::blank());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Frame for MicrobitFrame

Source§

type Mtx = MicrobitMatrix