add valign. simpler way of rendering padding bg.

This commit is contained in:
Christopher Jeffrey 2013-07-16 20:19:44 -05:00
parent c8c0d1f269
commit 1561bdef7d
2 changed files with 22 additions and 1 deletions

View File

@ -2073,11 +2073,29 @@ 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);
}
if (this.padding) { if (this.padding) {
yi_ += this.padding, yl -= this.padding; yi_ += this.padding, yl -= this.padding;
xi_ += this.padding, xl -= 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_;
if (this._clines.length < visible) {
if (this.options.valign === 'middle') {
visible = visible / 2 | 0;
visible -= this._clines.length / 2 | 0;
} else if (this.options.valign === 'bottom') {
visible -= this._clines.length;
}
yi_ += visible;
}
}
outer: outer:
for (yi = yi_; yi < yl; yi++) { for (yi = yi_; yi < yl; yi++) {
if (!lines[yi]) break; if (!lines[yi]) break;
@ -2171,6 +2189,7 @@ outer:
xi_ -= this.padding, xl += this.padding; xi_ -= this.padding, xl += this.padding;
} }
/*
if (this.padding) { if (this.padding) {
// Set padding to green for debugging: // Set padding to green for debugging:
// dattr = (dattr & ~0x1ff) | colors.convert('green'); // dattr = (dattr & ~0x1ff) | colors.convert('green');
@ -2199,6 +2218,7 @@ outer:
yi_ + (this.border ? 1 : 0), yi_ + (this.border ? 1 : 0),
yl - (this.border ? 1 : 0)); yl - (this.border ? 1 : 0));
} }
*/
if (this.border) { if (this.border) {
yi = yi_; yi = yi_;

View File

@ -11,7 +11,8 @@ var box = blessed.box({
height: 5, height: 5,
top: 'center', top: 'center',
left: 0, left: 0,
content: 'line 1' content: 'line 1',
//valign: 'middle'
}); });
screen.render(); screen.render();