LensStudio:Ui.StackedLayout
ClassLayout manager displaying one widget at a time.
Index
Properties
Methods
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
isNull
readonlyisNull:boolean
Whether this object references a valid layout.
Inherited from
onCurrentChanged
readonlyonCurrentChanged: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
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
| Parameter | Type |
|---|---|
widget | Widget |
Returns
void
Inherited from
addWidgetAt()
addWidgetAt(
widget,index):number
Inserts a widget at the specified index and returns its position in the stack.
Parameters
| Parameter | Type |
|---|---|
widget | Widget |
index | number |
Returns
number
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
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