mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Fix RTL alignment of new blocks when zoomed.
This commit is contained in:
@@ -363,7 +363,6 @@ Blockly.Flyout.prototype.show = function(xmlList) {
|
||||
}
|
||||
this.buttons_.length = 0;
|
||||
|
||||
this.workspace_.scale = this.targetWorkspace_.scale;
|
||||
var margin = this.CORNER_RADIUS;
|
||||
this.svgGroup_.style.display = 'block';
|
||||
|
||||
@@ -466,6 +465,7 @@ Blockly.Flyout.prototype.show = function(xmlList) {
|
||||
* For RTL: Lay out the blocks right-aligned.
|
||||
*/
|
||||
Blockly.Flyout.prototype.reflow = function() {
|
||||
this.workspace_.scale = this.targetWorkspace_.scale;
|
||||
var flyoutWidth = 0;
|
||||
var margin = this.CORNER_RADIUS;
|
||||
var blocks = this.workspace_.getTopBlocks(false);
|
||||
@@ -484,10 +484,11 @@ Blockly.Flyout.prototype.reflow = function() {
|
||||
var blockHW = block.getHeightWidth();
|
||||
if (this.RTL) {
|
||||
// With the flyoutWidth known, right-align the blocks.
|
||||
var oldX = block.getRelativeToSurfaceXY().x;
|
||||
var dx = flyoutWidth - margin;
|
||||
dx /= this.workspace_.scale;
|
||||
dx -= Blockly.BlockSvg.TAB_WIDTH;
|
||||
block.moveBy(dx, 0);
|
||||
block.moveBy(dx - oldX, 0);
|
||||
}
|
||||
if (block.flyoutRect_) {
|
||||
block.flyoutRect_.setAttribute('width', blockHW.width);
|
||||
@@ -632,8 +633,13 @@ Blockly.Flyout.prototype.createBlockFunc_ = function(originBlock) {
|
||||
}
|
||||
var xyOld = Blockly.getSvgXY_(svgRootOld, workspace);
|
||||
// Scale the scroll (getSvgXY_ did not do this).
|
||||
xyOld.x += flyout.workspace_.scrollX / flyout.workspace_.scale -
|
||||
flyout.workspace_.scrollX;
|
||||
if (flyout.RTL) {
|
||||
var width = workspace.getMetrics().viewWidth - flyout.width_;
|
||||
xyOld.x += width / workspace.scale - width;
|
||||
} else {
|
||||
xyOld.x += flyout.workspace_.scrollX / flyout.workspace_.scale -
|
||||
flyout.workspace_.scrollX;
|
||||
}
|
||||
xyOld.y += flyout.workspace_.scrollY / flyout.workspace_.scale -
|
||||
flyout.workspace_.scrollY;
|
||||
var svgRootNew = block.getSvgRoot();
|
||||
|
||||
@@ -896,7 +896,6 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, type) {
|
||||
Blockly.hideChaff(false);
|
||||
if (this.flyout_) {
|
||||
// No toolbox, resize flyout.
|
||||
this.flyout_.workspace_.scale = this.scale;
|
||||
this.flyout_.reflow();
|
||||
}
|
||||
};
|
||||
@@ -921,6 +920,11 @@ Blockly.WorkspaceSvg.prototype.zoomReset = function() {
|
||||
var metrics = this.getMetrics();
|
||||
this.scrollbar.set((metrics.contentWidth - metrics.viewWidth) / 2,
|
||||
(metrics.contentHeight - metrics.viewHeight) / 2);
|
||||
Blockly.hideChaff(false);
|
||||
if (this.flyout_) {
|
||||
// No toolbox, resize flyout.
|
||||
this.flyout_.reflow();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user