UNPKG

@wcardinal/wcardinal-geditor

Version:

WebGL-based graphic editor, tester and viewer for supervisory systems

195 lines 7.3 kB
import { __extends } from "tslib"; import { DButtonCheckRight, DControllers, DLayoutVertical, DPane, DText, DThemes, EShapeButton } from "@wcardinal/wcardinal-ui"; import { ECommandShapeButtonPropertyIsActive } from "./e-command-shape-button-property-is-active"; import { ECommandShapeButtonPropertyIsGrouped } from "./e-command-shape-button-property-is-grouped"; import { ECommandShapeButtonPropertyIsToggle } from "./e-command-shape-button-property-is-toggle"; var EEditorShapeButton = /** @class */ (function (_super) { __extends(EEditorShapeButton, _super); function EEditorShapeButton(options) { var _this = _super.call(this, options) || this; _this._icons = options.icons; var selection = options.selection; _this._selection = selection; _this._diagram = options.diagram; // Layout _this.initLayout(); return _this; } EEditorShapeButton.prototype.initLayout = function () { var _this = this; // Content height this.content.setHeight("padding"); // Layout new DLayoutVertical({ parent: this.content, x: "padding", y: "padding", width: "padding", height: "padding", children: [ this.newTextLabel(), this.checkIsToggle, this.checkIsGrouped, this.checkIsActive ] }); // Selection var selection = this._selection; this.state.isDisabled = selection.isEmpty(); selection.on("change", function () { _this.state.isDisabled = selection.isEmpty(); _this.onSelectionChange(selection); }); this.onSelectionChange(selection); }; EEditorShapeButton.prototype.newTextLabel = function () { return new DText({ width: "100%", text: { value: this.subtheme.getLabel() } }); }; Object.defineProperty(EEditorShapeButton.prototype, "checkIsToggle", { get: function () { var _a; return ((_a = this._checkIsToggle) !== null && _a !== void 0 ? _a : (this._checkIsToggle = this.newCheckIsToggle())); }, enumerable: false, configurable: true }); EEditorShapeButton.prototype.newCheckIsToggle = function () { var _this = this; return new DButtonCheckRight({ width: "padding", text: { value: this.subtheme.getCheckIsToggleLabel() }, on: { active: function () { _this.onCheckIsToggleChanged(true); }, inactive: function () { _this.onCheckIsToggleChanged(false); } } }); }; EEditorShapeButton.prototype.onCheckIsToggleChanged = function (isActive) { DControllers.getCommandController().push(new ECommandShapeButtonPropertyIsToggle(this._selection, isActive)); }; EEditorShapeButton.prototype.onSelectionChangeCheckIsToggle = function (selection) { var state = this.checkIsToggle.state; var last = selection.last(); if (last instanceof EShapeButton) { state.lock(); state.isActive = last.isToggle; state.isDisabled = false; state.unlock(); } else { state.isDisabled = true; } }; Object.defineProperty(EEditorShapeButton.prototype, "checkIsGrouped", { get: function () { var _a; return ((_a = this._checkIsGrouped) !== null && _a !== void 0 ? _a : (this._checkIsGrouped = this.newCheckIsGrouped())); }, enumerable: false, configurable: true }); EEditorShapeButton.prototype.newCheckIsGrouped = function () { var _this = this; return new DButtonCheckRight({ width: "padding", text: { value: this.subtheme.getCheckIsGroupedLabel() }, on: { active: function () { _this.onCheckIsGroupedChanged(true); }, inactive: function () { _this.onCheckIsGroupedChanged(false); } } }); }; EEditorShapeButton.prototype.onCheckIsGroupedChanged = function (isActive) { DControllers.getCommandController().push(new ECommandShapeButtonPropertyIsGrouped(this._selection, isActive)); }; EEditorShapeButton.prototype.onSelectionChangeCheckIsGrouped = function (selection) { var state = this.checkIsGrouped.state; var last = selection.last(); if (last instanceof EShapeButton) { state.lock(); state.isActive = last.isGrouped; state.isDisabled = false; state.unlock(); } else { state.isDisabled = true; } }; Object.defineProperty(EEditorShapeButton.prototype, "checkIsActive", { get: function () { var _a; return ((_a = this._checkIsActive) !== null && _a !== void 0 ? _a : (this._checkIsActive = this.newCheckIsActive())); }, enumerable: false, configurable: true }); EEditorShapeButton.prototype.newCheckIsActive = function () { var _this = this; return new DButtonCheckRight({ width: "padding", text: { value: this.subtheme.getCheckIsActiveLabel() }, on: { active: function () { _this.onCheckIsActiveChanged(true); }, inactive: function () { _this.onCheckIsActiveChanged(false); } } }); }; EEditorShapeButton.prototype.onCheckIsActiveChanged = function (isActive) { DControllers.getCommandController().push(new ECommandShapeButtonPropertyIsActive(this._selection, isActive)); }; EEditorShapeButton.prototype.onSelectionChangeCheckIsActive = function (selection) { var state = this.checkIsActive.state; var last = selection.last(); if (last instanceof EShapeButton) { state.lock(); state.isActive = last.state.isActive; state.isDisabled = false; state.unlock(); } else { state.isDisabled = true; } }; EEditorShapeButton.prototype.onSelectionChange = function (selection) { this.onSelectionChangeCheckIsToggle(selection); this.onSelectionChangeCheckIsGrouped(selection); this.onSelectionChangeCheckIsActive(selection); }; Object.defineProperty(EEditorShapeButton.prototype, "subtheme", { get: function () { var _a; return ((_a = this._subtheme) !== null && _a !== void 0 ? _a : (this._subtheme = this.newSubtheme())); }, enumerable: false, configurable: true }); EEditorShapeButton.prototype.newSubtheme = function () { return DThemes.get("EEditorShapeButton"); }; return EEditorShapeButton; }(DPane)); export { EEditorShapeButton }; //# sourceMappingURL=e-editor-shape-button.js.map