Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let blocks scroll over fixed flyout #274

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,19 @@ Blockly.hideChaff = function(opt_allowToolbox) {
Blockly.getMainWorkspaceMetrics_ = function() {
var svgSize = Blockly.svgSize(this.getParentSvg());
if (this.toolbox_) {
svgSize.width -= this.toolbox_.width;
if (this.horizontalLayout) {
svgSize.height -= this.toolbox_.height;
} else {
svgSize.width -= this.toolbox_.width;
}
} else if (this.flyout_) {
if (this.horizontalLayout) {
svgSize.height -= this.flyout_.height_;
} else {
svgSize.width -= this.flyout_.width_;
}
}

// Set the margin to match the flyout's margin so that the workspace does
// not jump as blocks are added.
var MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS - 1;
Expand Down Expand Up @@ -464,9 +475,19 @@ Blockly.getMainWorkspaceMetrics_ = function() {
var topEdge = blockBox.y;
var bottomEdge = topEdge + blockBox.height;
}
var absoluteLeft = 0;
if (this.toolbox_ && this.toolbox_.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
absoluteLeft = this.toolbox_.width;
var absoluteLeft = 0, absoluteTop = 0;
if (this.toolbox_) {
if (this.toolbox_.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
absoluteLeft = this.toolbox_.width;
} else if (this.flyout_.toolboxPosition == Blockly.TOOLBOX_AT_TOP) {
absoluteTop = this.toolbox_.height;
}
} else if (this.flyout_) {
if (this.flyout_.toolboxPosition_ == Blockly.TOOLBOX_AT_LEFT) {
absoluteLeft = this.flyout_.width_;
} else if (this.flyout_.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP) {
absoluteTop = this.flyout_.height_;
}
}
var metrics = {
viewHeight: svgSize.height,
Expand All @@ -477,7 +498,7 @@ Blockly.getMainWorkspaceMetrics_ = function() {
viewLeft: -this.scrollX,
contentTop: topEdge,
contentLeft: leftEdge,
absoluteTop: 0,
absoluteTop: absoluteTop,
absoluteLeft: absoluteLeft
};
return metrics;
Expand Down
9 changes: 5 additions & 4 deletions core/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,16 @@ Blockly.Flyout.prototype.position = function() {
this.setBackgroundPath_(edgeWidth,
this.horizontalLayout_ ? this.height_ + this.verticalOffset_ : metrics.viewHeight);

var x = metrics.absoluteLeft;
var x = 0;
var svgSize = Blockly.svgSize(this.workspace_.getParentSvg());
if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT) {
x += metrics.viewWidth;
x += svgSize.width;
x -= this.width_;
}

var y = metrics.absoluteTop;
var y = 0;
if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_BOTTOM) {
y += metrics.viewHeight;
y += svgSize.height_;
y -= this.height_;
}

Expand Down
6 changes: 0 additions & 6 deletions core/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ Blockly.init_ = function(mainWorkspace) {
// Build a fixed flyout with the root blocks.
mainWorkspace.flyout_.init(mainWorkspace);
mainWorkspace.flyout_.show(options.languageTree.childNodes);
// Translate the workspace sideways to avoid the fixed flyout.
mainWorkspace.scrollX = mainWorkspace.flyout_.width_;
if (options.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
mainWorkspace.scrollX *= -1;
}
mainWorkspace.translate(mainWorkspace.scrollX, 0);
}
}

Expand Down