mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-11 03:25:45 +00:00
refactor shrink.
This commit is contained in:
parent
1ae6a19b35
commit
8e81ef015b
108
lib/widget.js
108
lib/widget.js
@ -1962,12 +1962,12 @@ Box.prototype._getShrinkBox = function(xi, xl, yi, yl) {
|
|||||||
return { xi: xi, xl: xi, yi: yi, yl: yi };
|
return { xi: xi, xl: xi, yi: yi, yl: yi };
|
||||||
}
|
}
|
||||||
|
|
||||||
var i, el, mxi = 0, mxl = 0, myi = 0, myl = 0;
|
var i, el, ret, mxi = 0, mxl = 0, myi = 0, myl = 0;
|
||||||
|
|
||||||
for (i = 0; i < this.children.length; i++) {
|
for (i = 0; i < this.children.length; i++) {
|
||||||
el = this.children[i];
|
el = this.children[i];
|
||||||
|
|
||||||
var ret = el.render(true);
|
ret = el.render(true);
|
||||||
if (!ret) continue;
|
if (!ret) continue;
|
||||||
|
|
||||||
if (ret.xi < mxi) mxi = ret.xi;
|
if (ret.xi < mxi) mxi = ret.xi;
|
||||||
@ -1976,31 +1976,25 @@ Box.prototype._getShrinkBox = function(xi, xl, yi, yl) {
|
|||||||
if (ret.yl > myl) myl = ret.yl;
|
if (ret.yl > myl) myl = ret.yl;
|
||||||
}
|
}
|
||||||
|
|
||||||
var xll = xl, yll = yl;
|
if (this.options.width == null
|
||||||
|
&& (this.options.left == null
|
||||||
if (this.options.left == null && this.options.right != null) {
|
|| this.options.right == null)) {
|
||||||
if (this.options.width == null) xi = xl - (mxl - mxi);
|
if (this.options.left == null && this.options.right != null) {
|
||||||
} else {
|
xi = xl - (mxl - mxi);
|
||||||
if (this.options.width == null) xl = mxl;
|
} else {
|
||||||
|
xl = mxl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.top == null && this.options.bottom != null) {
|
if (this.options.height == null
|
||||||
if (this.options.height == null) yi = yl - (myl - myi);
|
&& (this.options.top == null
|
||||||
} else {
|
|| this.options.bottom == null)
|
||||||
if (this.options.height == null) yl = myl;
|
&& this.childBase == null) {
|
||||||
}
|
if (this.options.top == null && this.options.bottom != null) {
|
||||||
|
yi = yl - (myl - myi);
|
||||||
// Recenter shrunken elements.
|
} else {
|
||||||
if (xl < xll && this.options.left === 'center') {
|
yl = myl;
|
||||||
xll = (xll - xl) / 2 | 0;
|
}
|
||||||
xi += xll;
|
|
||||||
xl += xll;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (yl < yll && this.options.top === 'center') {
|
|
||||||
yll = (yll - yl) / 2 | 0;
|
|
||||||
yi += yll;
|
|
||||||
yl += yll;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { xi: xi, xl: xl, yi: yi, yl: yl };
|
return { xi: xi, xl: xl, yi: yi, yl: yl };
|
||||||
@ -2009,9 +2003,7 @@ Box.prototype._getShrinkBox = function(xi, xl, yi, yl) {
|
|||||||
Box.prototype._getShrinkContent = function(xi, xl, yi, yl, content) {
|
Box.prototype._getShrinkContent = function(xi, xl, yi, yl, content) {
|
||||||
var hw = this._getShrinkSize(content)
|
var hw = this._getShrinkSize(content)
|
||||||
, h = hw.height
|
, h = hw.height
|
||||||
, w = hw.width
|
, w = hw.width;
|
||||||
, xll = xl
|
|
||||||
, yll = yl;
|
|
||||||
|
|
||||||
if (this.options.width == null
|
if (this.options.width == null
|
||||||
&& (this.options.left == null
|
&& (this.options.left == null
|
||||||
@ -2034,26 +2026,16 @@ Box.prototype._getShrinkContent = function(xi, xl, yi, yl, content) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recenter shrunken elements.
|
|
||||||
if (xl < xll && this.options.left === 'center') {
|
|
||||||
xll = (xll - xl) / 2 | 0;
|
|
||||||
xi += xll;
|
|
||||||
xl += xll;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (yl < yll && this.options.top === 'center') {
|
|
||||||
yll = (yll - yl) / 2 | 0;
|
|
||||||
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) {
|
Box.prototype._getShrink = function(xi, xl, yi, yl, content) {
|
||||||
var shrinkBox = this._getShrinkBox(xi, xl, yi, yl)
|
var shrinkBox = this._getShrinkBox(xi, xl, yi, yl)
|
||||||
, shrinkContent = this._getShrinkContent(xi, xl, yi, yl, content);
|
, shrinkContent = this._getShrinkContent(xi, xl, yi, yl, content)
|
||||||
|
, xll = xl
|
||||||
|
, yll = yl;
|
||||||
|
|
||||||
|
// Figure out which one is bigger and use it.
|
||||||
if (shrinkBox.xl - shrinkBox.xi > shrinkContent.xl - shrinkContent.xi) {
|
if (shrinkBox.xl - shrinkBox.xi > shrinkContent.xl - shrinkContent.xi) {
|
||||||
xi = shrinkBox.xi;
|
xi = shrinkBox.xi;
|
||||||
xl = shrinkBox.xl;
|
xl = shrinkBox.xl;
|
||||||
@ -2070,17 +2052,39 @@ Box.prototype._getShrink = function(xi, xl, yi, yl, content) {
|
|||||||
yl = shrinkContent.yl;
|
yl = shrinkContent.yl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add padding if we're shrinking.
|
// Recenter shrunken elements.
|
||||||
if (this.padding) {
|
if (xl < xll && this.options.left === 'center') {
|
||||||
if (this.options.left == null && this.options.right != null) {
|
xll = (xll - xl) / 2 | 0;
|
||||||
if (this.options.width == null) xi -= this.padding * 2;
|
xi += xll;
|
||||||
} else {
|
xl += xll;
|
||||||
if (this.options.width == null) xl += this.padding * 2;
|
}
|
||||||
|
|
||||||
|
if (yl < yll && this.options.top === 'center') {
|
||||||
|
yll = (yll - yl) / 2 | 0;
|
||||||
|
yi += yll;
|
||||||
|
yl += yll;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add padding, doesn't seem to be necessary.
|
||||||
|
if (0 && this.padding) {
|
||||||
|
if (this.options.width == null
|
||||||
|
&& (this.options.left == null
|
||||||
|
|| this.options.right == null)) {
|
||||||
|
if (this.options.left == null && this.options.right != null) {
|
||||||
|
xi -= this.padding * 2;
|
||||||
|
} else {
|
||||||
|
xl += this.padding * 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.options.top == null && this.options.bottom != null) {
|
if (this.options.height == null
|
||||||
if (this.options.height == null) yi -= this.padding * 2;
|
&& (this.options.top == null
|
||||||
} else {
|
|| this.options.bottom == null)
|
||||||
if (this.options.height == null) yl += this.padding * 2;
|
&& this.childBase == null) {
|
||||||
|
if (this.options.top == null && this.options.bottom != null) {
|
||||||
|
yi -= this.padding * 2;
|
||||||
|
} else {
|
||||||
|
yl += this.padding * 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user