Selection UI example (plus fixes to pageToScreen) (#3015)
This PR adds a custom selection UI example.  It also fixes a bug with pageToScreen and adds a `getSelectionRotatedScreenBounds` method. ### Change Type - [ ] `patch` — Bug fix - [x] `minor` — New feature - [ ] `major` — Breaking change - [ ] `dependencies` — Changes to package dependencies[^1] - [ ] `documentation` — Changes to the documentation only[^2] - [ ] `tests` — Changes to any test code only[^2] - [ ] `internal` — Any other changes that don't affect the published package[^2] - [ ] I don't know [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version ### Release Notes - Adds selection UI example. - Adds `Editor.getSelectionRotatedScreenBounds` method - Fixes a bug with `pageToScreen`.
This commit is contained in:
parent
1d5a9efa17
commit
4bd1a31721
5 changed files with 197 additions and 1 deletions
|
@ -726,6 +726,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
getSelectedShapes(): TLShape[];
|
||||
getSelectionPageBounds(): Box | null;
|
||||
getSelectionRotatedPageBounds(): Box | undefined;
|
||||
getSelectionRotatedScreenBounds(): Box | undefined;
|
||||
getSelectionRotation(): number;
|
||||
getShape<T extends TLShape = TLShape>(shape: TLParentId | TLShape): T | undefined;
|
||||
getShapeAncestors(shape: TLShape | TLShapeId, acc?: TLShape[]): TLShape[];
|
||||
|
|
|
@ -12182,6 +12182,42 @@
|
|||
"isAbstract": false,
|
||||
"name": "getSelectionRotatedPageBounds"
|
||||
},
|
||||
{
|
||||
"kind": "Method",
|
||||
"canonicalReference": "@tldraw/editor!Editor#getSelectionRotatedScreenBounds:member(1)",
|
||||
"docComment": "/**\n * The bounds of the selection bounding box in the current page space.\n *\n * @readonly @public\n */\n",
|
||||
"excerptTokens": [
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": "getSelectionRotatedScreenBounds(): "
|
||||
},
|
||||
{
|
||||
"kind": "Reference",
|
||||
"text": "Box",
|
||||
"canonicalReference": "@tldraw/editor!Box:class"
|
||||
},
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": " | undefined"
|
||||
},
|
||||
{
|
||||
"kind": "Content",
|
||||
"text": ";"
|
||||
}
|
||||
],
|
||||
"isStatic": false,
|
||||
"returnTypeTokenRange": {
|
||||
"startIndex": 1,
|
||||
"endIndex": 3
|
||||
},
|
||||
"releaseTag": "Public",
|
||||
"isProtected": false,
|
||||
"overloadIndex": 1,
|
||||
"parameters": [],
|
||||
"isOptional": false,
|
||||
"isAbstract": false,
|
||||
"name": "getSelectionRotatedScreenBounds"
|
||||
},
|
||||
{
|
||||
"kind": "Method",
|
||||
"canonicalReference": "@tldraw/editor!Editor#getSelectionRotation:member(1)",
|
||||
|
|
|
@ -1661,6 +1661,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* The bounds of the selection bounding box in the current page space.
|
||||
*
|
||||
|
@ -1701,6 +1702,20 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
return boxFromRotatedVertices
|
||||
}
|
||||
|
||||
/**
|
||||
* The bounds of the selection bounding box in the current page space.
|
||||
*
|
||||
* @readonly
|
||||
* @public
|
||||
*/
|
||||
@computed getSelectionRotatedScreenBounds(): Box | undefined {
|
||||
const bounds = this.getSelectionRotatedPageBounds()
|
||||
if (!bounds) return undefined
|
||||
const { x, y } = this.pageToScreen(bounds.point)
|
||||
const zoom = this.getZoomLevel()
|
||||
return new Box(x, y, bounds.width * zoom, bounds.height * zoom)
|
||||
}
|
||||
|
||||
// Focus Group
|
||||
|
||||
/**
|
||||
|
@ -2848,7 +2863,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
* @public
|
||||
*/
|
||||
pageToScreen(point: VecLike) {
|
||||
const { screenBounds } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID)!
|
||||
const screenBounds = this.getViewportScreenBounds()
|
||||
const { x: cx, y: cy, z: cz = 1 } = this.getCamera()
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue