fix text alignment.

This commit is contained in:
Christopher Jeffrey 2013-06-13 04:42:08 -05:00
parent 831425d5af
commit fccb1627a6
2 changed files with 16 additions and 9 deletions

View File

@ -79,7 +79,11 @@ var score = new blessed.Box({
top: 0,
left: 4,
height: 3,
width: 20,
width: 26,
border: {
type: 'ascii'
},
align: 'center',
bold: true
});
@ -109,6 +113,7 @@ var text = new blessed.Box({
left: 1,
right: 1,
height: 1,
align: 'center',
content: 'Waiting for players to connect...'
});

View File

@ -1022,16 +1022,17 @@ Box.prototype.render = function(stop) {
}
if (this.align === 'center' || this.align === 'right') {
var width = this.width - (this.border ? 2 : 0);
//var width = this.width - (this.border ? 2 : 0);
var width = this.width;
var ncontent = content.split('\n')[0].replace(/\x1b\[[^m]*m/g, '');
if (ncontent.length < width) {
var s = width - 1 - ncontent.length - 1;
var s = width - ncontent.length;
if (this.align === 'center') {
//xi_ += s / 2 | 0;
content = Array(s / 2 | 0).join(' ') + content;
content = Array(((s / 2 | 0) - (this.border ? 1 : 0)) + 1).join(' ') + content;
} else {
//xi_ += s;
content = Array(s).join(' ') + content;
content = Array((s - (this.border ? 2 : 0)) + 1).join(' ') + content;
}
}
}
@ -1208,16 +1209,17 @@ Text.prototype.render = function(stop) {
}
if (this.align === 'center' || this.align === 'right') {
var width = this.width - (this.border ? 2 : 0);
//var width = this.width - (this.border ? 2 : 0);
var width = this.width;
var ncontent = content.split('\n')[0].replace(/\x1b\[[^m]*m/g, '');
if (ncontent.length < width) {
var s = width - 1 - ncontent.length - 1;
var s = width - ncontent.length;
if (this.align === 'center') {
//xi_ += s / 2 | 0;
content = Array(s / 2 | 0).join(' ') + content;
content = Array(((s / 2 | 0) - (this.border ? 1 : 0)) + 1).join(' ') + content;
} else {
//xi_ += s;
content = Array(s).join(' ') + content;
content = Array((s - (this.border ? 2 : 0)) + 1).join(' ') + content;
}
}
}