pub struct Tile { /* private fields */ }Expand description
A single drawable tile in the terminal grid.
Each tile occupies one cell on a single layer; a Grid
holds up to 256 independent layers of tiles per cell, composited
bottom-to-top. Sub-cell pixel offsets (dx, dy) are visual only, they do
not affect grid logic or hit-testing. Backends that cannot represent pixel
offsets (e.g. CrosstermBackend) ignore them.
A tile does not carry its own multi-codepoint grapheme text (see
TileFlags::HAS_EXTRA): that lives in a sparse side-table on the owning
Grid, keeping every Tile a small, fully Copy
value regardless of whether the egc feature is enabled. Read it back via
Grid::grapheme.
§Examples
use retroglyph_core::{Color, Style, Tile};
let tile = Tile::new('@', Style::new().fg(Color::GREEN));
assert_eq!(tile.glyph(), '@');
assert_eq!(tile.style().foreground(), Color::GREEN);Implementations§
Source§impl Tile
impl Tile
Sourcepub fn new(glyph: char, style: Style) -> Self
pub fn new(glyph: char, style: Style) -> Self
Creates a new tile with the given glyph and style.
dx and dy default to 0 (no sub-cell offset). glyph’s display width is computed
once here (see width) rather than on every render.
Sourcepub const fn width(&self) -> u16
pub const fn width(&self) -> u16
Returns the precomputed display (column) width of glyph.
Computed once when the glyph is written (see with_glyph and
Grid::write_grapheme), not recomputed on every
render. For tiles written via write_grapheme, this reflects the full grapheme cluster’s
width, not just the primary codepoint’s.
Sourcepub const fn span(&self) -> (u16, u16)
pub const fn span(&self) -> (u16, u16)
Returns how many cells this tile occupies, (width, height).
(1, 1) for every tile except a TileFlags::SPAN_ANCHOR, which reports the footprint
declared by Grid::write_span. A covered cell reports
(1, 1): it does not own a footprint, it is inside one (see
span_offset).
Sourcepub const fn span_offset(&self) -> Option<(u16, u16)>
pub const fn span_offset(&self) -> Option<(u16, u16)>
Returns this tile’s (dx, dy) offset back to its span anchor, or None when it is not
covered by one.
A covered cell at (x, y) has its anchor at (x - dx, y - dy), so a backend holding a
whole layer reaches it with one subtraction. A caller holding a
Grid should use
Grid::span_owner instead, which handles the bounds and
the anchor-cell case too.
Sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns true if nothing has been written to this tile.
Empty tiles are transparent when compositing layers. An explicit
space (e.g. Tile::new(' ', style)) is not empty.
Sourcepub fn with_glyph(self, glyph: char) -> Self
pub fn with_glyph(self, glyph: char) -> Self
Sourcepub const fn with_style(self, style: Style) -> Self
pub const fn with_style(self, style: Style) -> Self
Sets the style for this tile (builder style).
Writing content marks the tile non-empty (see is_empty).
Sourcepub const fn with_offset(self, dx: i16, dy: i16) -> Self
pub const fn with_offset(self, dx: i16, dy: i16) -> Self
Sets the sub-cell pixel offset for this tile (builder style).
Writing content marks the tile non-empty (see is_empty).