Skip to main content

BitTile

Struct BitTile 

Source
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>

Source

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.
Source

pub fn width(&self) -> u8

Returns the width of the bit tile in pixels.

Source

pub fn height(&self) -> u8

Returns the height of the bit tile in pixels.

Source

pub fn size(&self) -> Size

Returns the size of the bit tile in pixels.

Source

pub fn get(&self, x: u32, y: u32) -> Option<bool>

Returns the value of the pixel (set or unset) at the specified coordinates.

§Arguments
  • x - The x coordinate of the pixel.
  • y - The y coordinate of the pixel.
§Returns
  • Some(bool) - If the pixel is set.
  • None - If the coordinates are outside the bounds of the bit tile.
Source

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).
Source

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).
Source

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.
Source§

impl BitTile<2>

Source

pub fn from_u16(width: u8, height: u8, bits: u16) -> Option<Self>

Source

pub fn to_u16(&self) -> u16

Source

pub fn reset(&mut self, bits: u16)

Source§

impl BitTile<4>

Source

pub fn from_u32(width: u8, height: u8, bits: u32) -> Option<Self>

Source

pub fn to_u32(&self) -> u32

Source

pub fn reset(&mut self, bits: u32)

Source§

impl BitTile<8>

Source

pub fn from_u64(width: u8, height: u8, bits: u64) -> Option<Self>

Source

pub fn to_u64(&self) -> u64

Source

pub fn reset(&mut self, bits: u64)

Source§

impl BitTile<16>

Source

pub fn from_u128(width: u8, height: u8, bits: u128) -> Option<Self>

Source

pub fn to_u128(&self) -> u128

Source

pub fn reset(&mut self, bits: u128)

Trait Implementations§

Source§

impl<const STORAGE_BYTES: usize> Clone for BitTile<STORAGE_BYTES>

Source§

fn clone(&self) -> BitTile<STORAGE_BYTES>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const STORAGE_BYTES: usize> Copy for BitTile<STORAGE_BYTES>

Source§

impl<const STORAGE_BYTES: usize> Debug for BitTile<STORAGE_BYTES>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const STORAGE_BYTES: usize> Eq for BitTile<STORAGE_BYTES>

Source§

impl<const STORAGE_BYTES: usize> FromStr for BitTile<STORAGE_BYTES>

Source§

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

The associated error which can be returned from parsing.
Source§

impl<const STORAGE_BYTES: usize> PartialEq for BitTile<STORAGE_BYTES>

Source§

fn eq(&self, other: &BitTile<STORAGE_BYTES>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more