Layouts
Parent elements lay out their child elements in one of three ways:
- Paragraphs
- Stacks
- Overlays
These simple stacking rules allow creating quite sophisticated layouts.
pub fn RenderLeaderboardRow(playerName, userId, rating, [color, ui]) {
ShinyPanel(backgroundColor=color, vPadding=0.4) { // ShinyPanel is a VStack like most other stacking elements
HStack { // Change to an HStack so we can stack horizontally
P(fontSize=1.2, bold=true) {
SubtleLink(ProfilePage(userId)) {
%(playerName)
}
}
Spacer // Take up all remaining space in between the two elements
P { // This element appears on the right because of the Spacer
%(rating.Rating.FormatWithDecimals(0))
" rating"
}
}
}
}
Paragraphs
Paragraph elements (for example P or Button) lay out each child horizontally one after the other, wrapping to the next line when the line is full.
Stacks
Stacks (for example VStack, HStack or Panel) lay out their children either horizontally or vertically, one after the other.
Paragraphs should be used for text, whereas Stacks should be used for layout.
Most stacking elements (VStack, Panel) will stack vertically,
except for HStack and Toolbar which stack horizontally.
Place an HStack inside of a VStack or vice versa to change stacking direction.
Making a grid with stacks
Use the wrap=true parameter on an HStack or VStack to create a grid layout.
Once a particular row or column is full, it will automatically wrap to the next row or column,
creating a grid.