LensStudio:Ui.AspectRatioMode
EnumEnum controlling aspect ratio scaling behavior.
Index
Enumeration Members
Example
export class AspectRatioModeExamplePanel extends PanelPlugin {
connections: any[];
static descriptor() {
const d = new Descriptor();
d.id = 'com.docs.AspectRatioModeExample';
d.name = 'AspectRatioMode Example';
d.defaultDockState = DockState.Detached;
d.defaultSize = new Size(400, 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 = 8;
root.layout = layout;
const title = new Label(root);
title.text = 'AspectRatioMode Demo';
layout.addWidget(title);
// Create an ImageView to display an image
const imageView = new ImageView(root);
imageView.scaledContents = true;
layout.addWidget(imageView);
// AspectRatioMode is set on Pixmap to control resize behavior
const pixmap = imageView.pixmap;
if (!Editor.isNull(pixmap)) {
pixmap.aspectRatioMode = AspectRatioMode.KeepAspectRatio;
}
const statusLabel = new Label(root);
statusLabel.text = 'Current: KeepAspectRatio';
layout.addWidget(statusLabel);
// Cycle through modes on button click
const btn = new PushButton(root);
btn.text = 'Cycle AspectRatioMode';
layout.addWidget(btn);
const modes = [
{ mode: AspectRatioMode.IgnoreAspectRatio, name: 'IgnoreAspectRatio' },
{ mode: AspectRatioMode.KeepAspectRatio, name: 'KeepAspectRatio' },
{ mode: AspectRatioMode.KeepAspectRatioByExpanding, name: 'KeepAspectRatioByExpanding' },
];
let idx = 1;
this.connections.push(
btn.onClick.connect(() => {
idx = (idx + 1) % modes.length;
const pm = imageView.pixmap;
if (!Editor.isNull(pm)) {
pm.aspectRatioMode = modes[idx].mode;
}
statusLabel.text = 'Current: ' + modes[idx].name;
})
);
return root;
}
deinit(): void {
this.connections.forEach((c: any) => c?.disconnect());
this.connections = [];
}
}
Enumeration Members
IgnoreAspectRatio
IgnoreAspectRatio:
number
Ignore aspect ratio constraints.
KeepAspectRatio
KeepAspectRatio:
number
Maintain the aspect ratio.
KeepAspectRatioByExpanding
KeepAspectRatioByExpanding:
number
Maintain the aspect ratio by expanding as needed.