vi studio

Lessons · The language · 8 of 36

Arrange and place

Direction, spot and spread; floating with place.

arrange: says how a container lays out its children: the direction, the spot and the spread, in any order, all optional.

Vi works out the rest. You never say which axis is "main"; bottom right means the bottom right corner whichever way the children run.

Picture the container as a box and its children as a small stack. The spot says where in the box the stack sits; the first word is up or down, the second is left or right:

 arrange: center         arrange: top center
┌───────────────┐       ┌───────────────┐
│               │       │     [ A ]     │
│     [ A ]     │       │     [ B ]     │
│     [ B ]     │       │     [ C ]     │
│     [ C ]     │       │               │
│               │       │               │
└───────────────┘       └───────────────┘

 arrange: bottom right   arrange: row, center
┌───────────────┐       ┌───────────────┐
│               │       │               │
│               │       │               │
│          [ A ]│       │ [A]  [B]  [C] │
│          [ B ]│       │               │
│          [ C ]│       │               │
└───────────────┘       └───────────────┘

The spread shares out the free space instead of grouping the children at one spot: spread puts it only between them, even puts it around them too.

 arrange: spread         arrange: even
┌───────────────┐       ┌───────────────┐
│     [ A ]     │       │               │
│               │       │     [ A ]     │
│               │       │               │
│     [ B ]     │       │     [ B ]     │
│               │       │               │
│               │       │     [ C ]     │
│     [ C ]     │       │               │
└───────────────┘       └───────────────┘

Try every combination here:

main home:
  arrange: row, bottom right
  space_inside: 20
  space_between: 8
  color: indigo[50]
  children:
    a:
      size: 20
      color: indigo[300]
    b:
      size: 20
      color: indigo[500]
    c:
      size: 20
      color: indigo[700]

place: is for one container that should float above the others, pinned to a spot of its parent: place: bottom right for a round "+" button, or place: x, y to put its middle at a point out of 100 (place: 50, 10 is centred, near the top). Games move things this way.

main home:
  color: white
  children:
    message:
      text: "A list would go here"
      space_inside: 24
    add_button:
      place: bottom right
      space_around: 24
      size: 16
      shape: circle
      color: blue[600]
      button: "+"
      text_style: 28, white

Every example here runs in Vi Studio: open it in your browser (phones too) and press Start learning on the welcome page. Each code block there has a Try it button that runs it in the phone preview.

More in The language

About Vi. Vi is a free, open-source programming language for building real mobile apps. You describe each screen in plain words, and Vi compiles it to React Native (Expo) for Android, iOS and the web. Its editor, Vi Studio, runs on Windows, in any browser and on your phone, with the app running live as you type. Read more about Vi.