allow 0-width 0-height elements. see slap-editor/slap#153.

This commit is contained in:
Christopher Jeffrey 2015-04-27 00:14:02 -07:00
parent 3f8ed04898
commit f37a619cc6
2 changed files with 43 additions and 4 deletions

View File

@ -2821,6 +2821,8 @@ Element.prototype.__defineGetter__('visible', function() {
do {
if (el.detached) return false;
if (el.hidden) return false;
// if (!el.lpos) return false;
// if (el.position.width === 0 || el.position.height === 0) return false;
} while (el = el.parent);
return true;
});
@ -3154,7 +3156,7 @@ Element.prototype._getPos = function() {
Element.prototype._getWidth = function(get) {
var parent = get ? this.parent._getPos() : this.parent
, width = this.position.width || 0
, width = this.position.width
, left
, expr;
@ -3174,7 +3176,7 @@ Element.prototype._getWidth = function(get) {
// the content width, and the content width is initially
// decided by the width the element, so it needs to be
// calculated here.
if (!width) {
if (width == null) {
left = this.position.left || 0;
if (typeof left === 'string') {
if (left === 'center') left = '50%';
@ -3203,7 +3205,7 @@ Element.prototype.__defineGetter__('width', function() {
Element.prototype._getHeight = function(get) {
var parent = get ? this.parent._getPos() : this.parent
, height = this.position.height || 0
, height = this.position.height
, top
, expr;
@ -3223,7 +3225,7 @@ Element.prototype._getHeight = function(get) {
// the content width, and the content width is initially
// decided by the width the element, so it needs to be
// calculated here.
if (!height) {
if (height == null) {
top = this.position.top || 0;
if (typeof top === 'string') {
if (top === 'center') top = '50%';
@ -3950,6 +3952,16 @@ Element.prototype.render = function() {
return;
}
if (coords.xl - coords.xi <= 0) {
coords.xl = Math.max(coords.xl, coords.xi);
return;
}
if (coords.yl - coords.yi <= 0) {
coords.yl = Math.max(coords.yl, coords.yi);
return;
}
var lines = this.screen.lines
, xi = coords.xi
, xl = coords.xl

View File

@ -175,6 +175,33 @@ var stext = blessed.scrollabletext({
}
});
setTimeout(function() {
stext.width = 0;
screen.render();
setTimeout(function() {
stext.width = '50%';
screen.render();
setTimeout(function() {
stext.height = 0;
screen.render();
setTimeout(function() {
stext.height = 6;
screen.render();
setTimeout(function() {
stext.width = 0;
stext.height = 0;
screen.render();
setTimeout(function() {
stext.width = '50%';
stext.height = 6;
screen.render();
}, 1000);
}, 1000);
}, 1000);
}, 1000);
}, 1000);
}, 1000);
screen.append(stext);
stext.on('keypress', function(ch, key) {
if (key.name === 'up' || key.name === 'k') {