Struct embedded_graphics::mock_display::MockDisplay
source · [−]pub struct MockDisplay<C> where
C: PixelColor, { /* private fields */ }
Expand description
Mock display struct
See the module documentation for usage and examples.
Implementations
sourceimpl<C> MockDisplay<C> where
C: PixelColor,
impl<C> MockDisplay<C> where
C: PixelColor,
sourcepub fn from_points<I>(points: I, color: C) -> Self where
I: IntoIterator<Item = Point>,
pub fn from_points<I>(points: I, color: C) -> Self where
I: IntoIterator<Item = Point>,
Create a mock display from an iterator of Point
s.
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(&[
" ## ",
"####",
"####",
" ## ",
]);
sourcepub fn set_allow_out_of_bounds_drawing(&mut self, value: bool)
pub fn set_allow_out_of_bounds_drawing(&mut self, value: bool)
Sets if out of bounds drawing is allowed.
If this is set to true
the bounds checks during drawing are disabled.
sourcepub fn set_allow_overdraw(&mut self, value: bool)
pub fn set_allow_overdraw(&mut self, value: bool)
Sets if overdrawing is allowed.
If this is set to true
the overdrawing is allowed.
sourcepub fn set_pixel(&mut self, point: Point, color: Option<C>)
pub fn set_pixel(&mut self, point: Point, color: Option<C>)
Changes the value of a pixel without bounds checking.
Panics
This method will panic if point
is outside the display bounding box.
sourcepub fn set_pixels(
&mut self,
points: impl IntoIterator<Item = Point>,
color: Option<C>
)
pub fn set_pixels(
&mut self,
points: impl IntoIterator<Item = Point>,
color: Option<C>
)
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.
sourcepub fn affected_area(&self) -> Rectangle
pub fn affected_area(&self) -> Rectangle
Returns the area that was affected by drawing operations.
sourcepub fn draw_pixel(&mut self, point: Point, color: C)
pub fn draw_pixel(&mut self, point: Point, color: C)
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)
.
sourcepub fn swap_xy(&self) -> MockDisplay<C>
pub fn swap_xy(&self) -> MockDisplay<C>
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(&[
"#####",
"# # #",
"# # #",
"# #",
" ",
"#####",
"# #",
"# # #",
"# ###",
]);
sourcepub fn map<CT, F>(&self, f: F) -> MockDisplay<CT> where
CT: PixelColor,
F: Fn(C) -> CT + Copy,
pub fn map<CT, F>(&self, f: F) -> MockDisplay<CT> where
CT: PixelColor,
F: Fn(C) -> CT + Copy,
Maps a MockDisplay<C>' to a
MockDisplay
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(&[
"....",
". #",
"####",
]);
sourcepub fn diff(&self, other: &MockDisplay<C>) -> MockDisplay<Rgb888>
pub fn diff(&self, other: &MockDisplay<C>) -> MockDisplay<Rgb888>
Compares the display to another display.
The following color code is used to show the difference between the displays:
Color | Description |
---|---|
None | The 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 |
sourceimpl<C> MockDisplay<C> where
C: PixelColor + ColorMapping,
impl<C> MockDisplay<C> where
C: PixelColor + ColorMapping,
sourcepub fn from_pattern(pattern: &[&str]) -> MockDisplay<C>
pub fn from_pattern(pattern: &[&str]) -> MockDisplay<C>
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.
sourcepub fn assert_eq(&self, other: &MockDisplay<C>)
pub fn assert_eq(&self, other: &MockDisplay<C>)
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.
sourcepub fn assert_eq_with_message<F>(&self, other: &MockDisplay<C>, msg: F) where
F: Fn(&mut Formatter<'_>) -> Result,
pub fn assert_eq_with_message<F>(&self, other: &MockDisplay<C>, msg: F) where
F: Fn(&mut Formatter<'_>) -> Result,
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.
sourcepub fn assert_pattern(&self, pattern: &[&str])
pub fn assert_pattern(&self, pattern: &[&str])
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.
sourcepub fn assert_pattern_with_message<F>(&self, pattern: &[&str], msg: F) where
F: Fn(&mut Formatter<'_>) -> Result,
pub fn assert_pattern_with_message<F>(&self, pattern: &[&str], msg: F) where
F: Fn(&mut Formatter<'_>) -> Result,
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
sourceimpl<C: Clone> Clone for MockDisplay<C> where
C: PixelColor,
impl<C: Clone> Clone for MockDisplay<C> where
C: PixelColor,
sourcefn clone(&self) -> MockDisplay<C>
fn clone(&self) -> MockDisplay<C>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<C> Debug for MockDisplay<C> where
C: PixelColor + ColorMapping,
impl<C> Debug for MockDisplay<C> where
C: PixelColor + ColorMapping,
sourceimpl<C> Default for MockDisplay<C> where
C: PixelColor,
impl<C> Default for MockDisplay<C> where
C: PixelColor,
sourceimpl<C> DrawTarget for MockDisplay<C> where
C: PixelColor,
impl<C> DrawTarget for MockDisplay<C> where
C: PixelColor,
type Color = C
type Color = C
The pixel color type the targetted display supports.
type Error = Infallible
type Error = Infallible
Error type to return when a drawing operation fails. Read more
sourcefn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error> where
I: IntoIterator<Item = Pixel<Self::Color>>,
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error> where
I: IntoIterator<Item = Pixel<Self::Color>>,
Draw individual pixels to the display without a defined order. Read more
sourcefn fill_contiguous<I>(
&mut self,
area: &Rectangle,
colors: I
) -> Result<(), Self::Error> where
I: IntoIterator<Item = Self::Color>,
fn fill_contiguous<I>(
&mut self,
area: &Rectangle,
colors: I
) -> Result<(), Self::Error> where
I: IntoIterator<Item = Self::Color>,
Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
sourceimpl<C> OriginDimensions for MockDisplay<C> where
C: PixelColor,
impl<C> OriginDimensions for MockDisplay<C> where
C: PixelColor,
sourceimpl<C: PixelColor> PartialEq<MockDisplay<C>> for MockDisplay<C>
impl<C: PixelColor> PartialEq<MockDisplay<C>> for MockDisplay<C>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcepub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcepub fn checked_cast_from(src: Src) -> Option<Dst>
pub fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> Dimensions for T where
T: OriginDimensions,
impl<T> Dimensions for T where
T: OriginDimensions,
sourcepub fn bounding_box(&self) -> Rectangle
pub fn bounding_box(&self) -> Rectangle
Returns the bounding box.
sourceimpl<T> DrawTargetExt for T where
T: DrawTarget,
impl<T> DrawTargetExt for T where
T: DrawTarget,
sourcefn translated(&mut self, offset: Point) -> Translated<'_, Self>
fn translated(&mut self, offset: Point) -> Translated<'_, Self>
Creates a translated draw target based on this draw target. Read more
sourcefn cropped(&mut self, area: &Rectangle) -> Cropped<'_, Self>
fn cropped(&mut self, area: &Rectangle) -> Cropped<'_, Self>
Creates a cropped draw target based on this draw target. Read more
sourcefn clipped(&mut self, area: &Rectangle) -> Clipped<'_, Self>
fn clipped(&mut self, area: &Rectangle) -> Clipped<'_, Self>
Creates a clipped draw target based on this draw target. Read more
sourcefn color_converted<C>(&mut self) -> ColorConverted<'_, Self, C> where
C: PixelColor + Into<Self::Color>,
fn color_converted<C>(&mut self) -> ColorConverted<'_, Self, C> where
C: PixelColor + Into<Self::Color>,
Creates a color conversion draw target. Read more
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcepub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcepub fn overflowing_cast_from(src: Src) -> (Dst, bool)
pub fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcepub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcepub fn saturating_cast_from(src: Src) -> Dst
pub fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcepub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcepub fn unwrapped_cast_from(src: Src) -> Dst
pub fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcepub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcepub fn wrapping_cast_from(src: Src) -> Dst
pub fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.