mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
feat: have RenderedWorkspaceComment implement IBoundedElement and IRenderedElement (#7919)
* feat: implement IBoundedElement * feat: implement IRenderedElement
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user