Lessons · The language · 7 of 36
Size and space
size out of 100, and space_inside / between / around.
Boxes stretch with the screen; text and gaps stay the same.
size: width, height is out of 100 of the parent: width against the parent's width, height
against the parent's height. One number makes a square from the parent's width.
| Value | Means |
|---|---|
size: 50, 20 |
half as wide as the parent, a fifth as tall |
size: 30 |
a square, 30 % of the parent's width on each side |
size: max, auto |
fill the width, as tall as the content |
max |
fill the room that is left |
auto |
fit the content (the default) |
Space is in fixed points, the same on every phone:
| Attribute | The space… |
|---|---|
space_inside |
inside the container, around its children (padding) |
space_between |
between the children |
space_around |
outside the container (margin) |
The difference between space_inside and space_around is which side of the edge the space is on.
space_inside is part of the container: its colour, image and tap area fill it, and it pushes the
children away from the edge. space_around is outside: the parent shows through, and it pushes the
container away from its neighbours and its parent's edge.
One number is every side. Name the sides for different ones, in any combination:
space_inside: 16, top 32 or space_inside: left right 20, top bottom 8.
main page:
space_inside: 24, top 48
space_between: 12
children:
box_a:
size: max, 20
color: amber[300]
box_b:
size: 50, 20
color: amber[500]
space_around: left 40
box_c:
size: 25
color: amber[700]
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.
- Arrange and placeDirection, spot and spread; floating with place.
- 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.