Skip to main content

LensStudio:Ui.BoxLayout

Class

Layout manager arranging widgets in a row or column.

Index

Example

const root = new Widget(parent);
const mainLayout = new BoxLayout();
mainLayout.setDirection(Direction.TopToBottom);
mainLayout.spacing = 12;
root.layout = mainLayout;

// Section 1: Vertical layout (TopToBottom)
const sec1 = new Label(root);
sec1.text = '1. Direction.TopToBottom';
sec1.fontRole = FontRole.TitleBold;
mainLayout.addWidget(sec1);

const vBox = new Widget(root);
const vLayout = new BoxLayout();
vLayout.setDirection(Direction.TopToBottom);
vLayout.spacing = 4;
vBox.layout = vLayout;
for (const t of ['First', 'Second', 'Third']) {
const l = new Label(vBox);
l.text = ` ${t}`;
vLayout.addWidget(l);
}
mainLayout.addWidget(vBox);

// Section 2: Horizontal layout (LeftToRight)
const sec2 = new Label(root);
sec2.text = '2. Direction.LeftToRight';
sec2.fontRole = FontRole.TitleBold;
mainLayout.addWidget(sec2);

const hBox = new Widget(root);
const hLayout = new BoxLayout();
hLayout.setDirection(Direction.LeftToRight);
hLayout.spacing = 8;
hBox.layout = hLayout;
for (const t of ['A', 'B', 'C']) {
const btn = new PushButton(hBox);
btn.text = t;
hLayout.addWidget(btn);
}
mainLayout.addWidget(hBox);

// Section 3: Spacing and margins
const sec3 = new Label(root);
sec3.text = '3. Spacing & Margins';
sec3.fontRole = FontRole.TitleBold;
mainLayout.addWidget(sec3);

const spacedBox = new Widget(root);
spacedBox.setContentsMargins(16, 8, 16, 8);
spacedBox.autoFillBackground = true;
(spacedBox as any).backgroundRole = BackgroundRole.ComponentBackground;
const spacedLayout = new BoxLayout();
spacedLayout.setDirection(Direction.LeftToRight);
spacedLayout.spacing = 16;
spacedBox.layout = spacedLayout;
const spacedLabel = new Label(spacedBox);
spacedLabel.text = 'spacing=16, margins=(16,8)';
spacedLayout.addWidget(spacedLabel);
mainLayout.addWidget(spacedBox);

// Section 4: Nested layouts
const sec4 = new Label(root);
sec4.text = '4. Nested Layouts';
sec4.fontRole = FontRole.TitleBold;
mainLayout.addWidget(sec4);

const nested = new Widget(root);
const outerLayout = new BoxLayout();
outerLayout.setDirection(Direction.LeftToRight);
outerLayout.spacing = 8;
nested.layout = outerLayout;

const leftCol = new BoxLayout();
leftCol.setDirection(Direction.TopToBottom);
const l1 = new Label(nested);
l1.text = 'Left 1';
leftCol.addWidget(l1);
const l2 = new Label(nested);
l2.text = 'Left 2';
leftCol.addWidget(l2);
outerLayout.addLayout(leftCol);

const rightCol = new BoxLayout();
rightCol.setDirection(Direction.TopToBottom);
const r1 = new Label(nested);
r1.text = 'Right 1';
rightCol.addWidget(r1);
const r2 = new Label(nested);
r2.text = 'Right 2';
rightCol.addWidget(r2);
outerLayout.addLayout(rightCol);

mainLayout.addWidget(nested);

Extends

Constructors

Constructor

new BoxLayout(): BoxLayout

Construct a BoxLayout for arranging widgets in a linear direction.

Returns

BoxLayout

Overrides

Layout.constructor

Properties

enabled

enabled: boolean

Whether the layout is active and responsive to user input.

Inherited from

Layout.enabled


isNull

readonly isNull: boolean

Whether this object references a valid layout.

Inherited from

Layout.isNull


spacing

spacing: number

Distance between widgets in the layout.

Inherited from

Layout.spacing

Methods

addLayout()

addLayout(layout): void

Adds a child layout to this BoxLayout. The child layout is appended in the current direction (left-to-right or top-to-bottom).

Parameters

ParameterType
layoutLayout

Returns

void


addStretch()

addStretch(stretch): void

Adds a stretch space (spacer) with the specified stretch factor. Higher stretch values take more available space proportionally. Default factor is 0 (fixed space).

Parameters

ParameterType
stretchnumber

Returns

void


addWidget()

addWidget(widget): void

Add a widget to the layout.

Parameters

ParameterType
widgetWidget

Returns

void

Inherited from

Layout.addWidget


addWidgetWithStretch()

addWidgetWithStretch(widget, stretch, alignment): void

Adds a widget to the layout with an optional stretch factor and alignment. The stretch determines how much space the widget claims; alignment controls its position within its allocated space.

Parameters

ParameterType
widgetWidget
stretchnumber
alignmentAlignment

Returns

void


clear()

clear(behavior): void

Remove all widgets from the layout with specified cleanup behavior.

Parameters

ParameterType
behaviorClearLayoutBehavior

Returns

void

Inherited from

Layout.clear


deleteLater()

deleteLater(): void

Schedule layout for deletion after event processing.

Returns

void

Inherited from

Layout.deleteLater


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

Layout.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Layout.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Layout.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Layout.isSame


setContentsMargins()

setContentsMargins(left, top, right, bottom): void

Set the margins around layout contents.

Parameters

ParameterType
leftnumber
topnumber
rightnumber
bottomnumber

Returns

void

Inherited from

Layout.setContentsMargins


setDirection()

setDirection(direction): void

Sets the layout direction (LeftToRight, RightToLeft, TopToBottom, BottomToTop). Controls whether widgets are arranged horizontally or vertically.

Parameters

ParameterType
directionDirection

Returns

void


setLayoutAlignment()

setLayoutAlignment(layout, alignment): boolean

Set alignment for a nested layout within this layout.

Parameters

ParameterType
layoutLayout
alignmentAlignment

Returns

boolean

Inherited from

Layout.setLayoutAlignment


setWidgetAlignment()

setWidgetAlignment(widget, alignment): boolean

Set alignment for a widget within this layout.

Parameters

ParameterType
widgetWidget
alignmentAlignment

Returns

boolean

Inherited from

Layout.setWidgetAlignment