refactor. stop usign xi_, yi_.
This commit is contained in:
parent
566b800a04
commit
6f8ab54a4f
214
lib/widget.js
214
lib/widget.js
|
@ -1953,9 +1953,9 @@ Box.prototype._getShrinkSize = function(content) {
|
|||
};
|
||||
};
|
||||
|
||||
Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) {
|
||||
Box.prototype._getShrinkBox = function(xi, xl, yi, yl) {
|
||||
if (!this.children.length) {
|
||||
return { xi: xi_, xl: xi_, yi: yi_, yl: yi_ };
|
||||
return { xi: xi, xl: xi, yi: yi, yl: yi };
|
||||
//return { xi: Infinity, xl: 0, yi: Infinity, yl: 0 };
|
||||
}
|
||||
|
||||
|
@ -1975,13 +1975,13 @@ Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) {
|
|||
var xll = xl, yll = yl;
|
||||
|
||||
if (this.options.left == null && this.options.right != null) {
|
||||
if (this.options.width == null) xi_ = xl - (mxl - mxi);
|
||||
if (this.options.width == null) xi = xl - (mxl - mxi);
|
||||
} else {
|
||||
if (this.options.width == null) xl = mxl;
|
||||
}
|
||||
|
||||
if (this.options.top == null && this.options.bottom != null) {
|
||||
if (this.options.height == null) yi_ = yl - (myl - myi);
|
||||
if (this.options.height == null) yi = yl - (myl - myi);
|
||||
} else {
|
||||
if (this.options.height == null) yl = myl;
|
||||
}
|
||||
|
@ -1989,20 +1989,20 @@ Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) {
|
|||
// Recenter shrunken elements.
|
||||
if (xl < xll && this.options.left === 'center') {
|
||||
xll = (xll - xl) / 2 | 0;
|
||||
xi_ += xll;
|
||||
xi += xll;
|
||||
xl += xll;
|
||||
}
|
||||
|
||||
if (yl < yll && this.options.top === 'center') {
|
||||
yll = (yll - yl) / 2 | 0;
|
||||
yi_ += yll;
|
||||
yi += yll;
|
||||
yl += yll;
|
||||
}
|
||||
|
||||
return { xi: xi_, xl: xl, yi: yi_, yl: yl };
|
||||
return { xi: xi, xl: xl, yi: yi, yl: yl };
|
||||
};
|
||||
|
||||
Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) {
|
||||
Box.prototype._getShrinkContent = function(xi, xl, yi, yl, content) {
|
||||
var hw = this._getShrinkSize(content)
|
||||
, h = hw.height
|
||||
, w = hw.width
|
||||
|
@ -2013,9 +2013,9 @@ Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) {
|
|||
&& (this.options.left == null
|
||||
|| this.options.right == null)) {
|
||||
if (this.options.left == null && this.options.right != null) {
|
||||
xi_ = xl - w - (this.border ? 2 : 0) - this.padding * 2;
|
||||
xi = xl - w - (this.border ? 2 : 0) - this.padding * 2;
|
||||
} else {
|
||||
xl = xi_ + w + (this.border ? 2 : 0) + this.padding * 2;
|
||||
xl = xi + w + (this.border ? 2 : 0) + this.padding * 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2024,40 +2024,40 @@ Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) {
|
|||
|| this.options.bottom == null)
|
||||
&& this.childBase == null) {
|
||||
if (this.options.top == null && this.options.bottom != null) {
|
||||
yi_ = yl - h - (this.border ? 2 : 0) - this.padding * 2;
|
||||
yi = yl - h - (this.border ? 2 : 0) - this.padding * 2;
|
||||
} else {
|
||||
yl = yi_ + h + (this.border ? 2 : 0) + this.padding * 2;
|
||||
yl = yi + h + (this.border ? 2 : 0) + this.padding * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Recenter shrunken elements.
|
||||
if (xl < xll && this.options.left === 'center') {
|
||||
xll = (xll - xl) / 2 | 0;
|
||||
xi_ += xll;
|
||||
xi += xll;
|
||||
xl += xll;
|
||||
}
|
||||
|
||||
if (yl < yll && this.options.top === 'center') {
|
||||
yll = (yll - yl) / 2 | 0;
|
||||
yi_ += yll;
|
||||
yi += yll;
|
||||
yl += yll;
|
||||
}
|
||||
|
||||
return { xi: xi_, xl: xl, yi: yi_, yl: yl };
|
||||
return { xi: xi, xl: xl, yi: yi, yl: yl };
|
||||
};
|
||||
|
||||
Box.prototype._getShrink = function(xi_, xl, yi_, yl, content) {
|
||||
var shrinkBox = this._getShrinkBox(xi_, xl, yi_, yl)
|
||||
, shrinkContent = this._getShrinkContent(xi_, xl, yi_, yl, content);
|
||||
Box.prototype._getShrink = function(xi, xl, yi, yl, content) {
|
||||
var shrinkBox = this._getShrinkBox(xi, xl, yi, yl)
|
||||
, shrinkContent = this._getShrinkContent(xi, xl, yi, yl, content);
|
||||
|
||||
if (this.options.left == null && this.options.right != null) {
|
||||
xi_ = Math.min(shrinkBox.xi, shrinkContent.xi);
|
||||
xi = Math.min(shrinkBox.xi, shrinkContent.xi);
|
||||
} else {
|
||||
xl = Math.max(shrinkBox.xl, shrinkContent.xl);
|
||||
}
|
||||
|
||||
if (this.options.top == null && this.options.bottom != null) {
|
||||
yi_ = Math.min(shrinkBox.yi, shrinkContent.yi);
|
||||
yi = Math.min(shrinkBox.yi, shrinkContent.yi);
|
||||
} else {
|
||||
yl = Math.max(shrinkBox.yl, shrinkContent.yl);
|
||||
}
|
||||
|
@ -2065,18 +2065,18 @@ Box.prototype._getShrink = function(xi_, xl, yi_, yl, content) {
|
|||
// Add padding if we're shrinking.
|
||||
if (this.padding) {
|
||||
if (this.options.left == null && this.options.right != null) {
|
||||
if (this.options.width == null) xi_ -= this.padding * 2;
|
||||
if (this.options.width == null) xi -= this.padding * 2;
|
||||
} else {
|
||||
if (this.options.width == null) xl += this.padding * 2;
|
||||
}
|
||||
if (this.options.top == null && this.options.bottom != null) {
|
||||
if (this.options.height == null) yi_ -= this.padding * 2;
|
||||
if (this.options.height == null) yi -= this.padding * 2;
|
||||
} else {
|
||||
if (this.options.height == null) yl += this.padding * 2;
|
||||
}
|
||||
}
|
||||
|
||||
return { xi: xi_, xl: xl, yi: yi_, yl: yl };
|
||||
return { xi: xi, xl: xl, yi: yi, yl: yl };
|
||||
};
|
||||
|
||||
// Here be dragons.
|
||||
|
@ -2089,11 +2089,11 @@ Box.prototype.render = function(stop) {
|
|||
this.parseContent();
|
||||
|
||||
var lines = this.screen.lines
|
||||
, xi_ = this.left
|
||||
, xi
|
||||
, xi = this.left
|
||||
, x
|
||||
, xl = this.screen.cols - this.right
|
||||
, yi_ = this.top
|
||||
, yi
|
||||
, yi = this.top
|
||||
, y
|
||||
, yl = this.screen.rows - this.bottom
|
||||
, cell
|
||||
, attr
|
||||
|
@ -2111,11 +2111,11 @@ Box.prototype.render = function(stop) {
|
|||
, cci;
|
||||
|
||||
if (this.position.width) {
|
||||
xl = xi_ + this.width;
|
||||
xl = xi + this.width;
|
||||
}
|
||||
|
||||
if (this.position.height) {
|
||||
yl = yi_ + this.height;
|
||||
yl = yi + this.height;
|
||||
}
|
||||
|
||||
// Check to make sure we're visible and inside of the visible scroll area.
|
||||
|
@ -2123,7 +2123,7 @@ Box.prototype.render = function(stop) {
|
|||
rtop = this.rtop - (this.parent.border ? 1 : 0);
|
||||
visible = this.parent.height - (this.parent.border ? 2 : 0);
|
||||
|
||||
yi_ -= this.parent.childBase;
|
||||
yi -= this.parent.childBase;
|
||||
yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0));
|
||||
|
||||
if (rtop - this.parent.childBase < 0) {
|
||||
|
@ -2140,17 +2140,17 @@ Box.prototype.render = function(stop) {
|
|||
// TODO: Check for 'center', recalculate yi, and xi. Better
|
||||
// yet, simply move this check into this.left/width/etc.
|
||||
if (this.shrink) {
|
||||
ret = this._getShrink(xi_, xl, yi_, yl, content);
|
||||
xi_ = ret.xi, xl = ret.xl, yi_ = ret.yi, yl = ret.yl;
|
||||
ret = this._getShrink(xi, xl, yi, yl, content);
|
||||
xi = ret.xi, xl = ret.xl, yi = ret.yi, yl = ret.yl;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Calculate whether we moved/resized by checking the previous _lastPos.
|
||||
// Maybe clear based on that. Possibly emit events here.
|
||||
ret = {
|
||||
xi: xi_,
|
||||
xi: xi,
|
||||
xl: xl,
|
||||
yi: yi_,
|
||||
yi: yi,
|
||||
yl: yl
|
||||
};
|
||||
|
||||
|
@ -2178,20 +2178,20 @@ Box.prototype.render = function(stop) {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.border) yi_++, yl--, xi_++, xl--;
|
||||
if (this.border) yi++, yl--, xi++, xl--;
|
||||
|
||||
if (this.padding || this.options.valign) {
|
||||
this.screen.fillRegion(dattr, ' ', xi_, xl, yi_, yl);
|
||||
this.screen.fillRegion(dattr, ' ', xi, xl, yi, yl);
|
||||
}
|
||||
|
||||
if (this.padding) {
|
||||
yi_ += this.padding, yl -= this.padding;
|
||||
xi_ += this.padding, xl -= this.padding;
|
||||
yi += this.padding, yl -= this.padding;
|
||||
xi += this.padding, xl -= this.padding;
|
||||
}
|
||||
|
||||
if (this.options.valign === 'middle' || this.options.valign === 'bottom') {
|
||||
//visible = (yl - yi_) - (this.border ? 2 : 0) - this.padding;
|
||||
visible = yl - yi_;
|
||||
//visible = (yl - yi) - (this.border ? 2 : 0) - this.padding;
|
||||
visible = yl - yi;
|
||||
if (this._clines.length < visible) {
|
||||
if (this.options.valign === 'middle') {
|
||||
visible = visible / 2 | 0;
|
||||
|
@ -2199,15 +2199,15 @@ Box.prototype.render = function(stop) {
|
|||
} else if (this.options.valign === 'bottom') {
|
||||
visible -= this._clines.length;
|
||||
}
|
||||
yi_ += visible;
|
||||
yi += visible;
|
||||
}
|
||||
}
|
||||
|
||||
outer:
|
||||
for (yi = yi_; yi < yl; yi++) {
|
||||
if (!lines[yi]) break;
|
||||
for (xi = xi_; xi < xl; xi++) {
|
||||
cell = lines[yi][xi];
|
||||
for (y = yi; y < yl; y++) {
|
||||
if (!lines[y]) break;
|
||||
for (x = xi; x < xl; x++) {
|
||||
cell = lines[y][x];
|
||||
if (!cell) break;
|
||||
|
||||
ch = content[ci++] || ' ';
|
||||
|
@ -2230,20 +2230,20 @@ outer:
|
|||
// If we're on the first cell and we find a newline and the last cell
|
||||
// of the last line was not a newline, let's just treat this like the
|
||||
// newline was already "counted".
|
||||
if (xi === xi_ && yi !== yi_ && content[ci-2] !== '\n') {
|
||||
xi--;
|
||||
if (x === xi && y !== yi && content[ci-2] !== '\n') {
|
||||
x--;
|
||||
continue;
|
||||
}
|
||||
// this.screen.fillRegion(attr, ' ', xi, xl, yi, yi + 1);
|
||||
// this.screen.fillRegion(attr, ' ', x, xl, y, y + 1);
|
||||
// continue outer;
|
||||
ch = ' ';
|
||||
for (; xi < xl; xi++) {
|
||||
cell = lines[yi][xi];
|
||||
for (; x < xl; x++) {
|
||||
cell = lines[y][x];
|
||||
if (!cell) break;
|
||||
if (attr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi][0] = attr;
|
||||
lines[yi][xi][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][x][0] = attr;
|
||||
lines[y][x][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -2251,26 +2251,26 @@ outer:
|
|||
// if (ch < ' ') ch = ' ';
|
||||
|
||||
if (attr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi][0] = attr;
|
||||
lines[yi][xi][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][x][0] = attr;
|
||||
lines[y][x][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h = this.items ? this.items.length : this._clines.length;
|
||||
if (this.scrollbar && (yl - yi_) < h) {
|
||||
xi = xl - 1;
|
||||
if (this.scrollbar.ignoreBorder && this.border) xi++;
|
||||
if (this.scrollbar && (yl - yi) < h) {
|
||||
x = xl - 1;
|
||||
if (this.scrollbar.ignoreBorder && this.border) x++;
|
||||
if (this.selected == null) {
|
||||
// TODO: Fix this - doesn't work with lists (and possibly scrollabletext).
|
||||
yi = h - (yl - yi_) - (this.border ? 2 : 0) - this.padding * 2;
|
||||
yi = yi_ + (((yl - yi_) * (this.childBase / yi)) | 0);
|
||||
y = h - (yl - yi) - (this.border ? 2 : 0) - this.padding * 2;
|
||||
y = yi + (((yl - yi) * (this.childBase / y)) | 0);
|
||||
} else {
|
||||
yi = this.selected / h;
|
||||
yi = yi_ + ((yl - yi_) * yi | 0);
|
||||
y = this.selected / h;
|
||||
y = yi + ((yl - yi) * y | 0);
|
||||
}
|
||||
cell = lines[yi] && lines[yi][xi];
|
||||
cell = lines[y] && lines[y][x];
|
||||
if (cell) {
|
||||
ch = this.scrollbar.ch || ' ';
|
||||
//attr = this.sattr(this.style,
|
||||
|
@ -2280,20 +2280,20 @@ outer:
|
|||
this.style.scrollbar.fg || this.style.fg,
|
||||
this.style.scrollbar.bg || this.style.bg);
|
||||
if (attr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi][0] = attr;
|
||||
lines[yi][xi][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][x][0] = attr;
|
||||
lines[y][x][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This seems redundant, but we need to draw the
|
||||
// border second because of the `shrink` option.
|
||||
if (this.border) yi_--, yl++, xi_--, xl++;
|
||||
if (this.border) yi--, yl++, xi--, xl++;
|
||||
|
||||
if (this.padding) {
|
||||
yi_ -= this.padding, yl += this.padding;
|
||||
xi_ -= this.padding, xl += this.padding;
|
||||
yi -= this.padding, yl += this.padding;
|
||||
xi -= this.padding, xl += this.padding;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2302,89 +2302,89 @@ outer:
|
|||
// dattr = (dattr & ~0x1ff) | colors.convert('green');
|
||||
// top
|
||||
this.screen.fillRegion(dattr, ' ',
|
||||
xi_ + (this.border ? 1 : 0),
|
||||
xi + (this.border ? 1 : 0),
|
||||
xl - (this.border ? 1 : 0),
|
||||
yi_ + (this.border ? 1 : 0),
|
||||
yi_ + 0 + (this.border ? 1 : 0) + this.padding);
|
||||
yi + (this.border ? 1 : 0),
|
||||
yi + 0 + (this.border ? 1 : 0) + this.padding);
|
||||
// bottom
|
||||
this.screen.fillRegion(dattr, ' ',
|
||||
xi_ + (this.border ? 1 : 0),
|
||||
xi + (this.border ? 1 : 0),
|
||||
xl - (this.border ? 1 : 0),
|
||||
yl - 0 - (this.border ? 1 : 0) - this.padding,
|
||||
yl - (this.border ? 1 : 0));
|
||||
// left
|
||||
this.screen.fillRegion(dattr, ' ',
|
||||
xi_ + (this.border ? 1 : 0),
|
||||
xi_ + 0 + (this.border ? 1 : 0) + this.padding,
|
||||
yi_ + (this.border ? 1 : 0),
|
||||
xi + (this.border ? 1 : 0),
|
||||
xi + 0 + (this.border ? 1 : 0) + this.padding,
|
||||
yi + (this.border ? 1 : 0),
|
||||
yl - (this.border ? 1 : 0));
|
||||
// right
|
||||
this.screen.fillRegion(dattr, ' ',
|
||||
xl - 0 - (this.border ? 1 : 0) - this.padding,
|
||||
xl - (this.border ? 1 : 0),
|
||||
yi_ + (this.border ? 1 : 0),
|
||||
yi + (this.border ? 1 : 0),
|
||||
yl - (this.border ? 1 : 0));
|
||||
}
|
||||
*/
|
||||
|
||||
if (this.border) {
|
||||
yi = yi_;
|
||||
for (xi = xi_; xi < xl; xi++) {
|
||||
if (!lines[yi]) break;
|
||||
y = yi;
|
||||
for (x = xi; x < xl; x++) {
|
||||
if (!lines[y]) break;
|
||||
if (this.border.type === 'line') {
|
||||
if (xi === xi_) ch = '┌';
|
||||
else if (xi === xl - 1) ch = '┐';
|
||||
if (x === xi) ch = '┌';
|
||||
else if (x === xl - 1) ch = '┐';
|
||||
else ch = '─';
|
||||
} else if (this.border.type === 'bg') {
|
||||
ch = this.border.ch;
|
||||
}
|
||||
cell = lines[yi][xi];
|
||||
cell = lines[y][x];
|
||||
if (!cell) break;
|
||||
if (battr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi][0] = battr;
|
||||
lines[yi][xi][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][x][0] = battr;
|
||||
lines[y][x][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
yi = yi_ + 1;
|
||||
for (; yi < yl; yi++) {
|
||||
if (!lines[yi]) break;
|
||||
y = yi + 1;
|
||||
for (; y < yl; y++) {
|
||||
if (!lines[y]) break;
|
||||
if (this.border.type === 'line') {
|
||||
ch = '│';
|
||||
} else if (this.border.type === 'bg') {
|
||||
ch = this.border.ch;
|
||||
}
|
||||
cell = lines[yi][xi_];
|
||||
cell = lines[y][xi];
|
||||
if (!cell) break;
|
||||
if (battr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi_][0] = battr;
|
||||
lines[yi][xi_][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][xi][0] = battr;
|
||||
lines[y][xi][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
cell = lines[yi][xl - 1];
|
||||
cell = lines[y][xl - 1];
|
||||
if (!cell) break;
|
||||
if (battr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xl - 1][0] = battr;
|
||||
lines[yi][xl - 1][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][xl - 1][0] = battr;
|
||||
lines[y][xl - 1][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
yi = yl - 1;
|
||||
for (xi = xi_; xi < xl; xi++) {
|
||||
if (!lines[yi]) break;
|
||||
y = yl - 1;
|
||||
for (x = xi; x < xl; x++) {
|
||||
if (!lines[y]) break;
|
||||
if (this.border.type === 'line') {
|
||||
if (xi === xi_) ch = '└';
|
||||
else if (xi === xl - 1) ch = '┘';
|
||||
if (x === xi) ch = '└';
|
||||
else if (x === xl - 1) ch = '┘';
|
||||
else ch = '─';
|
||||
} else if (this.border.type === 'bg') {
|
||||
ch = this.border.ch;
|
||||
}
|
||||
cell = lines[yi][xi];
|
||||
cell = lines[y][x];
|
||||
if (!cell) break;
|
||||
if (battr !== cell[0] || ch !== cell[1]) {
|
||||
lines[yi][xi][0] = battr;
|
||||
lines[yi][xi][1] = ch;
|
||||
lines[yi].dirty = true;
|
||||
lines[y][x][0] = battr;
|
||||
lines[y][x][1] = ch;
|
||||
lines[y].dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue