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 678)
674fn demo_dialog() {
675    println!("\n╔══ NPC DIALOG ═══════════════════════════╗");
676    let provider = HelloConfig::new();
677    let mut engine = DialogEngine::new(provider);
678    let mut buffer = TileBuffer::new(20, 18);
679
680    // "Greetings, young hero!" + DONE
681    let text: &[u8] = b"Greetings, young hero!";
682    let mut full = text.to_vec();
683    full.push(0xFF); // DONE
684
685    engine.open_dialog(&full);
686    while engine.is_active() {
687        engine.update(&mut buffer);
688    }
689
690    print!("║ Merlin: \"");
691    for i in 0..20usize {
692        let t = buffer.tiles[i].tile_id;
693        if (0x20..=0x7E).contains(&t) {
694            print!("{}", t as u8 as char);
695        }
696    }
697    println!("\"");
698    println!("╚══════════════════════════════════════════╝");
699}
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 383)
380    fn render_char(&self, c: &AsciiChar, buffer: &mut TileBuffer) {
381        if let AsciiChar::Char(ch) = c {
382            let pos = buffer.cursor;
383            buffer.set_tile(pos, *ch as u16, 0);
384            buffer.cursor.x += 1;
385        }
386    }
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 = !

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.