@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
465 lines • 15.4 kB
JavaScript
import { __extends } from "tslib";
import { DButtonColor, DDialogLayered, DInputIntegerAndLabel, DInputLabel, DInputTextAndLabel, DInputTextArea, DLayoutHorizontal, DLayoutSpace, DMenu, DSelect, isNumber } from "@wcardinal/wcardinal-ui";
var EDialogCanvas = /** @class */ (function (_super) {
__extends(EDialogCanvas, _super);
function EDialogCanvas(options) {
var _this = _super.call(this, options) || this;
var canvas = options.canvas;
_this._canvas = options.canvas;
_this.onDefaultChange(canvas);
return _this;
}
EDialogCanvas.prototype.onDefaultChange = function (def) {
var category = def.category;
var categoryDefault = category.default;
var categoryItems = category.items;
var layout = this.layoutCategory;
if (categoryDefault != null && 0 < categoryItems.length) {
var items = [];
for (var i = 0, imax = categoryItems.length; i < imax; ++i) {
var categoryItem = categoryItems[i];
items.push({
value: categoryItem.id,
text: {
value: categoryItem.label
}
});
}
var selectCategory = this.selectCategory;
selectCategory.menu = new DMenu({
fit: true,
items: items
});
selectCategory.value = category.default;
layout.state.isEnabled = category.writable;
layout.show();
}
else {
layout.hide();
}
};
EDialogCanvas.prototype.newContentChildren = function (theme, options) {
var result = _super.prototype.newContentChildren.call(this, theme, options);
result.push(this.layoutName, this.layoutLabel, this.layoutWidth, this.layoutHeight, this.layoutCategory, this.layoutSummary, this.layoutDescription, this.layoutBackground);
return result;
};
Object.defineProperty(EDialogCanvas.prototype, "layoutName", {
get: function () {
var result = this._layoutName;
if (result == null) {
result = this.newLayoutName();
this._layoutName = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutName = function () {
var _this = this;
return new DInputTextAndLabel({
width: "padding",
label: {
text: {
value: this.theme.getInputNameLabel()
}
},
input: {
weight: 1,
on: {
enter: function () {
_this.ok();
}
}
},
space: {
width: 60
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutLabel", {
get: function () {
var result = this._layoutLabel;
if (result == null) {
result = this.newLayoutLabel();
this._layoutLabel = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutLabel = function () {
var _this = this;
return new DInputTextAndLabel({
width: "padding",
label: {
text: {
value: this.theme.getInputLabelLabel()
}
},
input: {
weight: 1,
on: {
enter: function () {
_this.ok();
}
}
},
space: {
width: 60
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutWidth", {
get: function () {
var result = this._layoutWidth;
if (result == null) {
result = this.newLayoutWidth();
this._layoutWidth = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutWidth = function () {
var _this = this;
return new DInputIntegerAndLabel({
width: "padding",
label: {
text: {
value: this.theme.getInputWidthLabel()
}
},
input: {
weight: 1,
min: 1,
on: {
enter: function () {
_this.ok();
}
}
},
space: {
width: 60
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutHeight", {
get: function () {
var result = this._layoutHeight;
if (result == null) {
result = this.newLayoutHeight();
this._layoutHeight = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutHeight = function () {
var _this = this;
return new DInputIntegerAndLabel({
width: "padding",
label: {
text: {
value: this.theme.getInputHeightLabel()
}
},
input: {
weight: 1,
min: 1,
on: {
enter: function () {
_this.ok();
}
}
},
space: {
width: 60
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutCategory", {
get: function () {
var result = this._layoutCategory;
if (result == null) {
result = this.newLayoutCategory();
this._layoutCategory = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutCategory = function () {
return new DLayoutHorizontal({
width: "padding",
visible: false,
children: [
new DInputLabel({
text: {
value: this.theme.getSelectCategoryLabel()
}
}),
this.selectCategory,
new DLayoutSpace({
width: 60
})
]
});
};
Object.defineProperty(EDialogCanvas.prototype, "selectCategory", {
get: function () {
var result = this._selectCategory;
if (result == null) {
result = this.newSelectCategory();
this._selectCategory = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newSelectCategory = function () {
return new DSelect({
weight: 1
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutSummary", {
get: function () {
var result = this._layoutSummary;
if (result == null) {
result = this.newLayoutSummary();
this._layoutSummary = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutSummary = function () {
return new DLayoutHorizontal({
width: "padding",
height: "auto",
children: [
this.newLabelSummary(),
this.inputSummary,
new DLayoutSpace({
width: 60
})
]
});
};
EDialogCanvas.prototype.newLabelSummary = function () {
return new DInputLabel({
width: 60,
text: {
value: this.theme.getInputSummaryLabel()
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "inputSummary", {
get: function () {
var result = this._inputSummary;
if (result == null) {
result = this.newInputSummary();
this._inputSummary = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newInputSummary = function () {
return new DInputTextArea({
weight: 1,
height: 60
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutDescription", {
get: function () {
var result = this._layoutDescription;
if (result == null) {
result = this.newLayoutDescription();
this._layoutDescription = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutDescription = function () {
return new DLayoutHorizontal({
width: "padding",
height: "auto",
children: [
this.newLabelDescription(),
this.inputDescription,
new DLayoutSpace({
width: 60
})
]
});
};
EDialogCanvas.prototype.newLabelDescription = function () {
return new DInputLabel({
width: 60,
text: {
value: this.theme.getInputDescriptionLabel()
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "inputDescription", {
get: function () {
var result = this._inputDescription;
if (result == null) {
result = this.newInputDescription();
this._inputDescription = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newInputDescription = function () {
return new DInputTextArea({
weight: 1,
height: 100
});
};
Object.defineProperty(EDialogCanvas.prototype, "layoutBackground", {
get: function () {
var result = this._layoutBackground;
if (result == null) {
result = this.newLayoutBackground();
this._layoutBackground = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newLayoutBackground = function () {
return new DLayoutHorizontal({
width: "padding",
height: "auto",
children: [
this.newLabelBackground(),
this.inputBackground,
new DLayoutSpace({
width: 60
})
]
});
};
EDialogCanvas.prototype.newLabelBackground = function () {
return new DInputLabel({
width: 60,
text: {
value: this.theme.getInputBackgroundLabel()
}
});
};
Object.defineProperty(EDialogCanvas.prototype, "inputBackground", {
get: function () {
var result = this._inputBackground;
if (result == null) {
result = this.newInputBackground();
this._inputBackground = result;
}
return result;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.newInputBackground = function () {
var result = new DButtonColor({
weight: 1
});
result.dialog.on("open", function () {
var dialog = result.dialog;
var dialogNew = dialog.new;
var dialogCurrent = dialog.current;
dialogNew.color = dialogCurrent.color;
dialogNew.alpha = dialogCurrent.alpha;
});
return result;
};
EDialogCanvas.prototype.reset = function (diagram) {
var diagramCanvas = diagram === null || diagram === void 0 ? void 0 : diagram.canvas;
if (diagramCanvas != null) {
var background = diagramCanvas.background;
var backgroundColor = background.color;
var backgroundAlpha = background.alpha;
this.value = {
name: diagramCanvas.name,
label: diagramCanvas.label,
width: diagramCanvas.width,
height: diagramCanvas.height,
category: diagramCanvas.category,
summary: diagramCanvas.summary,
description: diagramCanvas.description,
background: {
color: isNumber(backgroundColor) ? backgroundColor : 0xffffff,
alpha: isNumber(backgroundAlpha) ? backgroundAlpha : 1
}
};
}
else {
var canvas = this._canvas;
this.value = {
name: canvas.name,
label: canvas.label,
width: canvas.width,
height: canvas.height,
category: canvas.category.default,
summary: canvas.summary,
description: canvas.description,
background: {
color: canvas.background.color,
alpha: canvas.background.alpha
}
};
}
return this;
};
Object.defineProperty(EDialogCanvas.prototype, "value", {
get: function () {
return {
name: this.layoutName.input.value,
label: this.layoutLabel.input.value,
width: this.layoutWidth.input.value,
height: this.layoutHeight.input.value,
category: this.selectCategory.value,
summary: this.inputSummary.value,
description: this.inputDescription.value,
background: this.inputBackground.value
};
},
set: function (value) {
var _a, _b;
this.layoutName.input.value = value.name;
this.layoutLabel.input.value = value.label;
this.layoutWidth.input.value = value.width;
this.layoutHeight.input.value = value.height;
this.selectCategory.value = (_b = (_a = value.category) !== null && _a !== void 0 ? _a : this._canvas.category.default) !== null && _b !== void 0 ? _b : null;
this.inputSummary.value = value.summary;
this.inputDescription.value = value.description;
this.inputBackground.value.color = value.background.color;
this.inputBackground.value.alpha = value.background.alpha;
},
enumerable: false,
configurable: true
});
EDialogCanvas.prototype.getResolvedValue = function () {
return this.value;
};
EDialogCanvas.prototype.getType = function () {
return "EDialogCanvas";
};
return EDialogCanvas;
}(DDialogLayered));
export { EDialogCanvas };
//# sourceMappingURL=e-dialog-canvas.js.map