molstar
Version:
A comprehensive macromolecular library.
55 lines • 3.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimationControls = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
/**
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
var base_1 = require("../base");
var parameters_1 = require("../controls/parameters");
var common_1 = require("../controls/common");
var icons_1 = require("../controls/icons");
var AnimationControls = /** @class */ (function (_super) {
(0, tslib_1.__extends)(AnimationControls, _super);
function AnimationControls() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.updateParams = function (p) {
var _a;
_this.plugin.managers.animation.updateParams((_a = {}, _a[p.name] = p.value, _a));
};
_this.updateCurrentParams = function (p) {
var _a;
_this.plugin.managers.animation.updateCurrentParams((_a = {}, _a[p.name] = p.value, _a));
};
_this.startOrStop = function () {
var anim = _this.plugin.managers.animation;
if (anim.state.animationState === 'playing')
anim.stop();
else {
if (_this.props.onStart)
_this.props.onStart();
anim.start();
}
};
return _this;
}
AnimationControls.prototype.componentDidMount = function () {
var _this = this;
this.subscribe(this.plugin.managers.animation.events.updated, function () { return _this.forceUpdate(); });
};
AnimationControls.prototype.render = function () {
var _a, _b;
var anim = this.plugin.managers.animation;
if (anim.isEmpty)
return null;
var isDisabled = anim.state.animationState === 'playing';
var canApply = (_b = (_a = anim.current.anim).canApply) === null || _b === void 0 ? void 0 : _b.call(_a, this.plugin);
return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: anim.getParams(), values: anim.state.params, onChange: this.updateParams, isDisabled: isDisabled }, void 0), (0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: anim.current.params, values: anim.current.paramValues, onChange: this.updateCurrentParams, isDisabled: isDisabled }, void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-flex-row' }, { children: (0, jsx_runtime_1.jsx)(common_1.Button, (0, tslib_1.__assign)({ icon: anim.state.animationState !== 'playing' ? void 0 : icons_1.PlayArrowSvg, onClick: this.startOrStop, disabled: canApply !== void 0 && canApply.canApply === false }, { children: anim.state.animationState === 'playing' ? 'Stop' : canApply === void 0 || canApply.canApply ? 'Start' : canApply.reason || 'Start' }), void 0) }), void 0)] }, void 0);
};
return AnimationControls;
}(base_1.PluginUIComponent));
exports.AnimationControls = AnimationControls;
//# sourceMappingURL=animation.js.map
;