improve mouse events by sorting by index.

This commit is contained in:
Christopher Jeffrey 2013-07-12 08:58:25 -05:00
parent 7414922a76
commit a801b47e28
1 changed files with 39 additions and 4 deletions

View File

@ -169,6 +169,21 @@ Node.prototype.emitDescendants = function() {
})(this);
};
Node.prototype.emitAncestors = function() {
var args = Array.prototype.slice(arguments)
, el = this
, iter;
if (typeof args[args.length-1] === 'function') {
iter = args.pop();
}
do {
if (iter) iter(el);
el.emit.apply(el, args);
} while (el = el.parent);
};
Node.prototype.hasDescendant = function(target) {
return (function find(el) {
for (var i = 0; i < el.children.length; i++) {
@ -347,7 +362,8 @@ Screen.prototype._listenMouse = function(el) {
this.program.on('mouse', function(data) {
if (self.lockKeys) return;
var i = 0
var clickable = hsort(self.clickable)
, i = 0
, left
, top
, width
@ -356,8 +372,8 @@ Screen.prototype._listenMouse = function(el) {
, set
, ret;
for (; i < self.clickable.length; i++) {
el = self.clickable[i];
for (; i < clickable.length; i++) {
el = clickable[i];
if (!el.visible) continue;
// Get the true coordinates.
@ -391,7 +407,20 @@ Screen.prototype._listenMouse = function(el) {
set = true;
}
el.emit(data.action, data);
self.emit('element ' + data.action, data);
self.emit('element ' + data.action, el, data);
// XXX Temporary workaround for List wheel events.
// Make sure they get propogated to the list instead of the list item.
if ((data.action === 'wheeldown' || data.action === 'wheelup')
&& el.listeners(data.action).length === 0
&& el.parent.listeners(data.action).length > 0) {
el.parent.emit(data.action, data);
self.emit('element ' + data.action, el.parent, data);
}
// Seems to work better without this if statement:
// if (data.action !== 'mousemove')
break;
}
}
@ -3324,6 +3353,12 @@ function asort(obj) {
});
}
function hsort(obj) {
return obj.sort(function(a, b) {
return b.index - a.index;
});
}
var colors = {
default: -1,
bg: -1,