LensStudio:Ui.Layout
ClassBase class for layout managers.
Index
Properties
Methods
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
readonlyisNull: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
| Parameter | Type |
|---|---|
widget | Widget |
Returns
void
clear()
clear(
behavior):void
Remove all widgets from the layout with specified cleanup behavior.
Parameters
| Parameter | Type |
|---|---|
behavior | ClearLayoutBehavior |
Returns
void
deleteLater()
deleteLater():
void
Schedule layout for deletion after event processing.
Returns
void
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
setLayoutAlignment()
setLayoutAlignment(
layout,alignment):boolean
Set alignment for a nested layout within this layout.
Parameters
| Parameter | Type |
|---|---|
layout | Layout |
alignment | Alignment |
Returns
boolean
setWidgetAlignment()
setWidgetAlignment(
widget,alignment):boolean
Set alignment for a widget within this layout.
Parameters
Returns
boolean