aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/AntimodeMenu.tsx
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2020-01-09 13:32:13 -0500
committerFawn <fangrui_tong@brown.edu>2020-01-09 13:32:13 -0500
commit8f030c9a8ca1f61f8430e5ea92c48a7a6b6f079f (patch)
treeaffec456a9fe0e48839e3b5d20d1721b8ce48cea /src/client/views/AntimodeMenu.tsx
parent531147df4186df3d4326748a5d083579cbc9e4c6 (diff)
bounded antimodemenu to the boundaries of the screen and minor styling of richtextmenu
Diffstat (limited to 'src/client/views/AntimodeMenu.tsx')
-rw-r--r--src/client/views/AntimodeMenu.tsx25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/client/views/AntimodeMenu.tsx b/src/client/views/AntimodeMenu.tsx
index 25bd90d87..e358d88cf 100644
--- a/src/client/views/AntimodeMenu.tsx
+++ b/src/client/views/AntimodeMenu.tsx
@@ -22,6 +22,9 @@ export default abstract class AntimodeMenu extends React.Component {
@observable public Pinned: boolean = false;
+ get width() { return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().width : 0; }
+ get height() { return this._mainCont.current ? this._mainCont.current.getBoundingClientRect().height : 0; }
+
@action
/**
* @param x
@@ -44,7 +47,7 @@ export default abstract class AntimodeMenu extends React.Component {
* Called when you want the menu to disappear
*/
public fadeOut = (forceOut: boolean) => {
- if (!this.Pinned && this._canFade) {
+ if (!this.Pinned) {
if (this._opacity === 0.2) {
this._transition = "opacity 0.1s";
this._transitionDelay = "";
@@ -89,8 +92,8 @@ export default abstract class AntimodeMenu extends React.Component {
document.removeEventListener("pointerup", this.dragEnd);
document.addEventListener("pointerup", this.dragEnd);
- this._offsetX = this._mainCont.current!.getBoundingClientRect().width - e.nativeEvent.offsetX;
- this._offsetY = e.nativeEvent.offsetY;
+ this._offsetX = e.pageX - this._mainCont.current!.getBoundingClientRect().left;
+ this._offsetY = e.pageY - this._mainCont.current!.getBoundingClientRect().top;
e.stopPropagation();
e.preventDefault();
@@ -98,14 +101,14 @@ export default abstract class AntimodeMenu extends React.Component {
@action
protected dragging = (e: PointerEvent) => {
- this._left = e.pageX - this._offsetX;
- this._top = e.pageY - this._offsetY;
-
- // assumes dragger is on right
- // let width = this._mainCont.current!.getBoundingClientRect().width;
- // let height = this._mainCont.current!.getBoundingClientRect().width;
- // this._left = Math.max(width, e.pageX - this._offsetX);
- // this._top = Math.min(height, e.pageY - this._offsetY);
+ const width = this._mainCont.current!.getBoundingClientRect().width;
+ const height = this._mainCont.current!.getBoundingClientRect().height;
+
+ const left = e.pageX - this._offsetX;
+ const top = e.pageY - this._offsetY;
+
+ this._left = Math.min(Math.max(left, 0), window.innerWidth - width);
+ this._top = Math.min(Math.max(top, 0), window.innerHeight - height);
e.stopPropagation();
e.preventDefault();