fix mouse events for overlapping elements.

This commit is contained in:
Christopher Jeffrey 2013-06-06 10:27:19 -05:00
parent 0477f38a2d
commit 7fb6b2cc3b
2 changed files with 32 additions and 23 deletions

View File

@ -139,8 +139,8 @@ Screen.prototype._listenMouse = function(el, hover) {
left = el.left + (el.border ? 1 : 0);
top = el.top + (el.border ? 1 : 0);
if (el.parent.childBase != null) top -= el.parent.childBase;
if (data.x >= left && data.x <= left + el.width
&& data.y >= top && data.y <= top + el.height) {
if (data.x > left && data.x <= left + el.width
&& data.y > top && data.y <= top + el.height) {
el.emit('mouse', data);
if (data.action === 'mouseup') {
el.emit('click', data);
@ -148,7 +148,6 @@ Screen.prototype._listenMouse = function(el, hover) {
el.emit('hover', data);
}
el.emit(data.action, data);
break;
}
}
self.emit('mouse', data);
@ -161,6 +160,10 @@ Screen.prototype._listenKeys = function(el) {
if (el) {
this.input.push(el);
//if (this.mouse)
//el.on('click', function() {
// el.focus();
//});
}
if (this._listenedKeys) return;
@ -1020,6 +1023,18 @@ function List(options) {
if (this.children.length) {
this.select(0);
}
if (this.mouse) {
self.on('wheeldown', function(data) {
self.select(self.selected + 2);
self.screen.render();
});
self.on('wheelup', function(data) {
self.select(self.selected - 2);
self.screen.render();
});
}
}
List.prototype.__proto__ = ScrollableBox.prototype;
@ -1043,26 +1058,12 @@ List.prototype.add = function(item) {
this.append(item);
this.items.push(item);
if (!this.mouse) return;
item.on('click', function(data) {
self.select(item);
self.screen.render();
});
// Temporary workaround:
// We cannot bind to clickable events on the list because the parent will
// receive *all* clickable events in that particular area of the screen.
// Possibly fix in the future by emitting events through tree traversal as
// well as bubbling events.
item.on('wheeldown', function(data) {
self.select(self.selected + 2);
self.screen.render();
});
item.on('wheelup', function(data) {
self.select(self.selected - 2);
self.screen.render();
});
if (this.mouse) {
item.on('click', function(data) {
self.select(item);
self.screen.render();
});
}
};
List.prototype._remove = List.prototype.remove;

View File

@ -114,6 +114,10 @@ list.on('keypress', function(ch, key) {
}
});
list.on('click', function() {
list.focus();
});
var progress = new blessed.ProgressBar({
screen: screen,
parent: screen,
@ -161,6 +165,10 @@ var stext = new blessed.ScrollableText({
bottom: 0
});
stext.on('click', function() {
stext.focus();
});
screen.append(stext);
stext.on('keypress', function(ch, key) {
if (key.name === 'up') {