parent
5ec1f2808c
commit
dbacb6f8ed
88
lib/high.js
88
lib/high.js
|
@ -245,12 +245,7 @@ Screen.prototype.draw = function(start, end) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Element(options) {
|
function Element(options) {
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
Node.call(this, options);
|
Node.call(this, options);
|
||||||
|
|
||||||
this.options = options;
|
|
||||||
|
|
||||||
this.screen = options.screen;
|
this.screen = options.screen;
|
||||||
this.parent = options.parent || (function(){throw Error('No parent.')})();
|
this.parent = options.parent || (function(){throw Error('No parent.')})();
|
||||||
this.position = {
|
this.position = {
|
||||||
|
@ -303,26 +298,13 @@ Element.prototype.__defineGetter__('left', function() {
|
||||||
left = (this.parent.width - len) * left | 0;
|
left = (this.parent.width - len) * left | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
if (opt.left == null && !left && opt.right != null && this.position.right) {
|
|
||||||
left = this.width - this.position.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (this.parent.left || 0) + left;
|
return (this.parent.left || 0) + left;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('left', function(val) {
|
|
||||||
return this.position.left = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('right', function() {
|
Element.prototype.__defineGetter__('right', function() {
|
||||||
return (this.parent.right || 0) + this.position.right;
|
return (this.parent.right || 0) + this.position.right;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('right', function(val) {
|
|
||||||
return this.position.right = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('top', function() {
|
Element.prototype.__defineGetter__('top', function() {
|
||||||
var top = this.position.top;
|
var top = this.position.top;
|
||||||
|
|
||||||
|
@ -333,31 +315,13 @@ Element.prototype.__defineGetter__('top', function() {
|
||||||
top = (this.parent.height - len) * top | 0;
|
top = (this.parent.height - len) * top | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
if (opt.top == null && !top && opt.bottom != null && this.position.bottom) {
|
|
||||||
top = this.height - this.position.bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.parent.childBase != null && ~this.parent.items.indexOf(this)) {
|
|
||||||
top += this.parent.items.indexOf(this);
|
|
||||||
top -= this.parent.childBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (this.parent.top || 0) + top;
|
return (this.parent.top || 0) + top;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('top', function() {
|
|
||||||
return this.position.top = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('bottom', function() {
|
Element.prototype.__defineGetter__('bottom', function() {
|
||||||
return (this.parent.bottom || 0) + this.position.bottom;
|
return (this.parent.bottom || 0) + this.position.bottom;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('bottom', function(val) {
|
|
||||||
return this.position.bottom = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('width', function() {
|
Element.prototype.__defineGetter__('width', function() {
|
||||||
var width = this.position.width;
|
var width = this.position.width;
|
||||||
if (typeof width === 'string') {
|
if (typeof width === 'string') {
|
||||||
|
@ -378,10 +342,6 @@ Element.prototype.__defineGetter__('width', function() {
|
||||||
return width;
|
return width;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('width', function(val) {
|
|
||||||
return this.position.width = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('height', function() {
|
Element.prototype.__defineGetter__('height', function() {
|
||||||
var height = this.position.height;
|
var height = this.position.height;
|
||||||
if (typeof height === 'string') {
|
if (typeof height === 'string') {
|
||||||
|
@ -402,10 +362,6 @@ Element.prototype.__defineGetter__('height', function() {
|
||||||
return height;
|
return height;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('height', function(val) {
|
|
||||||
return this.position.height = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('rleft', function() {
|
Element.prototype.__defineGetter__('rleft', function() {
|
||||||
var left = this.position.left;
|
var left = this.position.left;
|
||||||
|
|
||||||
|
@ -416,26 +372,13 @@ Element.prototype.__defineGetter__('rleft', function() {
|
||||||
left = len * left | 0;
|
left = len * left | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
if (opt.left == null && !left && opt.right != null && this.position.right) {
|
|
||||||
left = this.width - this.position.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
return left;
|
return left;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('rleft', function(val) {
|
|
||||||
return this.position.left = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('rright', function() {
|
Element.prototype.__defineGetter__('rright', function() {
|
||||||
return this.position.right;
|
return this.position.right;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('rright', function() {
|
|
||||||
return this.position.right = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('rtop', function() {
|
Element.prototype.__defineGetter__('rtop', function() {
|
||||||
var top = this.position.top;
|
var top = this.position.top;
|
||||||
|
|
||||||
|
@ -446,31 +389,13 @@ Element.prototype.__defineGetter__('rtop', function() {
|
||||||
top = len * top | 0;
|
top = len * top | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt = this.options;
|
|
||||||
if (opt.top == null && !top && opt.bottom != null && this.position.bottom) {
|
|
||||||
top = this.height - this.position.bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.parent.childBase != null && ~this.parent.items.indexOf(this)) {
|
|
||||||
top += this.parent.items.indexOf(this);
|
|
||||||
top -= this.parent.childBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
return top;
|
return top;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('rtop', function() {
|
|
||||||
return this.position.top = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
Element.prototype.__defineGetter__('rbottom', function() {
|
Element.prototype.__defineGetter__('rbottom', function() {
|
||||||
return this.position.bottom;
|
return this.position.bottom;
|
||||||
});
|
});
|
||||||
|
|
||||||
Element.prototype.__defineSetter__('rbottom', function() {
|
|
||||||
return this.position.bottom = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Border Measures
|
* Border Measures
|
||||||
*/
|
*/
|
||||||
|
@ -594,7 +519,6 @@ Box.prototype.render = function() {
|
||||||
function Text(options) {
|
function Text(options) {
|
||||||
Element.call(this, options);
|
Element.call(this, options);
|
||||||
this.full = options.full;
|
this.full = options.full;
|
||||||
this.noOverflow = options.noOverflow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text.prototype.__proto__ = Element.prototype;
|
Text.prototype.__proto__ = Element.prototype;
|
||||||
|
@ -624,15 +548,16 @@ Text.prototype.render = function() {
|
||||||
xl = xi + this.parent.width - (this.parent.border ? 2 : 0) - this.rleft - this.rright;
|
xl = xi + this.parent.width - (this.parent.border ? 2 : 0) - this.rleft - this.rright;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.noOverflow) {
|
if (this.parent.childBase != null && ~this.parent.items.indexOf(this)) {
|
||||||
var rtop = this.rtop - (this.parent.border ? 1 : 0)
|
var rtop = this.rtop - (this.parent.border ? 1 : 0)
|
||||||
, visible = this.parent.height - (this.parent.border ? 2 : 0);
|
, visible = this.parent.height - (this.parent.border ? 2 : 0);
|
||||||
|
|
||||||
if (rtop < 0) {
|
yi -= this.parent.childBase;
|
||||||
|
|
||||||
|
if (rtop - this.parent.childBase < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (rtop - this.parent.childBase >= visible) {
|
||||||
if (rtop >= visible) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -711,10 +636,9 @@ List.prototype.add = function(item) {
|
||||||
fg: this.fg,
|
fg: this.fg,
|
||||||
bg: this.bg,
|
bg: this.bg,
|
||||||
content: item.content || item,
|
content: item.content || item,
|
||||||
top: 0,
|
top: this.items.length + (this.border ? 1 : 0),
|
||||||
left: (this.border ? 1 : 0) + 1,
|
left: (this.border ? 1 : 0) + 1,
|
||||||
full: true,
|
full: true,
|
||||||
noOverflow: true,
|
|
||||||
height: 1
|
height: 1
|
||||||
});
|
});
|
||||||
this.append(item);
|
this.append(item);
|
||||||
|
|
Loading…
Reference in New Issue