Skip to content

Commit

Permalink
feat: Add margin around zoomToFit (google#6042)
Browse files Browse the repository at this point in the history
* Add margin around zoomToFit

* Change configurable property to fixed constant.

* VS Code keeps indenting stuff for no reason.
  • Loading branch information
NeilFraser authored Apr 7, 2022
1 parent 7991c8a commit a202558
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ goog.require('Blockly.MetricsManager');
goog.require('Blockly.Msg');


/**
* Margin around the top/bottom/left/right after a zoomToFit call.
* @const
*/
const ZOOM_TO_FIT_MARGIN = 20;

/**
* Class for a workspace. This is an onscreen area with optional trashcan,
* scrollbars, bubbles, and dragging.
Expand Down Expand Up @@ -2168,8 +2174,9 @@ class WorkspaceSvg extends Workspace {
let workspaceWidth = metrics.viewWidth;
let workspaceHeight = metrics.viewHeight;
const blocksBox = this.getBlocksBoundingBox();
let blocksWidth = blocksBox.right - blocksBox.left;
let blocksHeight = blocksBox.bottom - blocksBox.top;
const doubleMargin = ZOOM_TO_FIT_MARGIN * 2;
let blocksWidth = blocksBox.right - blocksBox.left + doubleMargin;
let blocksHeight = blocksBox.bottom - blocksBox.top + doubleMargin;
if (!blocksWidth) {
return; // Prevents zooming to infinity.
}
Expand Down

0 comments on commit a202558

Please sign in to comment.