Skip to main content

AttrGrid

Struct AttrGrid 

Source
pub struct AttrGrid<'a>(/* private fields */);
Available on crate feature cgb only.
Expand description

A rectangle of attribute bytes, with the row stride of the grid it sits in.

A level map is wider than a tilemap, so the strip that scrolls into view is not contiguous in the source. Binding the stride to the data rather than passing it alongside keeps the two from being paired wrongly, and the two kinds of grid are separate types so that one cannot be written where the other belongs.

const LEVEL: AttrGrid = AttrGrid::new(&DATA, 100);
map::write(d, Map::Zero, x, 0, LEVEL.sub(col, 0, 1, 18));

Implementations§

Source§

impl<'a> AttrGrid<'a>

Source

pub const fn new(data: &'a [u8], width: u8) -> Self

All of data, laid out width cells per row.

The height follows from the length, so a partial last row is dropped, and so is anything past row 255.

§Panics

If width is zero.

Source

pub const fn sub(self, x: u8, y: u8, w: u8, h: u8) -> Self

The w by h rectangle at (x, y) within this one.

Not checked here. One reaching outside the data it was built from is refused when it is written, not when it is taken.

Source

pub const fn width(self) -> u8

Cells across.

Source

pub const fn height(self) -> u8

Cells down.

Trait Implementations§

Source§

impl<'a> Clone for AttrGrid<'a>

Source§

fn clone(&self) -> AttrGrid<'a>

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<'a> Copy for AttrGrid<'a>

Auto Trait Implementations§

§

impl<'a> BankSafe for AttrGrid<'a>

§

impl<'a> Freeze for AttrGrid<'a>

§

impl<'a> RefUnwindSafe for AttrGrid<'a>

§

impl<'a> Send for AttrGrid<'a>

§

impl<'a> Sync for AttrGrid<'a>

§

impl<'a> Unpin for AttrGrid<'a>

§

impl<'a> UnsafeUnpin for AttrGrid<'a>

§

impl<'a> UnwindSafe for AttrGrid<'a>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CellValue for T
where T: Copy + BankSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.