allow style.hover and style.focus. no autofocus on buttons.

This commit is contained in:
Christopher Jeffrey 2013-07-17 01:37:57 -05:00
parent c805b80209
commit 70953689e2
3 changed files with 45 additions and 38 deletions

View File

@ -233,6 +233,12 @@ The base element.
},
scrollbar: {
bg: 'blue'
},
focus: {
bg: 'red'
},
hover: {
bg: 'red'
}
}
```

View File

@ -11,7 +11,8 @@
var EventEmitter = require('events').EventEmitter
, path = require('path')
, fs = require('fs')
, colors = require('./colors');
, colors = require('./colors')
, widget = exports;
/**
* Node
@ -1458,12 +1459,26 @@ function Element(options) {
self.parseContent();
});
// Legacy
if (this.options.hoverBg != null) {
this.options.hoverEffects = this.options.hoverEffects || {};
this.options.hoverEffects.bg = this.options.hoverBg;
if (options.hoverBg != null) {
options.hoverEffects = options.hoverEffects || {};
options.hoverEffects.bg = options.hoverBg;
}
if (this.style.hover) {
options.hoverEffects = this.style.hover;
//delete this.style.hover;
}
if (this.style.focus) {
options.focusEffects = this.style.focus;
//delete this.style.focus;
}
// if (options.effects) {
// if (options.effects.hover) options.hoverEffects = options.effects.hover;
// if (options.effects.focus) options.focusEffects = options.effects.focus;
// }
[['hoverEffects', 'mouseover', 'mouseout', '_htemp'],
['focusEffects', 'focus', 'blur', '_ftemp']].forEach(function(props) {
var pname = props[0], over = props[1], out = props[2], temp = props[3];
@ -3589,6 +3604,10 @@ function Button(options) {
return new Button(options);
}
if (options.autoFocus == null) {
options.autoFocus = false;
}
Input.call(this, options);
this.on('keypress', function(ch, key) {
@ -3597,18 +3616,6 @@ function Button(options) {
}
});
if (this.options.defaultEffects) {
this.on('mouseover', function() {
self.inverse = !self.options.inverse;
self.screen.render();
});
this.on('mouseout', function() {
self.inverse = self.options.inverse;
self.screen.render();
});
}
if (this.options.mouse) {
this.on('click', function() {
self.press();
@ -3623,15 +3630,6 @@ Button.prototype.type = 'button';
Button.prototype.press = function() {
var self = this;
this.emit('press');
if (this.border && this.options.defaultEffects) {
var color = this.border.fg;
this.border.fg = 'green';
this.screen.render();
setTimeout(function() {
self.border.fg = color;
self.screen.render();
}, 300);
}
};
/**
@ -4475,14 +4473,15 @@ Listbar.prototype.setItems = function(commands) {
width: len + 2,
align: 'center',
tags: true,
autoFocus: false,
hoverEffects: {
bg: 'blue'
},
focusEffects: {
bg: 'blue'
},
mouse: true
mouse: true,
style: {
hover: {
bg: 'blue'
},
focus: {
bg: 'blue'
}
}
});
self._[name] = button;
@ -4492,7 +4491,7 @@ Listbar.prototype.setItems = function(commands) {
if (cmd.callback) {
button.on('press', cmd.callback);
if (cmd.keys) {
screen.key(cmd.keys[0], cmd.callback);
screen.key(cmd.keys, cmd.callback);
}
}

View File

@ -91,11 +91,13 @@ var submit = blessed.button({
left: 30,
top: 0,
shrink: true,
bg: 'blue',
name: 'submit',
content: 'submit',
focusEffects: {
bg: 'red'
style: {
bg: 'blue',
focus: {
bg: 'red'
}
}
});