[fix] zoom to selection (#164)

* fix camera on zoom to selection

* Update tlstate.ts

* Update tlstate.ts
pull/170/head
Steve Ruiz 2021-10-17 09:47:41 +01:00 zatwierdzone przez GitHub
rodzic 01c824bbbe
commit 62343dab9f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -1391,12 +1391,15 @@ export class TLDrawState extends StateManager<Data> {
const bounds = Utils.getCommonBounds(shapes.map(TLDR.getBounds))
const zoom = TLDR.getCameraZoom(
this.bounds.width < this.bounds.height
? (this.bounds.width - 128) / bounds.width
: (this.bounds.height - 128) / bounds.height
let zoom = TLDR.getCameraZoom(
Math.min((this.bounds.width - 128) / bounds.width, (this.bounds.height - 128) / bounds.height)
)
zoom =
this.pageState.camera.zoom === zoom || this.pageState.camera.zoom < 1
? Math.min(1, zoom)
: zoom
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom
@ -1413,14 +1416,19 @@ export class TLDrawState extends StateManager<Data> {
zoomToSelection = (): this => {
if (this.selectedIds.length === 0) return this
console.log('zooming to selection')
const bounds = TLDR.getSelectedBounds(this.state)
const zoom = TLDR.getCameraZoom(
this.bounds.width < this.bounds.height
? (this.bounds.width - 128) / bounds.width
: (this.bounds.height - 128) / bounds.height
let zoom = TLDR.getCameraZoom(
Math.min((this.bounds.width - 128) / bounds.width, (this.bounds.height - 128) / bounds.height)
)
zoom =
this.pageState.camera.zoom === zoom || this.pageState.camera.zoom < 1
? Math.min(1, zoom)
: zoom
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom
@ -1443,6 +1451,7 @@ export class TLDrawState extends StateManager<Data> {
const bounds = Utils.getCommonBounds(Object.values(shapes).map(TLDR.getBounds))
const { zoom } = pageState.camera
const mx = (this.bounds.width - bounds.width * zoom) / 2 / zoom
const my = (this.bounds.height - bounds.height * zoom) / 2 / zoom