NUI / Components / Layout
Box
Box wraps exactly one child and applies layout constraints.
Supported as a one-child layout wrapper.
Overview
Box wraps exactly one child and applies layout constraints.
When to use
- Use Box when one child needs width, height, min/max size, aspect ratio, or alignment constraints.
Children
Supports exactly one child.
children {
Text ChildText {
text: "THIS IS THE CHILD COMPONENT"
}
}Basic syntax
Box ConstrainedBox {
width: 240
children {
Text ChildText {
text: "THIS IS THE CHILD COMPONENT"
}
}
}Supported properties
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
width | number | No | Auto | Desired width. |
height | number | No | Auto | Desired height. |
minWidth | number | No | Unset | Minimum width. |
minHeight | number | No | Unset | Minimum height. |
maxWidth | number | No | Unset | Maximum width. |
maxHeight | number | No | Unset | Maximum height. |
aspectRatio | number | No | Unset | Target aspect ratio. |
minAspectRatio | number | No | Unset | Minimum aspect ratio. |
maxAspectRatio | number | No | Unset | Maximum aspect ratio. |
padding | margin | No | margin(0) | Inner padding. |
horizontalAlign | enum | No | Inherited | Component horizontal alignment. |
verticalAlign | enum | No | Inherited | Component vertical alignment. |
contentHorizontalAlign | enum | No | Inherited | Child horizontal alignment. |
contentVerticalAlign | enum | No | Inherited | Child vertical alignment. |
layer | integer | No | Context default | Layer order inside layered parents. |
visible | bool | No | true | Visibility flag. |
Contextual properties
Contextual property rules
Box may receive stack, canvas, grid, wrap, or ExpandableArea slot properties only when it is authored as a direct child of the matching parent. See section 7.
Full syntax example
Box ConstrainedBox {
width: 240
height: 96
minWidth: 160
minHeight: 64
maxWidth: 360
maxHeight: 140
aspectRatio: 1.777
minAspectRatio: 1.3
maxAspectRatio: 2.0
padding: margin(8)
horizontalAlign: center
verticalAlign: center
contentHorizontalAlign: center
contentVerticalAlign: center
layer: 1
visible: true
children {
Text ChildText {
text: "THIS IS THE CHILD COMPONENT"
}
}
}Limitations
- Box must contain exactly one child.