@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
83 lines (82 loc) • 1.96 kB
JavaScript
"use strict";
import { Vector2 } from "three";
import { Color } from "three";
import { NodeEvent } from "../../poly/NodeEvent";
import { isNumber } from "../../../core/Type";
export class UIData {
constructor(node, x = 0, y = 0) {
this.node = node;
this._position = new Vector2();
this._width = 50;
// private _border_radius: number = 3;
this._color = new Color(0.75, 0.75, 0.75);
// private _icon: string | null = null;
this._layoutVertical = true;
this._json = {
x: 0,
y: 0
};
this._position.x = x;
this._position.y = y;
}
dispose() {
this._comment = void 0;
}
setComment(comment) {
this._comment = comment;
this.node.emit(NodeEvent.UI_DATA_COMMENT_UPDATED);
}
comment() {
return this._comment;
}
setColor(color) {
this._color = color;
}
color() {
return this._color;
}
// setIcon(icon: string) {
// this._icon = icon;
// }
// icon() {
// return this._icon;
// }
setLayoutHorizontal() {
this._layoutVertical = false;
}
isLayoutVertical() {
return this._layoutVertical;
}
copy(ui_data) {
this._position.copy(ui_data.position());
this._color.copy(ui_data.color());
}
position() {
return this._position;
}
setPosition(newPosition, y = 0) {
if (isNumber(newPosition)) {
const x = newPosition;
this._position.set(x, y);
} else {
this._position.copy(newPosition);
}
this.node.emit(NodeEvent.UI_DATA_POSITION_UPDATED);
return this;
}
translate(offset, snap = false) {
this._position.add(offset);
if (snap) {
this._position.x = Math.round(this._position.x);
this._position.y = Math.round(this._position.y);
}
this.node.emit(NodeEvent.UI_DATA_POSITION_UPDATED);
return this;
}
toJSON() {
this._json.x = this._position.x;
this._json.y = this._position.y;
this._json.comment = this._comment;
return this._json;
}
}