diff --git a/lib/widget.js b/lib/widget.js index 769b1a8..041a687 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -3108,7 +3108,7 @@ Element.prototype.render = function() { if (this.alwaysScroll) { y = this.childBase / (i - (yl - yi)); } else { - y = (this.childBase + this.childOffset) / i; + y = (this.childBase + this.childOffset) / (i - 1); } y = yi + ((yl - yi) * y | 0); if (y >= yl) y = yl - 1; @@ -3635,10 +3635,15 @@ ScrollableBox.prototype._scrollBottom = function() { return bottom; }; +ScrollableBox.prototype.setScroll = ScrollableBox.prototype.scrollTo = function(offset) { return this.scroll(offset - (this.childBase + this.childOffset)); }; +ScrollableBox.prototype.getScroll = function() { + return this.childBase + this.childOffset; +}; + ScrollableBox.prototype.scroll = function(offset, always) { if (!this.scrollable) return; @@ -3755,6 +3760,31 @@ ScrollableBox.prototype.resetScroll = function() { return this.emit('scroll'); }; +ScrollableBox.prototype.getScrollPerc = function(s) { + var pos = this.lpos || this._getCoords(); + if (!pos) return s ? -1 : 0; + + var height = (pos.yl - pos.yi) - this.iheight + , i = Math.max(this._clines.length, this._scrollBottom()) + , p; + + if (height < i) { + if (this.alwaysScroll) { + p = this.childBase / (i - height); + } else { + p = (this.childBase + this.childOffset) / (i - 1); + } + return p * 100; + } + + return s ? -1 : 0; +}; + +ScrollableBox.prototype.setScrollPerc = function(i) { + var m = Math.max(this._clines.length, this._scrollBottom()); + return this.scrollTo((i / 100) * m | 0); +}; + /** * ScrollableText */