From fd1a02ff37a664a87b88ee3e40f151bb4963fabe Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 20 Mar 2024 15:27:32 +0000 Subject: [PATCH] feat: have RenderedWorkspaceComment implement IBoundedElement and IRenderedElement (#7919) * feat: implement IBoundedElement * feat: implement IRenderedElement --- core/comments/rendered_workspace_comment.ts | 31 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/core/comments/rendered_workspace_comment.ts b/core/comments/rendered_workspace_comment.ts index 61a1e24d4..87a52f9e7 100644 --- a/core/comments/rendered_workspace_comment.ts +++ b/core/comments/rendered_workspace_comment.ts @@ -7,9 +7,16 @@ import {WorkspaceComment} from './workspace_comment.js'; import {WorkspaceSvg} from '../workspace_svg.js'; import {CommentView} from './comment_view.js'; -import {Coordinate, Size} from '../utils.js'; +import {Coordinate} from '../utils/coordinate.js'; +import {Rect} from '../utils/rect.js'; +import {Size} from '../utils/size.js'; +import {IBoundedElement} from '../interfaces/i_bounded_element.js'; +import {IRenderedElement} from '../interfaces/i_rendered_element.js'; -export class RenderedWorkspaceComment extends WorkspaceComment { +export class RenderedWorkspaceComment + extends WorkspaceComment + implements IBoundedElement, IRenderedElement +{ /** The class encompassing the svg elements making up the workspace comment. */ private view: CommentView; @@ -72,6 +79,26 @@ export class RenderedWorkspaceComment extends WorkspaceComment { this.view.setEditable(this.isEditable()); } + /** Returns the root SVG element of this comment. */ + getSvgRoot(): SVGElement { + return this.view.getSvgRoot(); + } + + /** Returns the bounding rectangle of this comment in workspace coordinates. */ + getBoundingRectangle(): Rect { + const loc = this.getRelativeToSurfaceXY(); + const size = this.getSize(); + return new Rect(loc.y, loc.y + size.height, loc.x, loc.x + size.width); + } + + /** Move the comment by the given amounts in workspace coordinates. */ + moveBy(dx: number, dy: number, _reason?: string[] | undefined): void { + // TODO(#7909): Deal with reason when we add events. + const loc = this.getRelativeToSurfaceXY(); + const newLoc = new Coordinate(loc.x + dx, loc.y + dy); + this.moveTo(newLoc); + } + /** Moves the comment to the given location in workspace coordinates. */ override moveTo(location: Coordinate): void { super.moveTo(location);