---
title: "Layout"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/concepts/layout"
---
# Layout

Every drawing function takes a `Rect`: `x` and `y` from the top left, and `columns` and `rows`. The screen's rect is `frame.rect`. A component takes a rect for the part it draws, so you decide where each one goes.

`split` divides a rect into rows or columns. A positive size is that many cells; a negative size is a share of what is left, and the last share takes the rounding. For example, `[1, -1, 1]` is one row, all of the rest, and one row. `[24, -1]` with a gap of 1 is 24 columns, a one-column gap, and the rest.

`inset` shrinks a rect by a number of cells on every side, or by `[vertical, horizontal]`. `center` returns a rect of a fixed size in the middle of another, which is where a dialog goes.

`drawBox` draws a border around a rect and returns the rect inside it. The border can be `rounded`, `single`, `double`, or `heavy`, and the top edge can carry a title. `paint` fills a rect with spaces in a style, which makes a background. `text` writes one line and takes an optional clip rect; `write` clips at the right edge of the rect and never splits a wide character.

The HTML page runs [`examples/layout.ts`](https://github.com/vercel-labs/tui/blob/main/examples/layout.ts) here, in a terminal in the page.

```ts
import { center, createTestApp, drawBox, inset, paint, split, text } from "tui"

const app = createTestApp({
  columns: 40,
  rows: 10,
  view: (frame) => {
    const box = drawBox(frame.cells, frame.rect, { title: "Panel" })
    const [header, body] = split(box, "rows", [1, -1])
    const [left, right] = split(body, "columns", [-1, -1], 1)
    paint(frame, inset(left, 1), frame.theme.muted)
    text(frame, left.x + 1, left.y + 1, "Left")
    text(frame, right.x, right.y, "Right")
    text(frame, header.x, header.y, "Header", frame.theme.heading)
    const dialog = center(frame.rect, 20, 3)
    text(frame, dialog.x, dialog.y, "Dialog")
  },
})

console.log(app.screen().join("\n"))
```

Text that runs past the clip is cut there. Use `truncate` to add an ellipsis, and `wrap` to break a line at spaces before drawing it.
