diff --git a/core/flyout_base.js b/core/flyout_base.js index f0f7f390..92b69e23 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -590,6 +590,24 @@ Blockly.Flyout.prototype.stepScrollAnimation = function() { requestAnimationFrame(this.stepScrollAnimation.bind(this)); }; +/** + * Get the scaled scroll position. + * @return {number} The current scroll position. + */ +Blockly.Flyout.prototype.getScrollPos = function() { + var pos = this.horizontalLayout_ ? + -this.workspace_.scrollX : -this.workspace_.scrollY; + return pos / this.workspace_.scale; +}; + +/** + * Set the scroll position, scaling it. + * @param {number} pos The scroll position to set. + */ +Blockly.Flyout.prototype.setScrollPos = function(pos) { + this.scrollbar_.set(pos * this.workspace_.scale); +}; + /** * Delete blocks and background buttons from a previous showing of the flyout. * @private diff --git a/core/toolbox.js b/core/toolbox.js index 31ab9cb1..7be66256 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -337,6 +337,45 @@ Blockly.Toolbox.prototype.getSelectedItem = function() { return this.selectedItem_; }; +/** + * @return {string} The name of the currently selected category. + */ +Blockly.Toolbox.prototype.getSelectedCategoryName = function() { + return this.selectedItem_.name_; +}; + +/** + * @return {number} The distance flyout is scrolled below the top of the currently + * selected category. + */ +Blockly.Toolbox.prototype.getCategoryScrollOffset = function() { + var categoryPos = this.getCategoryPositionByName(this.getSelectedCategoryName()); + return this.flyout_.getScrollPos() - categoryPos; +}; + +/** + * Get the position of a category by name. + * @param {string} name The name of the category. + * @return {number} The position of the category. + */ +Blockly.Toolbox.prototype.getCategoryPositionByName = function(name) { + var scrollPositions = this.flyout_.categoryScrollPositions; + for (var i = 0; i < scrollPositions.length; i++) { + if (name === scrollPositions[i].categoryName) { + return scrollPositions[i].position; + } + } +}; + +/** + * Set the scroll position of the flyout. + * @param {number} pos The position to set. + */ +Blockly.Toolbox.prototype.setFlyoutScrollPos = function(pos) { + this.flyout_.setScrollPos(pos); +}; + + /** * Set the currently selected category. * @param {Blockly.Toolbox.Category} item The category to select.