pub struct TileGrid { /* private fields */ }Expand description
A display region divided into tiles for low-memory drawing.
CydDisplay::for_each_tile redraws the same logical-display-coordinate
scene into each tile, clipping drawing to that tile before flushing it.
The tiled region may cover the full display or only a subregion. Some tiles may be smaller when the region does not divide evenly.
§Example
use device_envoy_core::{
UnwrapInfallible,
cyd::{
CydDisplay,
display::{CydFrame, tiling::TileGrid},
},
};
use embedded_graphics::{
Drawable,
pixelcolor::Rgb565,
prelude::{Point, Primitive, RgbColor, Size},
primitives::{Circle, Line, PrimitiveStyle, Rectangle},
};
// Tile the entire 320 × 240 display. The grid could instead cover a subregion.
const GRID: TileGrid = TileGrid::new(
Rectangle::new(Point::zero(), Size::new(320, 240)),
4, // columns
3, // rows
);
async fn draw<D: CydDisplay>(display: &mut D) -> Result<(), D::Error> {
display
.for_each_tile(GRID, |frame| {
frame.fill(Rgb565::BLACK);
Circle::new(Point::new(85, 45), 150)
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLUE))
.draw(frame)
.unwrap_infallible();
Line::new(Point::new(20, 210), Point::new(300, 30))
.into_styled(PrimitiveStyle::with_stroke(Rgb565::YELLOW, 5))
.draw(frame)
.unwrap_infallible();
// Outline the current tile's frame rectangle so the tiling is visible.
frame
.rectangle()
.into_styled(PrimitiveStyle::with_stroke(Rgb565::WHITE, 1))
.draw(frame)
.unwrap_infallible();
})
.await
}
assert_eq!(GRID.max_tile_pixel_count(), 80 * 80);A 320 × 240 region split into 4 × 3 tiles uses one 80 × 80 frame buffer.
The white outlines show the individual frames; the scene remains continuous
across their boundaries.
Implementations§
Source§impl TileGrid
impl TileGrid
Sourcepub const fn new(rectangle: Rectangle, columns: usize, rows: usize) -> TileGrid
pub const fn new(rectangle: Rectangle, columns: usize, rows: usize) -> TileGrid
Creates a grid splitting rectangle into columns × rows tiles.
rectangle.top_left determines where the tiled region is drawn and
flushed on the display.
Panics if either count is zero or exceeds the corresponding rectangle
dimension. See the TileGrid example for construction,
buffer sizing, and tiled drawing.
Sourcepub const fn tile_width(&self) -> usize
pub const fn tile_width(&self) -> usize
Nominal tile width: the rectangle width divided by the column count, rounded up.
Sourcepub const fn tile_height(&self) -> usize
pub const fn tile_height(&self) -> usize
Nominal tile height: the rectangle height divided by the row count, rounded up.
Sourcepub const fn max_tile_pixel_count(&self) -> usize
pub const fn max_tile_pixel_count(&self) -> usize
Largest pixel count any single tile can have.
Use this as the reusable frame-buffer capacity for
CydDisplay::for_each_tile. Edge tiles may be smaller when the region
does not divide evenly.
See the TileGrid example.