aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/RadialMenu.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/RadialMenu.tsx')
-rw-r--r--src/client/views/nodes/RadialMenu.tsx140
1 files changed, 41 insertions, 99 deletions
diff --git a/src/client/views/nodes/RadialMenu.tsx b/src/client/views/nodes/RadialMenu.tsx
index 16450c359..48da4937a 100644
--- a/src/client/views/nodes/RadialMenu.tsx
+++ b/src/client/views/nodes/RadialMenu.tsx
@@ -6,22 +6,57 @@ import { RadialMenuItem, RadialMenuProps } from './RadialMenuItem';
@observer
export class RadialMenu extends React.Component {
+ // eslint-disable-next-line no-use-before-define
static Instance: RadialMenu;
static readonly buffer = 20;
+ @observable private _mouseX: number = -1;
+ @observable private _mouseY: number = -1;
+ @observable private _shouldDisplay: boolean = false;
+ @observable private _mouseDown: boolean = false;
+ @observable private _closest: number = -1;
+ @observable private _pageX: number = 0;
+ @observable private _pageY: number = 0;
+ @observable _display: boolean = false;
+ @observable private _yRelativeToTop: boolean = true;
+ @observable private _items: Array<RadialMenuProps> = [];
+ private _reactionDisposer?: IReactionDisposer;
+
constructor(props: any) {
super(props);
makeObservable(this);
RadialMenu.Instance = this;
}
- @observable private _mouseX: number = -1;
- @observable private _mouseY: number = -1;
- @observable private _shouldDisplay: boolean = false;
- @observable private _mouseDown: boolean = false;
- private _reactionDisposer?: IReactionDisposer;
+ componentDidMount() {
+ document.addEventListener('pointerdown', this.onPointerDown);
+ document.addEventListener('pointerup', this.onPointerUp);
+ this.previewcircle();
+ this._reactionDisposer = reaction(
+ () => this._shouldDisplay,
+ () =>
+ this._shouldDisplay &&
+ !this._mouseDown &&
+ runInAction(() => {
+ this._display = true;
+ })
+ );
+ }
- public used: boolean = false;
+ componentDidUpdate() {
+ this.previewcircle();
+ }
+ componentWillUnmount() {
+ document.removeEventListener('pointerdown', this.onPointerDown);
+
+ document.removeEventListener('pointerup', this.onPointerUp);
+ this._reactionDisposer && this._reactionDisposer();
+ }
+
+ @computed get menuItems() {
+ // eslint-disable-next-line react/jsx-props-no-spreading
+ return this._items.map((item, index) => <RadialMenuItem {...item} key={item.description} closeMenu={this.closeMenu} max={this._items.length} min={index} selected={this._closest} />);
+ }
catchTouch = (te: React.TouchEvent) => {
te.stopPropagation();
@@ -33,13 +68,9 @@ export class RadialMenu extends React.Component {
this._mouseDown = true;
this._mouseX = e.clientX;
this._mouseY = e.clientY;
- this.used = false;
document.addEventListener('pointermove', this.onPointerMove);
};
- @observable
- private _closest: number = -1;
-
@action
onPointerMove = (e: PointerEvent) => {
const curX = e.clientX;
@@ -65,7 +96,6 @@ export class RadialMenu extends React.Component {
};
@action
onPointerUp = (e: PointerEvent) => {
- this.used = true;
this._mouseDown = false;
const curX = e.clientX;
const curY = e.clientY;
@@ -78,86 +108,6 @@ export class RadialMenu extends React.Component {
this._items[this._closest].event();
}
};
- componentWillUnmount() {
- document.removeEventListener('pointerdown', this.onPointerDown);
-
- document.removeEventListener('pointerup', this.onPointerUp);
- this._reactionDisposer && this._reactionDisposer();
- }
-
- @action
- componentDidMount() {
- document.addEventListener('pointerdown', this.onPointerDown);
- document.addEventListener('pointerup', this.onPointerUp);
- this.previewcircle();
- this._reactionDisposer = reaction(
- () => this._shouldDisplay,
- () => this._shouldDisplay && !this._mouseDown && runInAction(() => (this._display = true))
- );
- }
-
- componentDidUpdate = () => {
- this.previewcircle();
- };
-
- @observable private _pageX: number = 0;
- @observable private _pageY: number = 0;
- @observable _display: boolean = false;
- @observable private _yRelativeToTop: boolean = true;
-
- @observable private _width: number = 0;
- @observable private _height: number = 0;
-
- getItems() {
- return this._items;
- }
-
- @action
- addItem(item: RadialMenuProps) {
- if (this._items.indexOf(item) === -1) {
- this._items.push(item);
- }
- }
-
- @observable
- private _items: Array<RadialMenuProps> = [];
-
- @action
- displayMenu = (x: number, y: number) => {
- //maxX and maxY will change if the UI/font size changes, but will work for any amount
- //of items added to the menu
- this._mouseX = x;
- this._mouseY = y;
- this._shouldDisplay = true;
- };
- // @computed
- // get pageX() {
- // const x = this._pageX;
- // if (x < 0) {
- // return 0;
- // }
- // const width = this._width;
- // if (x + width > window.innerWidth - RadialMenu.buffer) {
- // return window.innerWidth - RadialMenu.buffer - width;
- // }
- // return x;
- // }
- // @computed
- // get pageY() {
- // const y = this._pageY;
- // if (y < 0) {
- // return 0;
- // }
- // const height = this._height;
- // if (y + height > window.innerHeight - RadialMenu.buffer) {
- // return window.innerHeight - RadialMenu.buffer - height;
- // }
- // return y;
- // }
-
- @computed get menuItems() {
- return this._items.map((item, index) => <RadialMenuItem {...item} key={item.description} closeMenu={this.closeMenu} max={this._items.length} min={index} selected={this._closest} />);
- }
@action
closeMenu = () => {
@@ -167,14 +117,6 @@ export class RadialMenu extends React.Component {
};
@action
- openMenu = (x: number, y: number) => {
- this._pageX = x;
- this._pageY = y;
- this._shouldDisplay;
- this._display = true;
- };
-
- @action
clearItems() {
this._items = [];
}