From 363ff487a45c3c9bce8989f7a40964c7f984223c Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 28 Jan 2019 15:24:56 -0800 Subject: [PATCH] Changed trashcan and zoom controls to be positioned in the opposite corner of the toolbox. Fixed trashcan hotspot being incorrect. --- core/flyout_horizontal.js | 4 +--- core/flyout_vertical.js | 4 +--- core/trashcan.js | 29 +++++++++++------------------ core/zoom_controls.js | 25 ++++++++++--------------- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index e5e502a24..fd2c8c503 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -366,8 +366,6 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { } // Record the height for .getMetrics_ and .position. this.height_ = flyoutHeight; - // Call this since it is possible the trash and zoom buttons need - // to move. e.g. on a bottom positioned flyout when zoom is clicked. - this.targetWorkspace_.resize(); + this.position(); } }; diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 2f6e79de8..65886f384 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -392,8 +392,6 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { } // Record the width for .getMetrics_ and .position. this.width_ = flyoutWidth; - // Call this since it is possible the trash and zoom buttons need - // to move. e.g. on a bottom positioned flyout when zoom is clicked. - this.targetWorkspace_.resize(); + this.position(); } }; diff --git a/core/trashcan.js b/core/trashcan.js index 2041b1991..2de4d4f58 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -56,7 +56,8 @@ Blockly.Trashcan = function(workspace) { Blockly.TOOLBOX_AT_BOTTOM : Blockly.TOOLBOX_AT_TOP; this.flyout_ = new Blockly.HorizontalFlyout(flyoutWorkspaceOptions); } else { - flyoutWorkspaceOptions.toolboxPosition = this.workspace_.RTL ? + flyoutWorkspaceOptions.toolboxPosition = + this.workspace_.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT ? Blockly.TOOLBOX_AT_LEFT : Blockly.TOOLBOX_AT_RIGHT; this.flyout_ = new Blockly.VerticalFlyout(flyoutWorkspaceOptions); } @@ -304,9 +305,8 @@ Blockly.Trashcan.prototype.dispose = function() { /** * Position the trashcan. - * It is positioned in the upper corner when the toolbox is on bottom, and the - * bottom corner for all other toolbox positions. It is on the right in LTR, - * and left in RTL. + * It is positioned in the opposite corner to the corner the + * categories/toolbox starts at. */ Blockly.Trashcan.prototype.position = function() { // Not yet initialized. @@ -318,21 +318,14 @@ Blockly.Trashcan.prototype.position = function() { // There are no metrics available (workspace is probably not visible). return; } - if (this.workspace_.RTL) { - this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; - if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) { - this.left_ += metrics.flyoutWidth; - if (this.workspace_.toolbox_) { - this.left_ += metrics.absoluteLeft; - } - } - } else { + if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_LEFT + || (this.workspace_.horizontalLayout && !this.workspace_.RTL)) { + // Toolbox starts in the left corner. this.left_ = metrics.viewWidth + metrics.absoluteLeft - - this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; - - if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) { - this.left_ -= metrics.flyoutWidth; - } + this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; + } else { + // Toolbox starts in the right corner. + this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; } if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_BOTTOM) { diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 5ba858a37..5103d15cb 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -131,7 +131,9 @@ Blockly.ZoomControls.prototype.dispose = function() { }; /** - * Move the zoom controls to the bottom-right corner. + * Position the zoom controls. + * It is positioned in the opposite corner to the corner the + * categories/toolbox starts at. */ Blockly.ZoomControls.prototype.position = function() { // Not yet initialized. @@ -143,21 +145,14 @@ Blockly.ZoomControls.prototype.position = function() { // There are no metrics available (workspace is probably not visible). return; } - if (this.workspace_.RTL) { - this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; - if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) { - this.left_ += metrics.flyoutWidth; - if (this.workspace_.toolbox_) { - this.left_ += metrics.absoluteLeft; - } - } - } else { + if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_LEFT + || (this.workspace_.horizontalLayout && !this.workspace_.RTL)) { + // Toolbox starts in the left corner. this.left_ = metrics.viewWidth + metrics.absoluteLeft - - this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; - - if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) { - this.left_ -= metrics.flyoutWidth; - } + this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness; + } else { + // Toolbox starts in the right corner. + this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness; } if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_BOTTOM) {