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.
- Direction:
column(top to bottom, the default) orrow(left to right). - Spot:
top,bottom,left,right,center, or a pair likebottom right. - Spread:
spreadputs the free space between the children;evenputs it around them too. scrollmakes the container scroll when its children don't fit.
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
- Comments and names# comments, <# blocks #> and snake_case names.
- ContainersEverything on screen is a container; children one per line.
- Size and spacesize out of 100, and space_inside / between / around.
- Texttext and text_style.
- Colour, shape and imagesColours and shades, shape, shadow, see_through, outline, @images.
- Buttons, inputs and other kindsbutton, input, search, icon, link and scrolling lists.
- Eventson_tap, on_hold, on_touch, on_swipe, on_change, on_submit, on_hit.
- Data: lists and objectsVariables, lists, objects and the list helpers.
- FunctionsYour own functions and the built-in ones.
- Conditions and loopsif / else, the inline if, and, or, not, for and while.
- Programs without a screenmain functions and print().
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.