Skip to main content

Tile

Struct Tile 

Source
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

Source

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.

Source

pub const fn glyph(&self) -> char

Returns the tile’s glyph (primary codepoint).

Source

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.

Source

pub const fn style(&self) -> Style

Returns the tile’s style.

Source

pub const fn dx(&self) -> i16

Returns the sub-cell pixel X offset.

Source

pub const fn dy(&self) -> i16

Returns the sub-cell pixel Y offset.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub const fn is_wide(&self) -> bool

Returns true if this tile is the left half of a 2-column wide character.

Source

pub const fn is_wide_spacer(&self) -> bool

Returns true if this tile is the invisible right-half spacer of a wide character.

Source

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.

Source

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.

Source

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).

Source

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§

Source§

impl Clone for Tile

Source§

fn clone(&self) -> Tile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tile

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for Tile

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Tile

Source§

fn eq(&self, other: &Tile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Tile

Source§

impl Eq for Tile

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).