Skip to main content

LensStudio:Ui.Layout

Class

Base class for layout managers.

Index

Example

export class LayoutPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiLayoutExample';
d.name = 'Layout Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(350, 300);
return d;
}
constructor(pluginSystem: Editor.PluginSystem, descriptor?: Descriptor) {
super(pluginSystem, descriptor);
this.connections = [];
}
createWidget(parent: Widget): Widget {
const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 6;
layout.setContentsMargins(8, 8, 8, 8);
root.layout = layout;

const title = new Label(root);
title.text = 'Layout Properties';
title.fontRole = FontRole.TitleBold;
layout.addWidget(title);

// Layout.spacing controls distance between widgets
const spacingLabel = new Label(root);
spacingLabel.text = 'spacing = ' + layout.spacing;
layout.addWidget(spacingLabel);

// Layout.enabled controls whether the layout is active
const enabledLabel = new Label(root);
enabledLabel.text = 'enabled = ' + layout.enabled;
layout.addWidget(enabledLabel);

// Layout.addWidget adds widgets to the layout
const btn = new PushButton(root);
btn.text = 'Widget added via layout.addWidget()';
layout.addWidget(btn);

// BoxLayout.addWidgetWithStretch for stretch + alignment
const stretched = new Label(root);
stretched.text = 'Stretched label (stretch=1, AlignCenter)';
layout.addWidgetWithStretch(stretched, 1, Alignment.AlignCenter);

// BoxLayout.addStretch adds spacer
layout.addStretch(1);

const bottom = new Label(root);
bottom.text = 'Pushed to bottom by addStretch(1)';
layout.addWidget(bottom);

return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}

Extends

Extended by

Properties

enabled

enabled: boolean

Whether the layout is active and responsive to user input.


isNull

readonly isNull: boolean

Whether this object references a valid layout.


spacing

spacing: number

Distance between widgets in the layout.

Methods

addWidget()

addWidget(widget): void

Add a widget to the layout.

Parameters

ParameterType
widgetWidget

Returns

void


clear()

clear(behavior): void

Remove all widgets from the layout with specified cleanup behavior.

Parameters

ParameterType
behaviorClearLayoutBehavior

Returns

void


deleteLater()

deleteLater(): void

Schedule layout for deletion after event processing.

Returns

void


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

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

ScriptObject.isSame


setContentsMargins()

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

Set the margins around layout contents.

Parameters

ParameterType
leftnumber
topnumber
rightnumber
bottomnumber

Returns

void


setLayoutAlignment()

setLayoutAlignment(layout, alignment): boolean

Set alignment for a nested layout within this layout.

Parameters

ParameterType
layoutLayout
alignmentAlignment

Returns

boolean


setWidgetAlignment()

setWidgetAlignment(widget, alignment): boolean

Set alignment for a widget within this layout.

Parameters

ParameterType
widgetWidget
alignmentAlignment

Returns

boolean