Enum embedded_graphics::pixelcolor::BinaryColor
source · pub enum BinaryColor {
Off,
On,
}
Expand description
Binary color.
BinaryColor
is used for displays and images with two possible color states.
The interpretation of active and inactive states can be different for
different types of displays. A BinaryColor::On
might represent a black
pixel on an LCD and a white pixel on an OLED display.
To simplify the conversion from BinaryColor
to RGB and grayscale color
types the default conversions assume that BinaryColor::Off
is black and
BinaryColor::On
is white.
§Conversion between BinaryColor and bool
use embedded_graphics::pixelcolor::BinaryColor;
// A BinaryColor can be converted to a bool by using the is_on and is_off methods.
let color = BinaryColor::On;
assert!(color.is_on());
assert!(color.invert().is_off());
// BinaryColor implements From<bool>.
let bool_value = true;
let color: BinaryColor = bool_value.into();
assert_eq!(color, BinaryColor::On);
// this is equivalent to:
let bool_value = true;
let color = if bool_value {
BinaryColor::On
} else {
BinaryColor::Off
};
assert_eq!(color, BinaryColor::On);
Variants§
Implementations§
source§impl BinaryColor
impl BinaryColor
sourcepub fn invert(self) -> Self
pub fn invert(self) -> Self
Inverts the color.
§Examples
use embedded_graphics::pixelcolor::BinaryColor;
assert_eq!(BinaryColor::Off.invert(), BinaryColor::On);
assert_eq!(BinaryColor::On.invert(), BinaryColor::Off);
Trait Implementations§
source§impl Clone for BinaryColor
impl Clone for BinaryColor
source§fn clone(&self) -> BinaryColor
fn clone(&self) -> BinaryColor
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl ColorMapping<BinaryColor> for BinaryColor
impl ColorMapping<BinaryColor> for BinaryColor
source§fn char_to_color(c: char) -> Self
fn char_to_color(c: char) -> Self
Converts a char into a color of type
C
.source§fn color_to_char(color: BinaryColor) -> char
fn color_to_char(color: BinaryColor) -> char
Converts a color of type
C
into a char.source§impl Debug for BinaryColor
impl Debug for BinaryColor
source§impl Default for BinaryColor
impl Default for BinaryColor
source§impl From<BinaryColor> for Bgr555
impl From<BinaryColor> for Bgr555
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Bgr565
impl From<BinaryColor> for Bgr565
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Bgr888
impl From<BinaryColor> for Bgr888
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Gray2
impl From<BinaryColor> for Gray2
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Gray4
impl From<BinaryColor> for Gray4
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Gray8
impl From<BinaryColor> for Gray8
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for RawU1
impl From<BinaryColor> for RawU1
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Rgb555
impl From<BinaryColor> for Rgb555
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Rgb565
impl From<BinaryColor> for Rgb565
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<BinaryColor> for Rgb888
impl From<BinaryColor> for Rgb888
source§fn from(color: BinaryColor) -> Self
fn from(color: BinaryColor) -> Self
Converts to this type from the input type.
source§impl From<RawU1> for BinaryColor
impl From<RawU1> for BinaryColor
source§impl From<bool> for BinaryColor
impl From<bool> for BinaryColor
source§impl Hash for BinaryColor
impl Hash for BinaryColor
source§impl Ord for BinaryColor
impl Ord for BinaryColor
source§fn cmp(&self, other: &BinaryColor) -> Ordering
fn cmp(&self, other: &BinaryColor) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for BinaryColor
impl PartialEq for BinaryColor
source§fn eq(&self, other: &BinaryColor) -> bool
fn eq(&self, other: &BinaryColor) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for BinaryColor
impl PartialOrd for BinaryColor
source§fn partial_cmp(&self, other: &BinaryColor) -> Option<Ordering>
fn partial_cmp(&self, other: &BinaryColor) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl PixelColor for BinaryColor
impl PixelColor for BinaryColor
impl Copy for BinaryColor
impl Eq for BinaryColor
impl StructuralPartialEq for BinaryColor
Auto Trait Implementations§
impl RefUnwindSafe for BinaryColor
impl Send for BinaryColor
impl Sync for BinaryColor
impl Unpin for BinaryColor
impl UnwindSafe for BinaryColor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<C> IntoStorage for C
impl<C> IntoStorage for C
§type Storage = <<C as PixelColor>::Raw as RawData>::Storage
type Storage = <<C as PixelColor>::Raw as RawData>::Storage
The underlying storage type for the pixel color
source§fn into_storage(self) -> <C as IntoStorage>::Storage
fn into_storage(self) -> <C as IntoStorage>::Storage
Convert the
PixelColor
into its raw storage form