# Vi in five minutes

```vi
main home:
  color: blue[50]
  arrange: center
  children:
    greeting:
      text: "Hello!"
      text_style: 32, bold, blue[700]
```

- `main home:` is the screen the app opens on. Everything on screen is a **container**.
- Each container has **attributes**, one per line: `name: value`.
- `children:` lists what is inside, one per line. A child can be written right there
  (`greeting:` with its own attributes) or by name (a container defined elsewhere).
- `arrange: center` puts the children in the middle. `text_style: 32, bold, blue[700]` is size,
  weight and colour, in any order.

## Data makes the screen change

```vi
count = 0

main counter:
  arrange: center
  space_between: 16
  children:
    display:
      text: "Count: {count}"
      text_style: 32
    plus:
      button: "+ 1"
      on_tap: count = count + 1
```

- `count = 0` is a **variable**. `{count}` puts its value inside text.
- `button: "+ 1"` makes a button with that label. `on_tap:` runs when it is tapped.
- When a variable changes, every container that uses it redraws by itself.

## Functions do the work

```vi
tasks = ["Buy milk", "Call Sam"]

add_task(name):
  tasks.add(name)

main home:
  space_inside: 20
  space_between: 10
  children:
    title:
      text: "{tasks.count} tasks"
      text_style: 24, bold
    task_row
    add:
      button: "Add one"
      on_tap: add_task("Task {tasks.count + 1}")

task_row:
  repeat: task in tasks
  size: max, auto
  space_inside: 12
  color: gray[100]
  shape: rounded
  text: task
  on_hold: tasks.remove(task)
```

- `add_task(name):` is a **function**: it has brackets after its name and holds statements.
- `repeat: task in tasks` draws one `task_row` for each item, and follows the list as it changes.
- `on_hold` runs on a long press: hold a row to remove it.

## Sizes, space and layout

```vi
main home:
  arrange: column, spread
  space_inside: 24
  children:
    banner:
      size: max, 30
      color: purple[400]
      shape: rounded
    tiles:
      size: max, auto
      arrange: row, spread
      children:
        tile_a:
          size: 30
          color: orange[300]
        tile_b:
          size: 30
          color: green[300]
        tile_c:
          size: 30
          color: blue[300]
```

- `size: width, height` is **out of 100 of the parent**: `size: max, 30` is full width and 30 % of
  the parent's height. One number makes a square. `max` fills, `auto` fits the content.
- Text sizes and spaces (`space_inside`, `space_between`, `space_around`) are fixed points, so
  they look the same on every phone.
- `arrange:` sets the direction (`row`, `column`), the spot (`center`, `top right`…) and the spread
  (`spread` puts the space between the children).
