Skip to content
UrushiDocumentation

Layout

Layout determines where a View’s cells go and how much space they receive. It is not a second presentation model: layout operations construct and resolve the same View used by CLI output, prompts, TUIs, Canvas, and the Ratatui adapter.

Need Use Read
Margin, border, padding, dimensions, alignment, or overflow around one child View::block with BlockStyle Block geometry
Horizontal or vertical flow View::row or View::column Rows and columns
Shared column widths without table semantics View::grid with GridStyle Grid
A finite window onto larger content View::viewport Viewports and anchors
Report final geometry to a cursor, image, or host renderer View::anchor or View::anchor_block Viewports and anchors
Explicit coordinates, overlap, or connected lines View::canvas Canvas

BlockStyle contains both geometry and the appearance of cells created by a block. Its Rust name describes the value applied to a block; in this site its margin, border, padding, dimensions, alignment, and overflow are documented under Layout because those are layout tasks. Cell color and attributes remain under Styles.

Run the complete Layout quickstart ↓

This complete example gives two children weighted horizontal space inside a finite row:

use std::io;
use urushi::{BlockStyle, Border, Length, TextStyle, VerticalAlign, View};
fn main() -> io::Result<()> {
let panel = |label, weight| {
View::block(
BlockStyle::new()
.border(Border::ROUNDED)
.width(Length::fill(weight)),
View::text(label, TextStyle::new()),
)
};
let row = View::row(
VerticalAlign::Top,
[panel("build", 1), panel("tests", 2)],
);
let view = View::block(BlockStyle::new().width(30), row);
urushi::println_view(&view)
}

With 30 available columns, fill weights 1 and 2 divide the row into 10 and 20 columns:

Rendered output
╭────────╮╭──────────────────╮
│build ││tests │
╰────────╯╰──────────────────╯

The row owns horizontal allocation. Each block then resolves its border and child inside the width it receives. The resulting value is still one View and can be rendered by any Urushi surface.