Skip to main content

Module cells

Module cells 

Source
Expand description

A cell grid: a terminal’s screen as one node, rows × cols cells each with a character, a foreground, a background and attribute bits.

Build a slice of Cells, describe it with a CellGrid and hand it to Ui::cells with the node’s own spec. A glyph is shaped once per character and style variant and then placed at col × cell_w without shaping, so a pane whose every cell is new every frame costs the same as one that never changes. The node’s rows apply as on any node: an on_key makes it the terminal’s sink, an on_click or on_drag carries cell: {row, col}, selectable selects in cells, and its access row is terminal.

use kui_core::cells::{flags, Cell, CellGrid};
use kui_core::{CellCursor, Color, Core, NodeSpec, Size, TextStyle};

let (rows, cols) = (2, 4);
let mut cells = vec![Cell::default(); rows * cols];
for (i, ch) in "ab c".chars().enumerate() {
    cells[i] = Cell::new(ch, 0xffffffff, 0x0000ffff); // white on blue
}
cells[6] = Cell::new('x', 0xff0000ff, 0).with(flags::BOLD);

let mut core = Core::new();
let mut ui = core.frame(Size::new(400.0, 200.0), 1.0);
ui.cells(
    &CellGrid {
        rows,
        cols,
        cells: &cells,
        style: TextStyle::new(14.0).mono().line_height(20.0),
        cursor: Some((1, 2, CellCursor::Block, Color::WHITE)),
        origin_line: 0,
    },
    NodeSpec::default(),
);
ui.finish();

What it deliberately is not: shaped text. No ligatures, no kerning, no wrapping. A cell is one char: a precomposed character is one cell; a base with combining marks, a ZWJ emoji sequence or a flag is not representable, so the app precomposes what NFC can and drops the rest. A wide character is marked flags::WIDE and the cell after it is a spacer the app leaves blank. Box drawing, block elements and the Powerline separators are not shaped at all but rasterized from the cell box, so a TUI’s frames are seamless in any font.

Modules§

flags
Bits in Cell::flags.

Structs§

Cell
One cell: a character, its colours as 0xRRGGBBAA (a background of 0 is none, an underline colour of 0 the foreground’s), and attribute bits. Sixteen bytes, so a 200×50 pane is a 160 KB slice a frame.
CellGrid
A grid to draw: the cells in row-major order (rows × cols of them; fewer draw as blank), the style the glyphs are shaped in (size, line_height as the cell height, family / font), and the cursor.
CellStore
The frame’s grids and the glyph tables they draw from. The frame before it is kept too, the way the text store keeps its places: a host that reads the selection from inside its own view is asking about a frame that has not been built yet.
CellsId
Index into the frame’s grid list.

Enums§

CursorShape
How the grid’s cursor is drawn, in the colour given with it.