pub struct BitTile<const STORAGE_BYTES: usize> { /* private fields */ }Expand description
A bit tile is a 2D array of bits. It is used to store a 2D image in a compact way (where a pixel is represented by a single bit that can be either set or unset) The size of the bit tile is the STORAGE_BYTES generic parameter plus 2 bytes for the width and height. Since the width and height are stored in 2 bytes, the maximum size of the bit tile is 255 x 255 pixels. However, the STORAGE_BYTES parameter is limited to 1024 bytes, so the size of the tile should fit in this space.
Implementations§
Source§impl<const STORAGE_BYTES: usize> BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> BitTile<STORAGE_BYTES>
Sourcepub fn new(width: u8, height: u8) -> Option<Self>
pub fn new(width: u8, height: u8) -> Option<Self>
Creates a new bit tile with the specified width and height.
§Arguments
width- The width of the bit tile in pixels.height- The height of the bit tile in pixels.
§Returns
Some(BitTile)- If the bit tile was created successfully.None- If the width or height is 0 or if the bit tile does not fit in the allocated space.
Sourcepub fn set(&mut self, x: u32, y: u32, value: bool)
pub fn set(&mut self, x: u32, y: u32, value: bool)
Sets the value of the pixel (set or unset) at the specified coordinates. If the coordinates are outside the bounds of the bit tile, the operation is silently ignored.
§Arguments
x- The x coordinate of the pixel.y- The y coordinate of the pixel.value- The value of the pixel (set or unset).
Sourcepub fn clear(&mut self, value: bool)
pub fn clear(&mut self, value: bool)
Clears the bit tile by setting all pixels to the specified value.
§Arguments
value- The value to set all pixels to (set or unset).
Sourcepub fn to_string_format(&self) -> String
pub fn to_string_format(&self) -> String
Returns a string representation of the bit tile in the format of:
|...XX....XX...|
|..XXXX..XXXX..|
|.XXXXXXXXXXXX.|
|.XXXXXXXXXXXX.|
|..XXXXXXXXXX..|
|...XXXXXXXX...|
|....XXXXXX....|
|.....XXXX.....|
|......XX......|where:
X- a pixel that is set.- a pixel that is unset|- the start and end of a row
§Returns
String- The string representation of the bit tile.
Trait Implementations§
impl<const STORAGE_BYTES: usize> Copy for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> Eq for BitTile<STORAGE_BYTES>
Source§impl<const STORAGE_BYTES: usize> FromStr for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> FromStr for BitTile<STORAGE_BYTES>
Source§fn from_str(image: &str) -> Result<Self, Self::Err>
fn from_str(image: &str) -> Result<Self, Self::Err>
Creates a new bit tile from a string.
The format uses pipes (characters |) to delimit rows, and single characters to represent different colored pixels.
Since a tile is basically a black and white image, the characters used to represent the pixels are:
(space),.(point) - unset pixels- everything else - set pixels
For example, the following string will create a bit tile with a width of 14 and a height of 9:
use appcui::prelude::*;
use std::str::FromStr;
const HEART_TILE: &str = r#"
|...rr....rr...|
|..rrrr..rrrr..|
|.rrrrrrrrrrrr.|
|.rrrrrrrrrrrr.|
|..rrrrrrrrrr..|
| rrrrrrrr |
|....rrrrrr....|
|.....rrrr.....|
|......rr......|
"#;
// use 16 bytes to store the bit tile (14 x 9 = 126 pixels)
// a BitTile<16> implies 16 bytes x 8 bits/byte = 128 bits (128 pixels) maximum storage capacity.
// since 14 x 9 = 126 pixels, this is well within the maximum storage capacity.
let bit_tile: BitTile<16> = BitTile::from_str(HEART_TILE).unwrap();§Arguments
image- The string to create the bit tile from.
§Returns
Ok(BitTile)- If the bit tile was created successfully.Err(StringFormatError)- If the string is not a valid bit tile.
Source§type Err = StringFormatError
type Err = StringFormatError
Source§impl<const STORAGE_BYTES: usize> PartialEq for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> PartialEq for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> StructuralPartialEq for BitTile<STORAGE_BYTES>
Auto Trait Implementations§
impl<const STORAGE_BYTES: usize> Freeze for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> RefUnwindSafe for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> Send for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> Sync for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> Unpin for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> UnsafeUnpin for BitTile<STORAGE_BYTES>
impl<const STORAGE_BYTES: usize> UnwindSafe for BitTile<STORAGE_BYTES>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.