colors, line, and mouses fixes.

This commit is contained in:
Christopher Jeffrey 2013-07-14 08:05:42 -05:00
parent 965af859b0
commit 0c6695d236
1 changed files with 32 additions and 32 deletions

View File

@ -412,8 +412,8 @@ Screen.prototype._listenMouse = function(el) {
width = ret.xl - ret.xi;
height = ret.yl - ret.yi;
if (data.x > left && data.x <= left + width
&& data.y > top && data.y <= top + height) {
if (data.x >= left && data.x < left + width
&& data.y >= top && data.y < top + height) {
el.emit('mouse', data);
self.emit('element mouse', el, data);
if (data.action === 'mouseup') {
@ -1048,19 +1048,6 @@ Screen.prototype.setEffects = function(el, fel, over, out, effects, temp) {
el = function() { return _el; };
}
Object.keys(effects).forEach(function(key) {
var val = effects[key];
if (typeof val === 'string') {
effects[key] = val;
} else if (val && typeof val === 'object' && !Array.isArray(val)) {
// TODO: Remove this now that colors are handled lazily.
Object.keys(effects[key]).forEach(function(k) {
var v = effects[key][k];
effects[key][k] = v;
});
}
});
fel.on(over, function() {
Object.keys(effects).forEach(function(key) {
var val = effects[key];
@ -1125,8 +1112,8 @@ function Element(options) {
// this.position.padding = options.padding || 0;
// this.position.margin = options.margin || 0;
this.fg = options.fg;
this.bg = options.bg;
this.fg = cens(options.fg);
this.bg = cens(options.bg);
this.bold = options.bold;
this.underline = options.underline;
this.blink = options.blink;
@ -1142,8 +1129,8 @@ function Element(options) {
this.border = options.border;
if (this.border) {
this.border.type = this.border.type || 'bg';
this.border.fg = this.border.fg;
this.border.bg = this.border.bg;
this.border.fg = cens(this.border.fg);
this.border.bg = cens(this.border.bg);
this.border.ch = this.border.ch || ' ';
}
@ -2048,6 +2035,8 @@ Text.prototype.__proto__ = Box.prototype;
*/
function Line(options) {
var self = this;
if (!(this instanceof Line)) {
return new Line(options);
}
@ -2061,17 +2050,22 @@ function Line(options) {
options.height = 1;
}
this.ch = !options.type || options.type === 'ascii'
? orientation === 'horizontal' ? '─' : '│'
: options.ch || ' ';
options.border = {
type: 'bg',
bg: options.bg,
fg: options.fg,
ch: !options.type || options.type === 'ascii'
? orientation === 'horizontal' ? '─' : '│'
: options.ch || ' '
get fg() { return self.fg; },
get bg() { return self.bg; },
get ch() { return self.ch; },
set fg(c) { self.fg = c; },
set bg(c) { self.bg = c; },
set ch(c) { self.ch = c; }
};
delete options.bg;
delete options.fg;
delete options.bg;
delete options.ch;
Box.call(this, options);
@ -2100,8 +2094,8 @@ function ScrollableBox(options) {
this.scrollbar = options.scrollbar;
if (this.scrollbar) {
this.scrollbar.fg = this.scrollbar.fg;
this.scrollbar.bg = this.scrollbar.bg;
this.scrollbar.fg = cens(this.scrollbar.fg);
this.scrollbar.bg = cens(this.scrollbar.bg);
this.scrollbar.ch = this.scrollbar.ch || ' ';
}
}
@ -2165,8 +2159,8 @@ function List(options) {
this.ritems = [];
this.selected = 0;
this.selectedBg = options.selectedBg;
this.selectedFg = options.selectedFg;
this.selectedBg = cens(options.selectedBg);
this.selectedFg = cens(options.selectedFg);
this.selectedBold = options.selectedBold;
this.selectedUnderline = options.selectedUnderline;
this.selectedBlink = options.selectedBlink;
@ -2933,7 +2927,7 @@ Button.prototype.press = function() {
this.emit('press');
if (this.border && this.options.defaultEffects) {
var color = this.border.fg;
this.border.fg = 2;
this.border.fg = 'green';
this.screen.render();
setTimeout(function() {
self.border.fg = color;
@ -2956,8 +2950,8 @@ function ProgressBar(options) {
this.filled = +this.filled.slice(0, -1);
}
this.ch = options.ch || ' ';
this.barFg = options.barFg;
this.barBg = options.barBg;
this.barFg = cens(options.barFg);
this.barBg = cens(options.barBg);
this.orientation = options.orientation || 'horizontal';
}
@ -4059,6 +4053,12 @@ function sattr(obj, fg, bg) {
| colors.convert(bg);
}
function cens(color) {
return color != null
? color
: -1;
}
/**
* Expose
*/