mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
Fix flyout metrics and workspace scroll (#4674)
* Fix flyout metrics and max scroll logic in scroll * Fix horizontal scroll wheel logic
This commit is contained in:
@@ -90,13 +90,13 @@ Blockly.HorizontalFlyout.prototype.getMetrics_ = function() {
|
||||
var metrics = {
|
||||
contentHeight: optionBox.height * this.workspace_.scale,
|
||||
contentWidth: optionBox.width * this.workspace_.scale,
|
||||
contentTop: 0,
|
||||
contentLeft: 0,
|
||||
contentTop: optionBox.y,
|
||||
contentLeft: optionBox.x,
|
||||
|
||||
scrollHeight: (optionBox.height + 2 * this.MARGIN) * this.workspace_.scale,
|
||||
scrollWidth: (optionBox.width + 2 * this.MARGIN) * this.workspace_.scale,
|
||||
scrollTop: 0,
|
||||
scrollLeft: 0,
|
||||
scrollTop: optionBox.y - this.MARGIN,
|
||||
scrollLeft: optionBox.x - this.MARGIN,
|
||||
|
||||
viewHeight: viewHeight,
|
||||
viewWidth: viewWidth,
|
||||
@@ -276,10 +276,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) {
|
||||
|
||||
if (delta) {
|
||||
var metrics = this.getMetrics_();
|
||||
var pos = metrics.viewLeft + delta;
|
||||
var limit = metrics.scrollWidth - metrics.viewWidth;
|
||||
pos = Math.min(pos, limit);
|
||||
pos = Math.max(pos, 0);
|
||||
var pos = (metrics.viewLeft - metrics.scrollLeft) + delta;
|
||||
this.workspace_.scrollbar.setX(pos);
|
||||
// When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv.
|
||||
Blockly.WidgetDiv.hide();
|
||||
|
||||
@@ -102,7 +102,7 @@ Blockly.VerticalFlyout.prototype.getMetrics_ = function() {
|
||||
|
||||
viewHeight: viewHeight,
|
||||
viewWidth: viewWidth,
|
||||
viewTop: -this.workspace_.scrollY + optionBox.y,
|
||||
viewTop: -this.workspace_.scrollY,
|
||||
viewLeft: -this.workspace_.scrollX,
|
||||
|
||||
absoluteTop: absoluteTop,
|
||||
@@ -267,9 +267,6 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) {
|
||||
if (scrollDelta.y) {
|
||||
var metrics = this.getMetrics_();
|
||||
var pos = (metrics.viewTop - metrics.scrollTop) + scrollDelta.y;
|
||||
var limit = metrics.scrollHeight - metrics.viewHeight;
|
||||
pos = Math.min(pos, limit);
|
||||
pos = Math.max(pos, 0);
|
||||
this.workspace_.scrollbar.setY(pos);
|
||||
// When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv.
|
||||
Blockly.WidgetDiv.hide();
|
||||
|
||||
@@ -2218,9 +2218,10 @@ Blockly.WorkspaceSvg.prototype.scroll = function(x, y) {
|
||||
// to workspace coordinates so we have to inverse them.
|
||||
x = Math.min(x, -metrics.scrollLeft);
|
||||
y = Math.min(y, -metrics.scrollTop);
|
||||
var maxXScroll = metrics.scrollLeft + metrics.scrollWidth - metrics.viewWidth;
|
||||
var maxYScroll =
|
||||
metrics.scrollTop + metrics.scrollHeight - metrics.viewHeight;
|
||||
var maxXDisplacement = Math.max(0, metrics.scrollWidth - metrics.viewWidth);
|
||||
var maxXScroll = metrics.scrollLeft + maxXDisplacement;
|
||||
var maxYDisplacement = Math.max(0, metrics.scrollHeight - metrics.viewHeight);
|
||||
var maxYScroll = metrics.scrollTop + maxYDisplacement;
|
||||
x = Math.max(x, -maxXScroll);
|
||||
y = Math.max(y, -maxYScroll);
|
||||
this.scrollX = x;
|
||||
|
||||
Reference in New Issue
Block a user