* More WIP on VM redesign
This commit is contained in:
parent
cdfb7ce6f2
commit
0346cbc7cb
|
@ -21,20 +21,23 @@ function VerticalMenuView(options) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// :TODO: view.setDimens() would set autoSize to false. Otherwise, we cna scale @ setItems()
|
// :TODO: view.setDimens() would set autoSize to false. Otherwise, we cna scale @ setItems()
|
||||||
// topViewIndex = top visibile item
|
// topViewIndex = top visible item
|
||||||
// itemsInView = height * (1 + itemSpacing)
|
// itemsInView = height * (1 + itemSpacing)
|
||||||
|
this.jumpVisibleToTop = function() {
|
||||||
this.updateViewable = function() {
|
this.visibleRange = {
|
||||||
var viewableItems = self.dimens.height / ((self.itemSpacing + 1) - self.itemSpacing);
|
top : 0,
|
||||||
console.log(viewableItems)
|
bottom : this.maxVisibleItems,
|
||||||
this.viewableRange = {
|
|
||||||
top : self.focusedItemIndex,
|
|
||||||
bottom : viewableItems - self.focusedItemIndex,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(this.viewableRange)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.jumpVisibleToBottom = function() {
|
||||||
|
this.visibleRange = {
|
||||||
|
top : this.items.length - this.jumpVisibleToTop,
|
||||||
|
bottom : this.items.length,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.scaleDimension = function() {
|
this.scaleDimension = function() {
|
||||||
if(this.autoScale) {
|
if(this.autoScale) {
|
||||||
this.dimens.height = (self.items.length * (self.itemSpacing + 1)) - (self.itemSpacing);
|
this.dimens.height = (self.items.length * (self.itemSpacing + 1)) - (self.itemSpacing);
|
||||||
|
@ -76,7 +79,7 @@ console.log(viewableItems)
|
||||||
this.cacheVisiblePositions = function() {
|
this.cacheVisiblePositions = function() {
|
||||||
if(self.positionCacheExpired) {
|
if(self.positionCacheExpired) {
|
||||||
var x = self.position.x;
|
var x = self.position.x;
|
||||||
for(var i = this.viewableRange.top; i < this.viewableRange.bottom; ++i) {
|
for(var i = this.visibleRange.top; i < this.visibleRange.bottom; ++i) {
|
||||||
if(i > 0) {
|
if(i > 0) {
|
||||||
x += self.itemSpacing + 1;
|
x += self.itemSpacing + 1;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +111,33 @@ console.log(viewableItems)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.changeSelection2 = function(fromIndex, toIndex) {
|
||||||
|
assert(!self.positionCacheExpired);
|
||||||
|
assert(fromIndex >= 0 && fromIndex <= self.items.length);
|
||||||
|
assert(toIndex >= 0 && toIndex <= self.items.length);
|
||||||
|
|
||||||
|
if(fromIndex === self.items.length - 1 && fromIndex > toIndex) {
|
||||||
|
console.log('jump to top')
|
||||||
|
this.redraw();
|
||||||
|
return;
|
||||||
|
} else if(0 === fromIndex && toIndex > fromIndex) {
|
||||||
|
console.log('jump to bottom')
|
||||||
|
this.redraw();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*if(fromIndex > toIndex && self.items.length === fromIndex) {
|
||||||
|
console.log('jump to top')
|
||||||
|
this.jumpVisibleToTop();
|
||||||
|
} else if(0 === fromIndex && fromIndex < toIndex) {
|
||||||
|
console.log('jump to bottom')
|
||||||
|
this.jumpVisibleToBottom();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
this.changeSelection = function(fromIndex, toIndex) {
|
this.changeSelection = function(fromIndex, toIndex) {
|
||||||
assert(!self.positionCacheExpired);
|
assert(!self.positionCacheExpired);
|
||||||
assert(fromIndex >= 0 && fromIndex <= self.items.length);
|
assert(fromIndex >= 0 && fromIndex <= self.items.length);
|
||||||
|
@ -142,10 +172,9 @@ console.log(viewableItems)
|
||||||
util.inherits(VerticalMenuView, MenuView);
|
util.inherits(VerticalMenuView, MenuView);
|
||||||
|
|
||||||
VerticalMenuView.prototype.redraw = function() {
|
VerticalMenuView.prototype.redraw = function() {
|
||||||
//VerticalMenuView.super_.prototype.redrawAllItems.call(this);
|
|
||||||
VerticalMenuView.super_.prototype.redraw.call(this);
|
VerticalMenuView.super_.prototype.redraw.call(this);
|
||||||
|
|
||||||
for(var i = this.viewableRange.top; i < this.viewableRange.bottom; ++i) {
|
for(var i = this.visibleRange.top; i < this.visibleRange.bottom; ++i) {
|
||||||
this.items[i].focused = this.focusedItemIndex === i;
|
this.items[i].focused = this.focusedItemIndex === i;
|
||||||
this.drawItem(i);
|
this.drawItem(i);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +192,6 @@ VerticalMenuView.prototype.setFocus = function(focused) {
|
||||||
this.redraw();
|
this.redraw();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) {
|
VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
|
|
||||||
var prevFocusedItemIndex = this.focusedItemIndex;
|
var prevFocusedItemIndex = this.focusedItemIndex;
|
||||||
|
@ -184,6 +212,8 @@ VerticalMenuView.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
|
|
||||||
if(prevFocusedItemIndex !== this.focusedItemIndex) {
|
if(prevFocusedItemIndex !== this.focusedItemIndex) {
|
||||||
this.changeSelection(prevFocusedItemIndex, this.focusedItemIndex);
|
this.changeSelection(prevFocusedItemIndex, this.focusedItemIndex);
|
||||||
|
|
||||||
|
this.changeSelection2(prevFocusedItemIndex, this.focusedItemIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
VerticalMenuView.super_.prototype.onSpecialKeyPress.call(this, keyName);
|
VerticalMenuView.super_.prototype.onSpecialKeyPress.call(this, keyName);
|
||||||
|
@ -200,5 +230,7 @@ VerticalMenuView.prototype.setItems = function(items) {
|
||||||
this.cachePositions();
|
this.cachePositions();
|
||||||
this.scaleDimension();
|
this.scaleDimension();
|
||||||
|
|
||||||
this.updateViewable();
|
this.maxVisibleItems = this.dimens.height / (this.itemSpacing + 1);
|
||||||
|
|
||||||
|
this.jumpVisibleToTop();
|
||||||
};
|
};
|
Loading…
Reference in New Issue