Skip to content

Box

A box places up to nine children at fixed positions: the four corners, the four edges and the center. Children may overlap, which makes the box useful for badges, captions on images or controls on top of other content. A box clips its children and does not size itself by its content, so give it an explicit width and height.

Box

return HStack(
	Box(BoxLayout{
		TopLeading:     Text("TopLeading"),
		Center:         Text("Center"),
		BottomTrailing: Text("BottomTrailing"),
	}).BackgroundColor("#C9E7F8").
		Padding(Padding{}.All(L8)).
		Frame(Frame{}.Size(L320, L160)),

	BoxAlign(BottomTrailing, Text("BoxAlign")).
		BackgroundColor("#FDE2C4").
		Padding(Padding{}.All(L8)).
		Frame(Frame{}.Size(L200, L160)),
).Gap(L16)

Constructors

ConstructorDescription
Box(layout BoxLayout) TBoxCreates a box from a BoxLayout, whose fields Top, Center, Bottom, Leading, Trailing, TopLeading, TopTrailing, BottomLeading and BottomTrailing take the child for that position.
BoxAlign(alignment Alignment, child core.View) TBoxCreates a box with a single child at the given alignment.

Methods

MethodDescription
AccessibilityLabel(label string) DecoredViewSets a label used by screen readers for accessibility.
BackgroundColor(backgroundColor Color) DecoredViewSets the background color of the box.
Border(border Border) DecoredViewSets the border styling of the box.
DisableOutsidePointerEvents(disable bool) TBoxControls whether pointer events are disabled outside the box’s content.
Font(font Font) DecoredViewSets the font style for text content inside the box.
Frame(fr Frame) DecoredViewSets the layout frame of the box, including size and positioning.
FullWidth() TBoxSets the box to span the full available width.
Padding(p Padding) DecoredViewSets the inner spacing around the box’s children.
Visible(visible bool) DecoredViewControls the visibility of the box; setting false hides it.
WithFrame(fn func(Frame) Frame) DecoredViewApplies a transformation function to the box’s frame and returns the updated component.

Related