Right-align flyout buttons in RTL.

Fixes #1208.
This commit is contained in:
Neil Fraser
2017-11-06 18:41:58 -08:00
committed by Neil Fraser
parent 8cedef49ac
commit 3bf0418460
2 changed files with 19 additions and 2 deletions

View File

@@ -203,6 +203,14 @@ Blockly.FlyoutButton.prototype.moveTo = function(x, y) {
this.updateTransform_();
};
/**
* Location of the button.
* @return {!goog.math.Coordinate} x, y coordinates.
*/
Blockly.FlyoutButton.prototype.getPosition = function() {
return this.position_;
};
/**
* Get the button's target workspace.
* @return {!Blockly.WorkspaceSvg} The target workspace of the flyout where this

View File

@@ -353,14 +353,23 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() {
if (this.RTL) {
// With the flyoutWidth known, right-align the blocks.
var oldX = block.getRelativeToSurfaceXY().x;
var newX = flyoutWidth / this.workspace_.scale - this.MARGIN;
newX -= Blockly.BlockSvg.TAB_WIDTH;
var newX = flyoutWidth / this.workspace_.scale - this.MARGIN -
Blockly.BlockSvg.TAB_WIDTH;
block.moveBy(newX - oldX, 0);
}
if (block.flyoutRect_) {
this.moveRectToBlock_(block.flyoutRect_, block);
}
}
if (this.RTL) {
// With the flyoutWidth known, right-align the buttons.
for (var i = 0, button; button = this.buttons_[i]; i++) {
var y = button.getPosition().y;
var x = flyoutWidth - button.width - this.MARGIN -
Blockly.BlockSvg.TAB_WIDTH;
button.moveTo(x, y);
}
}
// Record the width for .getMetrics_ and .position.
this.width_ = flyoutWidth;
// Call this since it is possible the trash and zoom buttons need