Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._toolRelativePosition = RelativePosition.Left;
changed = true;
break;
case 38:
details.briefMessage = "Up pressed";
this._toolRelativePosition = RelativePosition.Top;
changed = true;
break;
case 39:
details.briefMessage = "Right pressed";
this._toolRelativePosition = RelativePosition.Right;
changed = true;
break;
case 40:
details.briefMessage = "Down pressed";
this._toolRelativePosition = RelativePosition.Bottom;
changed = true;
break;
case 27: // Escape
this._handleTool4Dismiss();
break;
}
if (changed) {
IModelApp.notifications.outputMessage(details);
IModelApp.notifications.updatePointerMessage({ x: CursorInformation.cursorX, y: CursorInformation.cursorY }, this._toolRelativePosition);
}
}
iconSpec: "icon-placeholder", labelKey: "SampleApp:buttons.addCursorPopups", execute: async () => {
CursorPopupManager.open("testR1", Hello World!, CursorInformation.cursorPosition, new Point(40, 20), RelativePosition.Right, 10);
CursorPopupManager.open("testBR1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.BottomRight, 10);
CursorPopupManager.open("testB1", Hello World!, CursorInformation.cursorPosition, new Point(20, 85), RelativePosition.Bottom, 10);
CursorPopupManager.open("testBL1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.BottomLeft, 10);
CursorPopupManager.open("testL1", Hello World!, CursorInformation.cursorPosition, new Point(40, 20), RelativePosition.Left, 10);
CursorPopupManager.open("testTL1", Hello World!, CursorInformation.cursorPosition, new Point(20, 20), RelativePosition.TopLeft, 10);
CursorPopupManager.open("testT1", Hello World!, CursorInformation.cursorPosition, new Point(20, 100), RelativePosition.Top, 10);
},
});
public static getRelativePositionFromCursorDirection(cursorDirection: CursorDirection): RelativePosition {
let relativePosition: RelativePosition = RelativePosition.BottomRight;
switch (cursorDirection) {
case CursorDirection.Top:
relativePosition = RelativePosition.Top;
break;
case CursorDirection.Left:
relativePosition = RelativePosition.Left;
break;
case CursorDirection.Right:
relativePosition = RelativePosition.Right;
break;
case CursorDirection.Bottom:
relativePosition = RelativePosition.Bottom;
break;
case CursorDirection.TopLeft:
relativePosition = RelativePosition.TopLeft;
break;
case CursorDirection.TopRight:
relativePosition = RelativePosition.TopRight;
break;
case CursorDirection.BottomLeft:
relativePosition = RelativePosition.BottomLeft;
break;
case CursorDirection.BottomRight:
relativePosition = RelativePosition.BottomRight;
break;
}
return relativePosition;
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
break;
case RelativePosition.Left:
popupRect.right = pt.x - offset.x;
popupRect.top = pt.y - (popupSize.height / 2);
popupRect.left = popupRect.right - popupSize.width;
popupRect.bottom = popupRect.top + popupSize.height;
break;
case RelativePosition.Right:
popupRect.left = pt.x + offset.x;
popupRect.top = pt.y - (popupSize.height / 2);
popupRect.right = popupRect.left + popupSize.width;
popupRect.bottom = popupRect.top + popupSize.height;
break;
case RelativePosition.Bottom:
popupRect.top = pt.y + offset.y;
popupRect.left = pt.x - (popupSize.width / 2);
popupRect.bottom = popupRect.top + popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
break;
case RelativePosition.TopLeft:
popupRect.bottom = pt.y - offset.y;
popupRect.right = pt.x - offset.x;
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.left = popupRect.right - popupSize.width;
break;
case RelativePosition.TopRight:
popupRect.bottom = pt.y - offset.y;
popupRect.left = pt.x + offset.x;
popupRect.top = popupRect.bottom - popupSize.height;
popupRect.right = popupRect.left + popupSize.width;
const adjustmentOffset = 20;
let offset: PointProps | undefined;
switch (this._relativePosition) {
case RelativePosition.Top:
offset = { x: 0, y: -adjustmentOffset };
break;
case RelativePosition.TopRight:
offset = { x: adjustmentOffset, y: -adjustmentOffset };
break;
case RelativePosition.Right:
offset = { x: adjustmentOffset, y: 0 };
break;
case RelativePosition.BottomRight:
offset = { x: adjustmentOffset, y: adjustmentOffset };
break;
case RelativePosition.Bottom:
offset = { x: 0, y: adjustmentOffset };
break;
case RelativePosition.BottomLeft:
offset = { x: -adjustmentOffset, y: adjustmentOffset };
break;
case RelativePosition.Left:
offset = { x: -adjustmentOffset, y: 0 };
break;
case RelativePosition.TopLeft:
offset = { x: -adjustmentOffset, y: -adjustmentOffset };
break;
}
this.setState((prevState) => {
if (!this._viewport)
return null;
case RelativePosition.Right:
case RelativePosition.BottomRight:
outPos = RelativePosition.TopRight;
break;
}
}
if (rect.top < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Left:
case RelativePosition.TopLeft:
outPos = RelativePosition.BottomLeft;
break;
case RelativePosition.Top:
outPos = RelativePosition.Bottom;
break;
case RelativePosition.Right:
case RelativePosition.TopRight:
outPos = RelativePosition.BottomRight;
break;
}
}
return { outPos, flipped };
}
private getDimension(popupSize: Size, relativePosition: RelativePosition): number {
let dimension = 0;
switch (relativePosition) {
case RelativePosition.Top:
case RelativePosition.Bottom:
case RelativePosition.TopLeft:
case RelativePosition.TopRight:
case RelativePosition.BottomLeft:
case RelativePosition.BottomRight:
dimension = popupSize.height;
break;
case RelativePosition.Left:
case RelativePosition.Right:
dimension = popupSize.width;
break;
}
return dimension;
}
private renderRelativePosition(relativePosition: RelativePosition): React.ReactNode {
const filteredInfo = CursorPopupManager.popups.filter((popupInfo: CursorPopupInfo) => popupInfo.renderRelativePosition === relativePosition);
if (filteredInfo.length > 0) {
let totalDimension = 0;
const ascending =
relativePosition === RelativePosition.Right ||
relativePosition === RelativePosition.BottomRight ||
relativePosition === RelativePosition.Bottom ||
relativePosition === RelativePosition.BottomLeft;
const positionPopups = filteredInfo
.sort((a: CursorPopupInfo, b: CursorPopupInfo): number => ascending ? a.priority - b.priority : b.priority - a.priority)
.map((popupInfo: CursorPopupInfo, index: number) => {
const title = (popupInfo.options !== undefined) ? popupInfo.options.title : "";
const shadow = (popupInfo.options !== undefined) ? popupInfo.options.shadow : false;
let offset = popupInfo.offset;
if (index > 0)
offset = this.adjustOffset(offset, popupInfo.renderRelativePosition, totalDimension);
if (popupInfo.popupSize)
totalDimension += this.getDimension(popupInfo.popupSize, relativePosition);
private static autoFlip(inPos: RelativePosition, rect: RectangleProps, windowWidth: number, windowHeight: number): { outPos: RelativePosition, flipped: boolean } {
let flipped = false;
let outPos = inPos;
if (rect.right > windowWidth) {
flipped = true;
switch (inPos) {
case RelativePosition.Top:
case RelativePosition.TopRight:
outPos = RelativePosition.TopLeft;
break;
case RelativePosition.Right:
outPos = RelativePosition.Left;
break;
case RelativePosition.Bottom:
case RelativePosition.BottomRight:
outPos = RelativePosition.BottomLeft;
break;
}
}
if (rect.left < 0) {
flipped = true;
switch (inPos) {
case RelativePosition.Top:
case RelativePosition.TopLeft:
outPos = RelativePosition.TopRight;
break;
case RelativePosition.Left:
outPos = RelativePosition.Right;
break;