NUI / Components / Layout

Box

ImplementedLayout

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.

nui
children {
    Text ChildText {
        text: "THIS IS THE CHILD COMPONENT"
    }
}

Basic syntax

nui
Box ConstrainedBox {
    width: 240

    children {
        Text ChildText {
            text: "THIS IS THE CHILD COMPONENT"
        }
    }
}

Supported properties

PropertyTypeRequiredDefaultDescription
widthnumberNoAutoDesired width.
heightnumberNoAutoDesired height.
minWidthnumberNoUnsetMinimum width.
minHeightnumberNoUnsetMinimum height.
maxWidthnumberNoUnsetMaximum width.
maxHeightnumberNoUnsetMaximum height.
aspectRationumberNoUnsetTarget aspect ratio.
minAspectRationumberNoUnsetMinimum aspect ratio.
maxAspectRationumberNoUnsetMaximum aspect ratio.
paddingmarginNomargin(0)Inner padding.
horizontalAlignenumNoInheritedComponent horizontal alignment.
verticalAlignenumNoInheritedComponent vertical alignment.
contentHorizontalAlignenumNoInheritedChild horizontal alignment.
contentVerticalAlignenumNoInheritedChild vertical alignment.
layerintegerNoContext defaultLayer order inside layered parents.
visibleboolNotrueVisibility 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

nui
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.