Refactor flyout and toolbox metrics (#4648)

This commit is contained in:
alschmiedt
2021-03-15 12:37:23 -07:00
committed by GitHub
parent e8ad0f92a7
commit d58c80db76
4 changed files with 7 additions and 2 deletions

View File

@@ -96,7 +96,7 @@ Blockly.HorizontalFlyout.prototype.getY = function() {
// If this flyout is not the trashcan flyout (e.g. toolbox or mutator).
if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) {
// If there is a category toolbox.
if (toolboxMetrics.height) {
if (this.targetWorkspace.getToolbox()) {
if (atTop) {
y = toolboxMetrics.height;
} else {

View File

@@ -89,7 +89,7 @@ Blockly.VerticalFlyout.prototype.getX = function() {
// If this flyout is not the trashcan flyout (e.g. toolbox or mutator).
if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) {
// If there is a category toolbox.
if (toolboxMetrics.width) {
if (this.targetWorkspace.getToolbox()) {
if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) {
x = toolboxMetrics.width;
} else {

View File

@@ -600,6 +600,7 @@ Blockly.Toolbox.prototype.isHorizontal = function() {
* @public
*/
Blockly.Toolbox.prototype.position = function() {
var workspaceMetrics = this.workspace_.getMetrics();
var toolboxDiv = this.HtmlDiv;
if (!toolboxDiv) {
// Not initialized yet.
@@ -611,6 +612,7 @@ Blockly.Toolbox.prototype.position = function() {
toolboxDiv.style.height = 'auto';
toolboxDiv.style.width = '100%';
this.height_ = toolboxDiv.offsetHeight;
this.width_ = workspaceMetrics.viewWidth;
if (this.toolboxPosition == Blockly.utils.toolbox.Position.TOP) {
toolboxDiv.style.top = '0';
} else { // Bottom
@@ -624,6 +626,7 @@ Blockly.Toolbox.prototype.position = function() {
}
toolboxDiv.style.height = '100%';
this.width_ = toolboxDiv.offsetWidth;
this.height_ = workspaceMetrics.viewHeight;
}
this.flyout_.position();
};

View File

@@ -423,6 +423,8 @@ suite('Toolbox', function() {
suite('position', function() {
setup(function() {
this.toolbox = getBasicToolbox();
var metricsStub = sinon.stub(this.toolbox.workspace_, 'getMetrics');
metricsStub.returns({});
});
function checkHorizontalToolbox(toolbox) {