feat: have RenderedWorkspaceComment implement IBoundedElement and IRenderedElement (#7919)

* feat: implement IBoundedElement

* feat: implement IRenderedElement
This commit is contained in:
Beka Westberg
2024-03-20 15:27:32 +00:00
committed by GitHub
parent 93acb62456
commit fd1a02ff37

View File

@@ -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);