Skip to main content

TileBuffer

Struct TileBuffer 

Source
pub struct TileBuffer {
    pub tiles: Vec<TileEntry>,
    pub width_tiles: u16,
    pub height_tiles: u16,
    pub cursor: TilePos,
}
Expand description

A configurable-width tile grid representing the text rendering surface.

Each cell carries a tile ID and ink colour. The cursor tracks the current write position for the next character. Dimensions are set at construction time via TileBuffer::new.

Fields§

§tiles: Vec<TileEntry>

Row-major tile entries. tiles[y * width_tiles + x].

§width_tiles: u16

Width of the buffer in tiles.

§height_tiles: u16

Height of the buffer in tiles.

§cursor: TilePos

Current text cursor position.

Implementations§

Source§

impl TileBuffer

Source

pub fn new(width_tiles: u16, height_tiles: u16) -> Self

Creates a new, empty tile buffer with the cursor at (0, 0).

Examples found in repository?
examples/hello_dotzuki.rs (line 464)
460fn demo_dialog() {
461    println!("\n╔══ NPC DIALOG ═══════════════════════════╗");
462    let provider = HelloConfig::new();
463    let mut engine = DialogEngine::new(provider);
464    let mut buffer = TileBuffer::new(20, 18);
465
466    // "Greetings, young hero!" + DONE
467    let text: &[u8] = b"Greetings, young hero!";
468    let mut full = text.to_vec();
469    full.push(0xFF); // DONE
470
471    engine.open_dialog(&full);
472    while engine.is_active() { engine.update(&mut buffer); }
473
474    print!("║ Merlin: \"");
475    for i in 0..20usize {
476        let t = buffer.tiles[i].tile_id;
477        if (0x20..=0x7E).contains(&t) { print!("{}", t as u8 as char); }
478    }
479    println!("\"");
480    println!("╚══════════════════════════════════════════╝");
481}
Source

pub fn clear(&mut self)

Clears all tiles and resets the cursor to (0, 0).

Source

pub fn set_tile(&mut self, pos: TilePos, tile_id: u16, ink: u8)

Writes a tile at the given position. Silently does nothing if the position is out of bounds.

Examples found in repository?
examples/hello_dotzuki.rs (line 273)
270    fn render_char(&self, c: &AsciiChar, buffer: &mut TileBuffer) {
271        if let AsciiChar::Char(ch) = c {
272            let pos = buffer.cursor;
273            buffer.set_tile(pos, *ch as u16, 0);
274            buffer.cursor.x += 1;
275        }
276    }
Source

pub fn newline(&mut self)

Moves the cursor to the start of the next line. Does not wrap or scroll.

Source

pub fn scroll(&mut self)

Scrolls the entire buffer up by one row. The top row is discarded and the bottom row is filled with default entries.

Trait Implementations§

Source§

impl Default for TileBuffer

Source§

fn default() -> Self

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

Auto Trait Implementations§

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