[][src]Struct embedded_graphics::mock_display::MockDisplay

pub struct MockDisplay<C> where
    C: PixelColor
{ /* fields omitted */ }

Mock display struct

See the module documentation for usage and examples.

Implementations

impl<C> MockDisplay<C> where
    C: PixelColor
[src]

pub fn new() -> Self[src]

Creates a new empty mock display.

pub fn set_allow_out_of_bounds_drawing(&mut self, value: bool)[src]

Sets if out of bounds drawing is allowed.

If this is set to true the bounds checks during drawing are disabled.

pub fn set_allow_overdraw(&mut self, value: bool)[src]

Sets if overdrawing is allowed.

If this is set to true the overdrawing is allowed.

pub fn get_pixel(&self, p: Point) -> Option<C>[src]

Returns the color of a pixel.

pub fn set_pixel(&mut self, point: Point, color: Option<C>)[src]

Changes the value of a pixel without bounds checking.

pub fn affected_area(&self) -> Rectangle[src]

Returns the area that was affected by drawing operations.

pub fn draw_pixel(&mut self, point: Point, color: C)[src]

Changes the color of a pixel.

Panics

If out of bounds draw checking is enabled (default), this method will panic if the point lies outside the display area. This behaviour can be disabled by calling set_allow_out_of_bounds_drawing(true).

Similarly, overdraw is checked by default and will panic if a point is drawn to the same coordinate twice. This behaviour can be disabled by calling set_allow_overdraw(true).

pub fn swap_xy(&self) -> MockDisplay<C>[src]

Returns a copy of with the content mirrored by swapping x and y.

Examples

use embedded_graphics::{mock_display::MockDisplay, pixelcolor::BinaryColor};

let display: MockDisplay<BinaryColor> = MockDisplay::from_pattern(&[
    "#### ####",
    "#    #   ",
    "###  # ##",
    "#    #  #",
    "#### ####",
]);

let mirrored = display.swap_xy();
mirrored.assert_pattern(&[
    "#####",
    "# # #",
    "# # #",
    "#   #",
    "     ",
    "#####",
    "#   #",
    "# # #",
    "# ###",
]);

pub fn map<CT, F>(&self, f: F) -> MockDisplay<CT> where
    CT: PixelColor,
    F: Fn(C) -> CT + Copy
[src]

Maps a MockDisplay<C>' to a MockDisplay` by applying a function to each pixel.

Examples

Invert a MockDisplay by applying BinaryColor::invert to the color of each pixel.

use embedded_graphics::{mock_display::MockDisplay, pixelcolor::BinaryColor};

let display: MockDisplay<BinaryColor> = MockDisplay::from_pattern(&[
    "####",
    "#  .",
    "....",
]);

let inverted = display.map(|c| c.invert());
inverted.assert_pattern(&[
    "....",
    ".  #",
    "####",
]);

pub fn diff(&self, other: &MockDisplay<C>) -> MockDisplay<Rgb888>[src]

Compares the display to another display.

The following color code is used to show the difference between the displays:

ColorDescription
NoneThe color of the pixel is equal in both displays.
Some(Rgb888::GREEN)The pixel was only set in self
Some(Rgb888::RED)The pixel was only set in other
Some(Rgb888::BLUE)The pixel was set to a different colors in self and other

impl MockDisplay<BinaryColor>[src]

pub fn from_points<I>(points: I) -> Self where
    I: IntoIterator<Item = Point>, 
[src]

Create a mock display from an iterator of Points.

This method can be used to create a mock display from the iterator produced by the Primitive::points method.

The color type used in the returned display is BinaryColor, which can be mapped to another color type using the map method.

Examples

use embedded_graphics::{prelude::*, primitives::Circle, mock_display::MockDisplay};

let circle = Circle::new(Point::new(0, 0), 4);

let mut display = MockDisplay::from_points(circle.points());

display.assert_pattern(&[
    " ## ",
    "####",
    "####",
    " ## ",
]);

impl<C> MockDisplay<C> where
    C: PixelColor + ColorMapping
[src]

pub fn from_pattern(pattern: &[&str]) -> MockDisplay<C>[src]

Creates a new mock display from a character pattern.

The color pattern is specified by a slice of string slices. Each string slice represents a row of pixels and every character a single pixel.

A space character in the pattern represents a pixel which wasn't modified by any drawing routine and is left in the default state. All other characters are converted by implementations of the ColorMapping trait.

pub fn assert_eq(&self, other: &MockDisplay<C>)[src]

Checks if the displays are equal.

An advanced output for failing tests can be enabled by setting the environment variable EG_FANCY_PANIC=1. See the module-level documentation for more details.

Panics

Panics if the displays aren't equal.

pub fn assert_pattern(&self, pattern: &[&str])[src]

Checks if the display is equal to the given pattern.

An advanced output for failing tests can be enabled, see the module-level documentation for more details.

Panics

Panics if the display content isn't equal to the pattern.

Trait Implementations

impl<C: Clone> Clone for MockDisplay<C> where
    C: PixelColor
[src]

impl<C: Copy> Copy for MockDisplay<C> where
    C: PixelColor
[src]

impl<C> Debug for MockDisplay<C> where
    C: PixelColor + ColorMapping
[src]

impl<C> Default for MockDisplay<C> where
    C: PixelColor
[src]

impl<C> DrawTarget for MockDisplay<C> where
    C: PixelColor
[src]

type Color = C

The pixel color type the targetted display supports.

type Error = Infallible

Error type to return when a drawing operation fails. Read more

impl<C> OriginDimensions for MockDisplay<C> where
    C: PixelColor
[src]

impl<C> PartialEq<MockDisplay<C>> for MockDisplay<C> where
    C: PixelColor
[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for MockDisplay<C> where
    C: RefUnwindSafe

impl<C> Send for MockDisplay<C> where
    C: Send

impl<C> Sync for MockDisplay<C> where
    C: Sync

impl<C> Unpin for MockDisplay<C> where
    C: Unpin

impl<C> UnwindSafe for MockDisplay<C> where
    C: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Dimensions for T where
    T: OriginDimensions
[src]

impl<T> DrawTargetExt for T where
    T: DrawTarget
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

impl<Src, Dst> LossyInto<Dst> for Src where
    Dst: LossyFrom<Src>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,