mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
Refactor flyout and toolbox metrics (#4648)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user