make new scrollable code compatible with get=false. add fixed option.

This commit is contained in:
Christopher Jeffrey 2013-07-27 05:34:59 -05:00
parent 2dc3146d1f
commit 69f5993735
1 changed files with 27 additions and 16 deletions

View File

@ -1577,10 +1577,7 @@ function Element(options) {
options = options || {}; options = options || {};
// Workaround to get a `scrollable` option. // Workaround to get a `scrollable` option.
if (options.scrollable if (options.scrollable && !this._ignore && this.type !== 'scrollable-box') {
&& !this._ignore
&& this.type !== 'scrollable-box'
&& this.type !== 'scrollable-text') {
Object.getOwnPropertyNames(ScrollableBox.prototype).forEach(function(key) { Object.getOwnPropertyNames(ScrollableBox.prototype).forEach(function(key) {
if (key === 'type') return; if (key === 'type') return;
Object.defineProperty(this, key, Object.defineProperty(this, key,
@ -1637,6 +1634,7 @@ function Element(options) {
this.valign = options.valign || 'top'; this.valign = options.valign || 'top';
this.wrap = options.wrap !== false; this.wrap = options.wrap !== false;
this.shrink = options.shrink; this.shrink = options.shrink;
this.fixed = options.fixed;
if (typeof options.padding === 'number' || !options.padding) { if (typeof options.padding === 'number' || !options.padding) {
options.padding = { options.padding = {
@ -1687,7 +1685,8 @@ function Element(options) {
top: this.border ? 0 : -1, top: this.border ? 0 : -1,
tags: this.parseTags, tags: this.parseTags,
shrink: true, shrink: true,
style: this.style.label style: this.style.label,
fixed: true
})); }));
} }
@ -2638,7 +2637,8 @@ Element.prototype._getCoords = function(get) {
, coords , coords
, v , v
, notop , notop
, nobot; , nobot
, ppos;
// Attempt to shrink the element base on the // Attempt to shrink the element base on the
// size of the content and child elements. // size of the content and child elements.
@ -2657,38 +2657,43 @@ Element.prototype._getCoords = function(get) {
// inside of the visible scroll area. // inside of the visible scroll area.
// NOTE: Lists have a property where only // NOTE: Lists have a property where only
// the list items are obfuscated. // the list items are obfuscated.
if (el && (!el.items || ~el.items.indexOf(this))) { if (el && !this.fixed) {
ppos = get
? this.parent.lpos
: this.parent._getCoords();
if (this.parent.scrollable) { if (this.parent.scrollable) {
yi -= this.parent.lpos.base; yi -= ppos.base;
yl -= this.parent.lpos.base; yl -= ppos.base;
} }
if (yi < this.parent.lpos.yi + this.parent.itop) { if (yi < ppos.yi + this.parent.itop) {
if (yl - 1 < this.parent.lpos.yi + this.parent.itop) { if (yl - 1 < ppos.yi + this.parent.itop) {
// Is above. // Is above.
return; return;
} else { } else {
// Is partially covered above. // Is partially covered above.
notop = true; notop = true;
v = this.parent.lpos.yi - yi; v = ppos.yi - yi;
v += this.parent.itop - this.itop; v += this.parent.itop - this.itop;
base += v; base += v;
yi += v; yi += v;
} }
} else if (yl > this.parent.lpos.yl - this.parent.ibottom) { } else if (yl > ppos.yl - this.parent.ibottom) {
if (yi > this.parent.lpos.yl - 1 - this.parent.ibottom) { if (yi > ppos.yl - 1 - this.parent.ibottom) {
// Is below. // Is below.
return; return;
} else { } else {
// Is partially covered below. // Is partially covered below.
nobot = true; nobot = true;
v = yl - this.parent.lpos.yl; v = yl - ppos.yl;
v += this.parent.ibottom - this.ibottom; v += this.parent.ibottom - this.ibottom;
yl -= v; yl -= v;
} }
} }
// Shouldn't be necessary. // Shouldn't be necessary.
// assert.ok(yi < yl);
if (yi >= yl) return; if (yi >= yl) return;
} }
@ -3637,6 +3642,12 @@ function List(options) {
self.childOffset = visible - 1; self.childOffset = visible - 1;
} }
}); });
this.on('adopt', function(el) {
if (!~self.items.indexOf(el)) {
el.fixed = true;
}
});
} }
List.prototype.__proto__ = Box.prototype; List.prototype.__proto__ = Box.prototype;
@ -3672,8 +3683,8 @@ List.prototype.add = function(item) {
var item = new Box(options); var item = new Box(options);
this.append(item);
this.items.push(item); this.items.push(item);
this.append(item);
if (this.mouse) { if (this.mouse) {
item.on('click', function(data) { item.on('click', function(data) {