From 71f5f596421706d36341e8b40dd9d5b81279cc6b Mon Sep 17 00:00:00 2001 From: picklesrus Date: Thu, 3 Nov 2016 12:06:03 -0700 Subject: [PATCH] Slightly simplify flyout setBackgroundPath method by passing the height and width calculated in similar ways. Before we were doing some calculations inside setBackgroundPath and some outside. (#730) --- core/flyout.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/core/flyout.js b/core/flyout.js index f31a4ff0b..bd3c0d8df 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -385,7 +385,7 @@ Blockly.Flyout.prototype.getMetrics_ = function() { } var viewHeight = this.height_; if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP) { - viewHeight += this.MARGIN - this.SCROLLBAR_PADDING; + viewHeight -= this.SCROLLBAR_PADDING; } var viewWidth = this.width_ - 2 * this.SCROLLBAR_PADDING; } else { @@ -448,15 +448,14 @@ Blockly.Flyout.prototype.position = function() { return; } var edgeWidth = this.horizontalLayout_ ? - targetWorkspaceMetrics.viewWidth : this.width_; - edgeWidth -= this.CORNER_RADIUS; - if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT) { - edgeWidth *= -1; - } + targetWorkspaceMetrics.viewWidth - 2 * this.CORNER_RADIUS : + this.width_ - this.CORNER_RADIUS; - this.setBackgroundPath_(edgeWidth, - this.horizontalLayout_ ? this.height_ : - targetWorkspaceMetrics.viewHeight); + var edgeHeight = this.horizontalLayout_ ? + this.height_ - this.CORNER_RADIUS : + targetWorkspaceMetrics.viewHeight - 2 * this.CORNER_RADIUS; + + this.setBackgroundPath_(edgeWidth, edgeHeight); var x = targetWorkspaceMetrics.absoluteLeft; if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT) { @@ -513,24 +512,26 @@ Blockly.Flyout.prototype.setBackgroundPath_ = function(width, height) { */ Blockly.Flyout.prototype.setBackgroundPathVertical_ = function(width, height) { var atRight = this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT; + var totalWidth = width + this.CORNER_RADIUS; + // Decide whether to start on the left or right. - var path = ['M ' + (atRight ? this.width_ : 0) + ',0']; + var path = ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. - path.push('h', width); + path.push('h', atRight ? -width : width); // Rounded corner. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); // Side closest to workspace. - path.push('v', Math.max(0, height - this.CORNER_RADIUS * 2)); + path.push('v', Math.max(0, height)); // Rounded corner. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); // Bottom. - path.push('h', -width); + path.push('h', atRight ? width : -width); path.push('z'); this.svgBackground_.setAttribute('d', path.join(' ')); }; @@ -552,13 +553,13 @@ Blockly.Flyout.prototype.setBackgroundPathHorizontal_ = function(width, if (atTop) { // Top. - path.push('h', width + this.CORNER_RADIUS); + path.push('h', width + 2 * this.CORNER_RADIUS); // Right. path.push('v', height); // Bottom. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, this.CORNER_RADIUS); - path.push('h', -1 * (width - this.CORNER_RADIUS)); + path.push('h', -1 * width); // Left. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, -this.CORNER_RADIUS); @@ -567,13 +568,13 @@ Blockly.Flyout.prototype.setBackgroundPathHorizontal_ = function(width, // Top. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, -this.CORNER_RADIUS); - path.push('h', width - this.CORNER_RADIUS); + path.push('h', width); // Right. path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, this.CORNER_RADIUS); - path.push('v', height - this.CORNER_RADIUS); + path.push('v', height); // Bottom. - path.push('h', -width - this.CORNER_RADIUS); + path.push('h', -width - 2 * this.CORNER_RADIUS); // Left. path.push('z'); }