pub trait Layout {
    fn width(&self) -> usize;
    fn height(&self) -> usize;
    fn slices_per_tile(&self) -> usize;
    fn slices<'l, 'b>(
        &'l mut self,
        buffer: &'b mut [u8]
    ) -> Ref<'l, [Slice<'b, u8>]>; fn write(
        slices: &mut [Slice<'_, u8>],
        flusher: Option<&dyn Flusher>,
        fill: TileFill<'_>
    ); fn width_in_tiles(&self) -> usize { ... } fn height_in_tiles(&self) -> usize { ... } }
Expand description

A buffer’s layout description.

Implementors are supposed to cache sub-slices between uses provided they are being used with exactly the same buffer. This is achieved by storing a SliceCache in every layout implementation.

Required Methods§

Width in pixels.

Examples
let layout = LinearLayout::new(2, 3 * 4, 4);

assert_eq!(layout.width(), 2);

Height in pixels.

Examples
let layout = LinearLayout::new(2, 3 * 4, 4);

assert_eq!(layout.height(), 4);

Number of buffer sub-slices that will be passes to Layout::write.

Examples
let layout = LinearLayout::new(2, 3 * 4, 4);

assert_eq!(layout.slices_per_tile(), TILE_HEIGHT);

Returns self-stored sub-slices of buffer which are stored in a SliceCache.

Examples
let mut buffer = [
    [1; 4], [2; 4], [3; 4],
    [4; 4], [5; 4], [6; 4],
].concat();
let mut layout = LinearLayout::new(2, 3 * 4, 2);
let slices = layout.slices(&mut buffer);

assert_eq!(&*slices[0], &[[1; 4], [2; 4]].concat());
assert_eq!(&*slices[1], &[[4; 4], [5; 4]].concat());

Writes fill to slices, optionally calling the flusher.

Examples
let mut buffer = [
    [1; 4], [2; 4], [3; 4],
    [4; 4], [5; 4], [6; 4],
].concat();
let mut layout = LinearLayout::new(2, 3 * 4, 2);

LinearLayout::write(&mut *layout.slices(&mut buffer), None, TileFill::Solid([0; 4]));

assert_eq!(buffer, [
    [0; 4], [0; 4], [3; 4],
    [0; 4], [0; 4], [6; 4],
].concat());

Provided Methods§

Width in tiles.

Examples
let layout = LinearLayout::new(2 * TILE_WIDTH, 3 * TILE_WIDTH * 4, 4 * TILE_HEIGHT);

assert_eq!(layout.width_in_tiles(), 2);

Height in tiles.

Examples
let layout = LinearLayout::new(2 * TILE_WIDTH, 3 * TILE_WIDTH * 4, 4 * TILE_HEIGHT);

assert_eq!(layout.height_in_tiles(), 4);

Implementors§