Trait Layout
pub trait Layout {
// Required methods
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<'_>,
);
// Provided methods
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§
fn width(&self) -> usize
fn width(&self) -> usize
Width in pixels.
§Examples
let layout = LinearLayout::new(2, 3 * 4, 4);
assert_eq!(layout.width(), 2);
fn height(&self) -> usize
fn height(&self) -> usize
Height in pixels.
§Examples
let layout = LinearLayout::new(2, 3 * 4, 4);
assert_eq!(layout.height(), 4);
fn slices_per_tile(&self) -> usize
fn slices_per_tile(&self) -> usize
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);
fn slices<'l, 'b>(
&'l mut self,
buffer: &'b mut [u8],
) -> Ref<'l, [Slice<'b, u8>]>
fn slices<'l, 'b>( &'l mut self, buffer: &'b mut [u8], ) -> Ref<'l, [Slice<'b, u8>]>
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());
fn write(
slices: &mut [Slice<'_, u8>],
flusher: Option<&dyn Flusher>,
fill: TileFill<'_>,
)
fn write( slices: &mut [Slice<'_, u8>], flusher: Option<&dyn Flusher>, fill: TileFill<'_>, )
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§
fn width_in_tiles(&self) -> usize
fn width_in_tiles(&self) -> usize
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);
fn height_in_tiles(&self) -> usize
fn height_in_tiles(&self) -> usize
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);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.