LensStudio:Ui.BoxLayout
ClassLayout manager arranging widgets in a row or column.
Index
Properties
Methods
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
isNull
readonlyisNull:boolean
Whether this object references a valid layout.
Inherited from
spacing
spacing:
number
Distance between widgets in the layout.
Inherited from
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
| Parameter | Type |
|---|---|
layout | Layout |
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
| Parameter | Type |
|---|---|
stretch | number |
Returns
void
addWidget()
addWidget(
widget):void
Add a widget to the layout.
Parameters
| Parameter | Type |
|---|---|
widget | Widget |
Returns
void
Inherited from
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
Returns
void
clear()
clear(
behavior):void
Remove all widgets from the layout with specified cleanup behavior.
Parameters
| Parameter | Type |
|---|---|
behavior | ClearLayoutBehavior |
Returns
void
Inherited from
deleteLater()
deleteLater():
void
Schedule layout for deletion after event processing.
Returns
void
Inherited from
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
setContentsMargins()
setContentsMargins(
left,top,right,bottom):void
Set the margins around layout contents.
Parameters
| Parameter | Type |
|---|---|
left | number |
top | number |
right | number |
bottom | number |
Returns
void
Inherited from
setDirection()
setDirection(
direction):void
Sets the layout direction (LeftToRight, RightToLeft, TopToBottom, BottomToTop). Controls whether widgets are arranged horizontally or vertically.
Parameters
| Parameter | Type |
|---|---|
direction | Direction |
Returns
void
setLayoutAlignment()
setLayoutAlignment(
layout,alignment):boolean
Set alignment for a nested layout within this layout.
Parameters
Returns
boolean
Inherited from
setWidgetAlignment()
setWidgetAlignment(
widget,alignment):boolean
Set alignment for a widget within this layout.
Parameters
Returns
boolean