dazscript-framework
Version:
The **DazScript Framework** is a TypeScript-based framework for writing Daz Studio scripts. It provides all the advantages of a typed language such as autocompletion, error checking, and method parameter documentation and hinting. The framework also inclu
50 lines (40 loc) • 1.64 kB
text/typescript
import { DialogProperties } from '../shared';
import { WidgetBuilderContext, WidgetsBuilder } from './widgets-builder';
export class DialogBuilder extends WidgetsBuilder {
public properties: DialogProperties
constructor(private title: string, private id?: string) {
super(new WidgetBuilderContext(new DzBasicDialog()))
this.properties = new DialogProperties()
}
options(properties: DialogProperties) {
this.properties = properties
}
build(setup: () => void): DzBasicDialog {
this.init()
setup()
this.resize()
return this.context.dialog
}
private init() {
this.context.dialog.caption = this.title
let dialogWidget = this.context.dialog.getWidget()
var key = (this.id ?? this.context.dialog.caption).replace(/ /g, "") + "Dlg"
dialogWidget.objectName = key
}
private resize() {
let dialogWidget = this.context.dialog.getWidget();
let sizeHint = dialogWidget.minimumSizeHint;
let height = this.properties.height ?? sizeHint.height;
this.context.dialog.minHeight = sizeHint.height;
this.context.dialog.height = height;
if (this.properties.width) this.context.dialog.width = this.properties.width;
if (this.properties.resizable === true) {
this.context.dialog.sizeGripEnabled = true;
}
else {
if (this.properties.width)
this.context.dialog.setFixedWidth(this.properties.width);
this.context.dialog.setFixedHeight(height);
}
}
}