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
DrawCell::grapheme, streamed off
Grid::layers.
§Examples
use retroglyph_core::color::{Color, Style};
use retroglyph_core::tile::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 flags(&self) -> TileFlags
pub const fn flags(&self) -> TileFlags
Returns the role and occupancy flags for this tile: emptiness, wide-character halves,
EGC side-table presence, and multi-cell span roles (see TileFlags).
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 span_anchor_index(&self, idx: usize, cols: usize) -> Option<usize>
pub const fn span_anchor_index(&self, idx: usize, cols: usize) -> Option<usize>
Returns the flat index of this tile’s span anchor in a row-major buffer, given this
tile’s own flat idx and the buffer’s row stride cols.
None when this tile is not TileFlags::SPAN_COVERED (see span_offset), or when
the offset would land before the start of the buffer. This does not check idx against
the buffer’s length or that the anchor is in the same row-block as idx; a caller holding
a whole layer already knows both hold.
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 const fn is_wide(&self) -> bool
pub const fn is_wide(&self) -> bool
Returns true if this tile is the left half of a 2-column wide character.
Sourcepub const fn is_wide_spacer(&self) -> bool
pub const fn is_wide_spacer(&self) -> bool
Returns true if this tile is the invisible right-half spacer of a wide character.
Sourcepub const fn is_span_anchor(&self) -> bool
pub const fn is_span_anchor(&self) -> bool
Returns true if this tile is the top-left anchor of a multi-cell span (see
span).
Unlike span() != (1, 1), this is accurate for a 1x1 span: a span anchor whose declared
footprint happens to be one cell still reports true here, whereas its span() is
indistinguishable from a plain tile’s.
Sourcepub fn with_glyph(self, glyph: char) -> Self
pub fn with_glyph(self, glyph: char) -> Self
Sets the glyph for this tile (builder style).
Writing content marks the tile non-empty (see is_empty). Recomputes
the cached display width (see width) for the new glyph, and clears
TileFlags::WIDE_CHAR/TileFlags::WIDE_CHAR_SPACER, which describe the old glyph’s
role and would otherwise disagree with the recomputed width.
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).
Trait Implementations§
impl Copy for Tile
impl Eq for Tile
impl StructuralPartialEq for Tile
Auto Trait Implementations§
impl Freeze for Tile
impl RefUnwindSafe for Tile
impl Send for Tile
impl Sync for Tile
impl Unpin for Tile
impl UnsafeUnpin for Tile
impl UnwindSafe for Tile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).