Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GE] Make sure artboard is resized correctly when resizing the canvas #12828

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions packages/tools/guiEditor/src/diagram/workbench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
this._visibleRegionContainer.heightInPixels = this._guiSize.height;
this.props.globalState.onResizeObservable.notifyObservers(this._guiSize);
this.props.globalState.onReframeWindowObservable.notifyObservers();
this.props.globalState.onArtBoardUpdateRequiredObservable.notifyObservers();
this.props.globalState.onWindowResizeObservable.notifyObservers();
}

public applyEditorTransformation() {
Expand Down Expand Up @@ -220,11 +220,21 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
// Hotkey shortcuts
globalState.hostDocument!.addEventListener("keydown", this.keyEvent, false);
globalState.hostDocument!.defaultView!.addEventListener("blur", this.blurEvent, false);

let framesToUpdate = 1;
globalState.onWindowResizeObservable.add(() => {
globalState.onGizmoUpdateRequireObservable.notifyObservers();
globalState.onArtBoardUpdateRequiredObservable.notifyObservers();
this._engine.resize();
// update the size for the next 5 frames
framesToUpdate += 5;
});
globalState.onNewSceneObservable.add((scene) => {
scene &&
scene.onBeforeRenderObservable.add(() => {
if (framesToUpdate > 0) {
framesToUpdate--;
globalState.onGizmoUpdateRequireObservable.notifyObservers();
this._engine.resize();
globalState.onArtBoardUpdateRequiredObservable.notifyObservers();
}
});
});

globalState.onCopyObservable.add((copyFn) => this.copyToClipboard(copyFn));
Expand Down Expand Up @@ -854,16 +864,19 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
// Watch for browser/canvas resize events
this.props.globalState.hostWindow.addEventListener("resize", () => {
this.props.globalState.onWindowResizeObservable.notifyObservers();
this._scene.onBeforeRenderObservable.addOnce(() => {
this.props.globalState.onWindowResizeObservable.notifyObservers();
});
});
this._engine.resize();
this.props.globalState.onWindowResizeObservable.notifyObservers();

this.props.globalState.guiTexture.onBeginRenderObservable.add(() => {
this.applyEditorTransformation();
});

this.props.globalState.onPropertyChangedObservable.add((ev) => {
(ev.object as Control).markAsDirty(false);
this.props.globalState.onArtBoardUpdateRequiredObservable.notifyObservers();
this.props.globalState.onWindowResizeObservable.notifyObservers();
});

// Every time the original ADT re-renders, we must also re-render, so that layout information is computed correctly
Expand Down Expand Up @@ -971,8 +984,7 @@ export class WorkbenchComponent extends React.Component<IWorkbenchComponentProps
const panningDelta = this.getScaledPointerPosition().subtract(this._initialPanningOffset).multiplyByFloats(1, -1);
this._panningOffset = this._panningOffset.add(panningDelta);
this._initialPanningOffset = this.getScaledPointerPosition();
this.props.globalState.onArtBoardUpdateRequiredObservable.notifyObservers();
this.props.globalState.onGizmoUpdateRequireObservable.notifyObservers();
this.props.globalState.onWindowResizeObservable.notifyObservers();
}

// Move the selected controls. Can be either on horizontal (leftInPixels) or
Expand Down