mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Merge pull request #1407 from ericrosenbaum/bugfix/scroll-position-stability
Support for scroll position stability
This commit is contained in:
commit
d60e700c3a
2 changed files with 57 additions and 0 deletions
|
@ -590,6 +590,24 @@ Blockly.Flyout.prototype.stepScrollAnimation = function() {
|
||||||
requestAnimationFrame(this.stepScrollAnimation.bind(this));
|
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.
|
* Delete blocks and background buttons from a previous showing of the flyout.
|
||||||
* @private
|
* @private
|
||||||
|
|
|
@ -337,6 +337,45 @@ Blockly.Toolbox.prototype.getSelectedItem = function() {
|
||||||
return this.selectedItem_;
|
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.
|
* Set the currently selected category.
|
||||||
* @param {Blockly.Toolbox.Category} item The category to select.
|
* @param {Blockly.Toolbox.Category} item The category to select.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue