* Lots of improvements (WIP) to file browsing

This commit is contained in:
Bryan Ashby 2016-10-12 22:07:22 -06:00
parent 67e2ff987f
commit 806e6539f4
7 changed files with 412 additions and 98 deletions

View file

@ -113,30 +113,39 @@ HorizontalMenuView.prototype.setItems = function(items) {
this.positionCacheExpired = true;
};
HorizontalMenuView.prototype.focusNext = function() {
if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0;
} else {
this.focusedItemIndex++;
}
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
this.redraw();
HorizontalMenuView.super_.prototype.focusNext.call(this);
};
HorizontalMenuView.prototype.focusPrevious = function() {
if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1;
} else {
this.focusedItemIndex--;
}
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
this.redraw();
HorizontalMenuView.super_.prototype.focusPrevious.call(this);
};
HorizontalMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
var prevFocusedItemIndex = this.focusedItemIndex;
if(this.isKeyMapped('left', key.name)) {
if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1;
} else {
this.focusedItemIndex--;
}
this.focusPrevious();
} else if(this.isKeyMapped('right', key.name)) {
if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0;
} else {
this.focusedItemIndex++;
}
}
if(prevFocusedItemIndex !== this.focusedItemIndex) {
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
// if this is changed to allow scrolling
this.redraw();
return;
this.focusNext();
}
}