Skip to main content

LensStudio:Ui.StackedLayout

Class

Layout manager displaying one widget at a time.

Index

Example

export class StackedLayoutPanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.UiStackedLayoutExample';
d.name = 'StackedLayout 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 outerLayout = new BoxLayout();
outerLayout.setDirection(Direction.TopToBottom);
outerLayout.spacing = 8;
root.layout = outerLayout;

const title = new Label(root);
title.text = 'StackedLayout Demo';
title.fontRole = FontRole.TitleBold;
outerLayout.addWidget(title);

// StackedLayout shows one widget at a time
const container = new Widget(root);
const stacked = new StackedLayout();
stacked.stackingMode = StackingMode.StackOne;
container.layout = stacked;
outerLayout.addWidget(container);

// Create pages
const pageA = new Label(container);
pageA.text = 'Page A content';
stacked.addWidget(pageA);

const pageB = new Label(container);
pageB.text = 'Page B content';
stacked.addWidget(pageB);

stacked.currentIndex = 0;

const switchBtn = new PushButton(root);
switchBtn.text = 'Switch Page';
outerLayout.addWidget(switchBtn);

const status = new Label(root);
status.text = 'Current page: 0';
outerLayout.addWidget(status);

this.connections.push(
switchBtn.onClick.connect(() => {
stacked.currentIndex = stacked.currentIndex === 0 ? 1 : 0;
status.text = 'Current page: ' + stacked.currentIndex;
})
);

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

Extends

Constructors

Constructor

new StackedLayout(): StackedLayout

Constructs a new StackedLayout instance for stacking widgets on top of each other.

Returns

StackedLayout

Overrides

Layout.constructor

Properties

currentIndex

currentIndex: number

Index of the currently visible widget in the stack.


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


onCurrentChanged

readonly onCurrentChanged: signal1<number, void>

Signal fired when the visible widget index changes, passing the new index.


spacing

spacing: number

Distance between widgets in the layout.

Inherited from

Layout.spacing


stackingMode

stackingMode: StackingMode

Controls how widgets are stacked and which one is visible.

Methods

addWidget()

addWidget(widget): void

Add a widget to the layout.

Parameters

ParameterType
widgetWidget

Returns

void

Inherited from

Layout.addWidget


addWidgetAt()

addWidgetAt(widget, index): number

Inserts a widget at the specified index and returns its position in the stack.

Parameters

ParameterType
widgetWidget
indexnumber

Returns

number


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


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