improve listtable.
This commit is contained in:
parent
04ffa283ac
commit
1c20b8b2ee
|
@ -25,7 +25,8 @@ function ListTable(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.shrink = true;
|
|
||||||
|
// options.shrink = true;
|
||||||
options.normalShrink = true;
|
options.normalShrink = true;
|
||||||
options.style = options.style || {};
|
options.style = options.style || {};
|
||||||
options.style.border = options.style.border || {};
|
options.style.border = options.style.border || {};
|
||||||
|
@ -37,8 +38,19 @@ function ListTable(options) {
|
||||||
options.style.selected = options.style.cell.selected;
|
options.style.selected = options.style.cell.selected;
|
||||||
options.style.item = options.style.cell;
|
options.style.item = options.style.cell;
|
||||||
|
|
||||||
|
var border = options.border;
|
||||||
|
if (border
|
||||||
|
&& border.top === false
|
||||||
|
&& border.bottom === false
|
||||||
|
&& border.left === false
|
||||||
|
&& border.right === false) {
|
||||||
|
delete options.border;
|
||||||
|
}
|
||||||
|
|
||||||
List.call(this, options);
|
List.call(this, options);
|
||||||
|
|
||||||
|
options.border = border;
|
||||||
|
|
||||||
this._header = new Box({
|
this._header = new Box({
|
||||||
parent: this,
|
parent: this,
|
||||||
left: this.screen.autoPadding ? 0 : this.ileft,
|
left: this.screen.autoPadding ? 0 : this.ileft,
|
||||||
|
@ -84,7 +96,10 @@ ListTable.prototype._calculateMaxes = Table.prototype._calculateMaxes;
|
||||||
ListTable.prototype.setRows =
|
ListTable.prototype.setRows =
|
||||||
ListTable.prototype.setData = function(rows) {
|
ListTable.prototype.setData = function(rows) {
|
||||||
var self = this
|
var self = this
|
||||||
, align = this.__align;
|
, align = this.__align
|
||||||
|
, selected = this.selected
|
||||||
|
, original = this.items.slice()
|
||||||
|
, sel = this.ritems[this.selected];
|
||||||
|
|
||||||
if (this.visible && this.lpos) {
|
if (this.visible && this.lpos) {
|
||||||
this.clearPos();
|
this.clearPos();
|
||||||
|
@ -148,7 +163,15 @@ ListTable.prototype.setData = function(rows) {
|
||||||
|
|
||||||
this._header.setFront();
|
this._header.setFront();
|
||||||
|
|
||||||
this.select(0);
|
// Try to find our old item if it still exists.
|
||||||
|
sel = this.ritems.indexOf(sel);
|
||||||
|
if (~sel) {
|
||||||
|
this.select(sel);
|
||||||
|
} else if (this.items.length === original.length) {
|
||||||
|
this.select(selected);
|
||||||
|
} else {
|
||||||
|
this.select(Math.min(selected, this.items.length - 1));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ListTable.prototype._select = ListTable.prototype.select;
|
ListTable.prototype._select = ListTable.prototype.select;
|
||||||
|
@ -183,7 +206,12 @@ ListTable.prototype.render = function() {
|
||||||
|
|
||||||
var height = coords.yl - coords.yi - this.ibottom;
|
var height = coords.yl - coords.yi - this.ibottom;
|
||||||
|
|
||||||
if (!this.border || this.options.noCellBorders) return coords;
|
var border = this.border;
|
||||||
|
if (!this.border && this.options.border) {
|
||||||
|
border = this.options.border;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!border || this.options.noCellBorders) return coords;
|
||||||
|
|
||||||
// Draw border with correct angles.
|
// Draw border with correct angles.
|
||||||
ry = 0;
|
ry = 0;
|
||||||
|
@ -200,7 +228,7 @@ ListTable.prototype.render = function() {
|
||||||
lines[yi + ry][xi + rx][0] = battr;
|
lines[yi + ry][xi + rx][0] = battr;
|
||||||
lines[yi + ry][xi + rx][1] = '\u252c'; // '┬'
|
lines[yi + ry][xi + rx][1] = '\u252c'; // '┬'
|
||||||
// XXX If we alter iheight and itop for no borders - nothing should be written here
|
// XXX If we alter iheight and itop for no borders - nothing should be written here
|
||||||
if (!self.border.top) {
|
if (!border.top) {
|
||||||
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
||||||
}
|
}
|
||||||
lines[yi + ry].dirty = true;
|
lines[yi + ry].dirty = true;
|
||||||
|
@ -210,7 +238,7 @@ ListTable.prototype.render = function() {
|
||||||
lines[yi + ry][xi + rx][0] = battr;
|
lines[yi + ry][xi + rx][0] = battr;
|
||||||
lines[yi + ry][xi + rx][1] = '\u2534'; // '┴'
|
lines[yi + ry][xi + rx][1] = '\u2534'; // '┴'
|
||||||
// XXX If we alter iheight and ibottom for no borders - nothing should be written here
|
// XXX If we alter iheight and ibottom for no borders - nothing should be written here
|
||||||
if (!self.border.bottom) {
|
if (!border.bottom) {
|
||||||
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
lines[yi + ry][xi + rx][1] = '\u2502'; // '│'
|
||||||
}
|
}
|
||||||
lines[yi + ry].dirty = true;
|
lines[yi + ry].dirty = true;
|
||||||
|
|
Loading…
Reference in New Issue