logo
pub struct MockDisplay<C> where
    C: PixelColor
{ /* private fields */ }
Expand description

Mock display struct

See the module documentation for usage and examples.

Implementations

Creates a new empty mock display.

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 PointsIter::points method.

Panics

This method will panic if the iterator returns a point that is outside the display bounding box.

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

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

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

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

Sets if out of bounds drawing is allowed.

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

Sets if overdrawing is allowed.

If this is set to true the overdrawing is allowed.

Returns the color of a pixel.

Changes the value of a pixel without bounds checking.

Panics

This method will panic if point is outside the display bounding box.

Sets the points in an iterator to the given color.

Panics

This method will panic if the iterator returns points outside the display bounding box.

Returns the area that was affected by drawing operations.

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 behavior 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 behavior can be disabled by calling set_allow_overdraw(true).

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(&[
    "#####",
    "# # #",
    "# # #",
    "#   #",
    "     ",
    "#####",
    "#   #",
    "# # #",
    "# ###",
]);

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(&[
    "....",
    ".  #",
    "####",
]);

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

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.

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.

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.

The output of the msg function will be prepended to the output if the assertion fails.

Panics

Panics if the displays aren’t equal.

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.

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.

The output of the msg function will be prepended to the output if the assertion fails.

Panics

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The pixel color type the targetted display supports.

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

Draw individual pixels to the display without a defined order. Read more

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more

Fill a given area with a solid color. Read more

Fill the entire display with a solid color. Read more

Returns the size of the bounding box.

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

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Returns the bounding box.

Creates a translated draw target based on this draw target. Read more

Creates a cropped draw target based on this draw target. Read more

Creates a clipped draw target based on this draw target. Read more

Creates a color conversion draw target. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Casts the value.

OverflowingCasts the value.

Casts the value.

Casts the value.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

UnwrappedCasts the value.

Casts the value.

WrappingCasts the value.