mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-11 03:25:45 +00:00
listbar cleanup.
This commit is contained in:
parent
5930dab630
commit
6fd0527c07
106
lib/widget.js
106
lib/widget.js
@ -3025,14 +3025,14 @@ Element.prototype._getCoords = function(get) {
|
||||
}
|
||||
|
||||
if (this.noOverflow && this.parent.lpos) {
|
||||
if (xi < this.parent.lpos.xi - this.parent.ileft) {
|
||||
xi = this.parent.lpos.xi - this.parent.ileft;
|
||||
if (xi < this.parent.lpos.xi + this.parent.ileft) {
|
||||
xi = this.parent.lpos.xi + this.parent.ileft;
|
||||
}
|
||||
if (xl > this.parent.lpos.xl - this.parent.iright) {
|
||||
xl = this.parent.lpos.xl - this.parent.iright;
|
||||
}
|
||||
if (yi < this.parent.lpos.yi - this.parent.itop) {
|
||||
yi = this.parent.lpos.yi - this.parent.itop;
|
||||
if (yi < this.parent.lpos.yi + this.parent.itop) {
|
||||
yi = this.parent.lpos.yi + this.parent.itop;
|
||||
}
|
||||
if (yl > this.parent.lpos.yl - this.parent.ibottom) {
|
||||
yl = this.parent.lpos.yl - this.parent.ibottom;
|
||||
@ -5730,14 +5730,14 @@ function Listbar(options) {
|
||||
|
||||
Box.call(this, options);
|
||||
|
||||
this._.debug = new Box({
|
||||
parent: this.screen,
|
||||
top: 0,
|
||||
left: 0,
|
||||
height: 'shrink',
|
||||
width: 'shrink',
|
||||
content: '...'
|
||||
});
|
||||
//this._.debug = new Box({
|
||||
// parent: this.screen,
|
||||
// top: 0,
|
||||
// left: 0,
|
||||
// height: 'shrink',
|
||||
// width: 'shrink',
|
||||
// content: '...'
|
||||
//});
|
||||
|
||||
if (options.commands || options.items) {
|
||||
this.setItems(options.commands || options.items);
|
||||
@ -5965,55 +5965,22 @@ Listbar.prototype.appendItem = function(item, callback) {
|
||||
|
||||
Listbar.prototype.render = function() {
|
||||
var self = this
|
||||
, lpos = this._getCoords(this)
|
||||
, drawn = 0
|
||||
, redo;
|
||||
, drawn = 0;
|
||||
|
||||
if (!this.screen.autoPadding) {
|
||||
drawn += this.ileft;
|
||||
}
|
||||
|
||||
this.items.forEach(function(el, i) {
|
||||
// XXX Ugly workaround - no need for .scrollable though
|
||||
if (0) el.width = el.getText().length + 2;
|
||||
|
||||
if (i < self.leftBase) {
|
||||
el.hide();
|
||||
} else {
|
||||
el.rleft = drawn + 1;
|
||||
|
||||
// XXX Ugly workaround - no need for .scrollable though
|
||||
if (0) if (drawn + el.width + 2 > lpos.xl - lpos.xi - self.iwidth) {
|
||||
//if (i === self.items.length - 1 && self.selected === i) {
|
||||
if (self.selected === i) {
|
||||
redo = true;
|
||||
return;
|
||||
}
|
||||
// 0 could be 2 without the autopadding check
|
||||
var d = (drawn + el.width + 2) - (lpos.xl - lpos.xi - self.iwidth);
|
||||
// XXX WHY? This seems backwards:
|
||||
//d -= self.screen.autoPadding ? 1 : 0;
|
||||
if (d >= el.width) {
|
||||
el.hide();
|
||||
return;
|
||||
}
|
||||
el.width -= d;
|
||||
}
|
||||
|
||||
drawn += el.width + 2;
|
||||
el.show();
|
||||
}
|
||||
});
|
||||
|
||||
// XXX Ugly workaround - no need for .scrollable though
|
||||
if (0) if (redo) {
|
||||
this.leftBase++;
|
||||
this.leftOffset--;
|
||||
this.leftBase = Math.min(this.items.length - 1, this.leftBase);
|
||||
this.leftOffset = Math.max(0, this.leftOffset);
|
||||
return this.render();
|
||||
}
|
||||
|
||||
return this._render();
|
||||
};
|
||||
|
||||
@ -6041,31 +6008,18 @@ Listbar.prototype.select = function(offset) {
|
||||
if (i < self.leftBase) return;
|
||||
var lpos = el._getCoords();
|
||||
if (!lpos) return;
|
||||
//drawn += (lpos.xl - lpos.xi) + 2;
|
||||
// XXX Ugly workaround - no need for .scrollable though
|
||||
drawn += el.getText().length + 2 + 2;
|
||||
|
||||
// XXX Need this because overflowed elements will still return lpos.
|
||||
if (lpos.xl - lpos.xi <= 0) return;
|
||||
|
||||
drawn += (lpos.xl - lpos.xi) + 2;
|
||||
|
||||
// XXX Need this because overflowed elements will still return lpos.
|
||||
//drawn += el.getText().length + 2 + 2;
|
||||
|
||||
if (drawn <= width) visible++;
|
||||
});
|
||||
|
||||
var diff = offset - (this.leftBase + this.leftOffset);
|
||||
if (0) if (offset > this.leftBase + this.leftOffset) {
|
||||
if (offset - this.leftBase > visible - 1) {
|
||||
this.leftOffset -= diff - 1;
|
||||
this.leftBase += diff;
|
||||
} else {
|
||||
this.leftOffset += diff;
|
||||
}
|
||||
} else if (offset < this.leftBase + this.leftOffset) {
|
||||
diff = -diff;
|
||||
if (offset - this.leftBase < 0) {
|
||||
this.leftOffset += diff - 1;
|
||||
//this.leftOffset = 0;
|
||||
this.leftBase -= diff;
|
||||
} else {
|
||||
this.leftOffset -= diff;
|
||||
}
|
||||
}
|
||||
|
||||
var diff = offset - (this.leftBase + this.leftOffset);
|
||||
if (offset > this.leftBase + this.leftOffset) {
|
||||
if (offset > this.leftBase + visible - 1) {
|
||||
@ -6089,14 +6043,14 @@ Listbar.prototype.select = function(offset) {
|
||||
//this.leftOffset = Math.max(0, this.leftOffset);
|
||||
//this.leftBase = Math.max(0, this.leftBase);
|
||||
|
||||
this._.debug.setContent(JSON.stringify({
|
||||
leftOffset: this.leftOffset,
|
||||
leftBase: this.leftBase,
|
||||
drawn: drawn,
|
||||
visible: visible,
|
||||
width: width,
|
||||
diff: diff
|
||||
}, null, 2));
|
||||
//this._.debug.setContent(JSON.stringify({
|
||||
// leftOffset: this.leftOffset,
|
||||
// leftBase: this.leftBase,
|
||||
// drawn: drawn,
|
||||
// visible: visible,
|
||||
// width: width,
|
||||
// diff: diff
|
||||
//}, null, 2));
|
||||
};
|
||||
|
||||
Listbar.prototype.removeItem = function(child) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user