2014-10-31 04:59:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +00:00
|
|
|
const MenuView = require('./menu_view.js').MenuView;
|
|
|
|
const ansi = require('./ansi_term.js');
|
|
|
|
const strUtil = require('./string_util.js');
|
|
|
|
const formatString = require('./string_format');
|
|
|
|
const pipeToAnsi = require('./color_codes.js').pipeToAnsi;
|
2015-05-04 21:39:48 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const util = require('util');
|
|
|
|
const _ = require('lodash');
|
2014-10-31 04:59:21 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
exports.VerticalMenuView = VerticalMenuView;
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
function VerticalMenuView(options) {
|
2022-06-05 20:04:25 +00:00
|
|
|
options.cursor = options.cursor || 'hide';
|
|
|
|
options.justify = options.justify || 'left';
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
MenuView.call(this, options);
|
|
|
|
|
2018-06-24 04:23:22 +00:00
|
|
|
this.initDefaultWidth();
|
2018-06-24 02:16:44 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const self = this;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// we want page up/page down by default
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!_.isObject(options.specialKeyMap)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
Object.assign(this.specialKeyMap, {
|
2022-06-05 20:04:25 +00:00
|
|
|
'page up': ['page up'],
|
|
|
|
'page down': ['page down'],
|
2018-06-22 05:15:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.autoAdjustHeightIfEnabled = function () {
|
|
|
|
if (this.autoAdjustHeight) {
|
|
|
|
this.dimens.height =
|
|
|
|
this.items.length * (this.itemSpacing + 1) - this.itemSpacing;
|
|
|
|
this.dimens.height = Math.min(
|
|
|
|
this.dimens.height,
|
|
|
|
this.client.term.termHeight - this.position.row
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-24 02:16:44 +00:00
|
|
|
this.autoAdjustHeightIfEnabled();
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.updateViewVisibleItems = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
self.maxVisibleItems = Math.ceil(self.dimens.height / (self.itemSpacing + 1));
|
|
|
|
|
|
|
|
self.viewWindow = {
|
2022-06-05 20:04:25 +00:00
|
|
|
top: self.focusedItemIndex,
|
|
|
|
bottom:
|
|
|
|
Math.min(
|
|
|
|
self.focusedItemIndex + self.maxVisibleItems,
|
|
|
|
self.items.length
|
|
|
|
) - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.drawItem = function (index) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const item = self.items[index];
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!item) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cached = this.getRenderCacheItem(index, item.focused);
|
2022-06-05 20:04:25 +00:00
|
|
|
if (cached) {
|
|
|
|
return self.client.term.write(
|
|
|
|
`${ansi.goto(item.row, self.position.col)}${cached}`
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let text;
|
|
|
|
let sgr;
|
2022-06-05 20:04:25 +00:00
|
|
|
if (item.focused && self.hasFocusItems()) {
|
2018-06-22 05:15:04 +00:00
|
|
|
const focusItem = self.focusItems[index];
|
|
|
|
text = focusItem ? focusItem.text : item.text;
|
|
|
|
sgr = '';
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.complexItems) {
|
|
|
|
text = pipeToAnsi(
|
|
|
|
formatString(
|
|
|
|
item.focused && this.focusItemFormat
|
|
|
|
? this.focusItemFormat
|
|
|
|
: this.itemFormat,
|
|
|
|
item
|
|
|
|
)
|
|
|
|
);
|
|
|
|
sgr = this.focusItemFormat
|
|
|
|
? ''
|
|
|
|
: index === self.focusedItemIndex
|
|
|
|
? self.getFocusSGR()
|
|
|
|
: self.getSGR();
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
text = strUtil.stylizeString(
|
|
|
|
item.text,
|
|
|
|
item.focused ? self.focusTextStyle : self.textStyle
|
|
|
|
);
|
|
|
|
sgr = index === self.focusedItemIndex ? self.getFocusSGR() : self.getSGR();
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
text = `${sgr}${strUtil.pad(
|
|
|
|
text,
|
|
|
|
this.dimens.width,
|
|
|
|
this.fillChar,
|
|
|
|
this.justify
|
|
|
|
)}`;
|
2018-06-22 05:15:04 +00:00
|
|
|
self.client.term.write(`${ansi.goto(item.row, self.position.col)}${text}`);
|
|
|
|
this.setRenderCacheItem(index, text, item.focused);
|
|
|
|
};
|
2014-10-31 04:59:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(VerticalMenuView, MenuView);
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.redraw = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.redraw.call(this);
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: rename positionCacheExpired to something that makese sense; combine methods for such
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.positionCacheExpired) {
|
2018-06-24 02:16:44 +00:00
|
|
|
this.autoAdjustHeightIfEnabled();
|
2018-06-22 05:15:04 +00:00
|
|
|
this.updateViewVisibleItems();
|
|
|
|
|
|
|
|
this.positionCacheExpired = false;
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// erase old items
|
|
|
|
// :TODO: optimize this: only needed if a item is removed or new max width < old.
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.oldDimens) {
|
|
|
|
const blank = new Array(Math.max(this.oldDimens.width, this.dimens.width)).join(
|
|
|
|
' '
|
|
|
|
);
|
|
|
|
let seq = ansi.goto(this.position.row, this.position.col) + this.getSGR() + blank;
|
|
|
|
let row = this.position.row + 1;
|
|
|
|
const endRow = row + this.oldDimens.height - 2;
|
|
|
|
|
|
|
|
while (row <= endRow) {
|
2018-06-22 05:15:04 +00:00
|
|
|
seq += ansi.goto(row, this.position.col) + blank;
|
|
|
|
row += 1;
|
|
|
|
}
|
|
|
|
this.client.term.write(seq);
|
|
|
|
delete this.oldDimens;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.items.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
let row = this.position.row;
|
2022-06-05 20:04:25 +00:00
|
|
|
for (let i = this.viewWindow.top; i <= this.viewWindow.bottom; ++i) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.items[i].row = row;
|
|
|
|
row += this.itemSpacing + 1;
|
|
|
|
this.items[i].focused = this.focusedItemIndex === i;
|
|
|
|
this.drawItem(i);
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 03:57:23 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setHeight = function (height) {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setHeight.call(this, height);
|
2015-06-30 05:14:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.positionCacheExpired = true;
|
2018-06-24 02:16:44 +00:00
|
|
|
this.autoAdjustHeight = false;
|
2015-06-30 05:14:17 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setPosition = function (pos) {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setPosition.call(this, pos);
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.positionCacheExpired = true;
|
2014-10-31 22:25:11 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setFocus = function (focused) {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setFocus.call(this, focused);
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
2015-12-24 18:54:03 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setFocusItemIndex = function (index) {
|
|
|
|
VerticalMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex
|
2016-02-03 04:35:59 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const remainAfterFocus = this.items.length - index;
|
2022-06-05 20:04:25 +00:00
|
|
|
if (remainAfterFocus >= this.maxVisibleItems) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow = {
|
2022-06-05 20:04:25 +00:00
|
|
|
top: this.focusedItemIndex,
|
|
|
|
bottom:
|
|
|
|
Math.min(
|
|
|
|
this.focusedItemIndex + this.maxVisibleItems,
|
|
|
|
this.items.length
|
|
|
|
) - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
2016-07-18 04:15:43 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.positionCacheExpired = false; // skip standard behavior
|
2018-06-24 02:16:44 +00:00
|
|
|
this.autoAdjustHeightIfEnabled();
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2016-08-11 04:48:13 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
2014-11-01 15:50:11 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.onKeyPress = function (ch, key) {
|
|
|
|
if (key) {
|
|
|
|
if (this.isKeyMapped('up', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusPrevious();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.isKeyMapped('down', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusNext();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.isKeyMapped('page up', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusPreviousPageItem();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.isKeyMapped('page down', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusNextPageItem();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.isKeyMapped('home', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusFirst();
|
2022-06-05 20:04:25 +00:00
|
|
|
} else if (this.isKeyMapped('end', key.name)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VerticalMenuView.super_.prototype.onKeyPress.call(this, ch, key);
|
2014-11-02 19:07:17 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.getData = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
const item = this.getItem(this.focusedItemIndex);
|
|
|
|
return _.isString(item.data) ? item.data : this.focusedItemIndex;
|
2014-11-02 19:07:17 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setItems = function (items) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// if we have items already, save off their drawing area so we don't leave fragments at redraw
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.items && this.items.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
|
|
|
}
|
2016-07-03 05:09:27 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setItems.call(this, items);
|
2014-11-02 19:07:17 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.positionCacheExpired = true;
|
2015-06-30 05:14:17 +00:00
|
|
|
};
|
2015-05-06 04:19:21 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.removeItem = function (index) {
|
|
|
|
if (this.items && this.items.length) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
|
|
|
}
|
2017-02-02 02:42:27 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.removeItem.call(this, index);
|
2017-02-02 02:42:27 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: Apply draw optimizaitons when only two items need drawn vs entire view!
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusNext = function () {
|
|
|
|
if (this.items.length - 1 === this.focusedItemIndex) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusedItemIndex = 0;
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow = {
|
2022-06-05 20:04:25 +00:00
|
|
|
top: 0,
|
|
|
|
bottom: Math.min(this.maxVisibleItems, this.items.length) - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.focusedItemIndex++;
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.focusedItemIndex > this.viewWindow.bottom) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow.top++;
|
|
|
|
this.viewWindow.bottom++;
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
2015-10-11 22:05:45 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.focusNext.call(this);
|
2015-09-18 04:53:19 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusPrevious = function () {
|
|
|
|
if (0 === this.focusedItemIndex) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusedItemIndex = this.items.length - 1;
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow = {
|
2018-06-23 03:26:46 +00:00
|
|
|
//top : this.items.length - this.maxVisibleItems,
|
2022-06-05 20:04:25 +00:00
|
|
|
top: Math.max(this.items.length - this.maxVisibleItems, 0),
|
|
|
|
bottom: this.items.length - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.focusedItemIndex--;
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.focusedItemIndex < this.viewWindow.top) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow.top--;
|
|
|
|
this.viewWindow.bottom--;
|
2016-07-18 04:15:43 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// adjust for focus index being set & window needing expansion as we scroll up
|
2022-06-05 20:04:25 +00:00
|
|
|
const rem = this.viewWindow.bottom - this.viewWindow.top + 1;
|
|
|
|
if (
|
|
|
|
rem < this.maxVisibleItems &&
|
|
|
|
this.items.length - 1 > this.focusedItemIndex
|
|
|
|
) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow.bottom = this.items.length - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
2015-10-11 22:05:45 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.focusPrevious.call(this);
|
2015-09-18 04:53:19 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusPreviousPageItem = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Jump to current - up to page size or top
|
|
|
|
// If already at the top, jump to bottom
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2022-06-05 20:04:25 +00:00
|
|
|
if (0 === this.focusedItemIndex) {
|
|
|
|
return this.focusPrevious(); // will jump to bottom
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const index = Math.max(this.focusedItemIndex - this.dimens.height, 0);
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (index < this.viewWindow.top) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
|
|
|
}
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.setFocusItemIndex(index);
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return VerticalMenuView.super_.prototype.focusPreviousPageItem.call(this);
|
2017-09-01 23:41:08 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusNextPageItem = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Jump to current + up to page size or bottom
|
|
|
|
// If already at the bottom, jump to top
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.items.length - 1 === this.focusedItemIndex) {
|
|
|
|
return this.focusNext(); // will jump to top
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const index = Math.min(
|
|
|
|
this.focusedItemIndex + this.maxVisibleItems,
|
|
|
|
this.items.length - 1
|
|
|
|
);
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (index > this.viewWindow.bottom) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusedItemIndex = index;
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow = {
|
2022-06-05 20:04:25 +00:00
|
|
|
top: this.focusedItemIndex,
|
|
|
|
bottom:
|
|
|
|
Math.min(
|
|
|
|
this.focusedItemIndex + this.maxVisibleItems,
|
|
|
|
this.items.length
|
|
|
|
) - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
|
|
|
} else {
|
|
|
|
this.setFocusItemIndex(index);
|
|
|
|
}
|
2017-09-01 23:41:08 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return VerticalMenuView.super_.prototype.focusNextPageItem.call(this);
|
2017-09-01 23:41:08 +00:00
|
|
|
};
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusFirst = function () {
|
|
|
|
if (0 < this.viewWindow.top) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
|
|
|
}
|
|
|
|
this.setFocusItemIndex(0);
|
|
|
|
return VerticalMenuView.super_.prototype.focusFirst.call(this);
|
2018-06-10 04:45:01 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.focusLast = function () {
|
2018-06-22 05:15:04 +00:00
|
|
|
const index = this.items.length - 1;
|
2018-06-10 04:50:57 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (index > this.viewWindow.bottom) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.oldDimens = Object.assign({}, this.dimens);
|
2018-06-10 04:50:57 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.focusedItemIndex = index;
|
2018-06-10 04:50:57 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.viewWindow = {
|
2022-06-05 20:04:25 +00:00
|
|
|
top: this.focusedItemIndex,
|
|
|
|
bottom:
|
|
|
|
Math.min(
|
|
|
|
this.focusedItemIndex + this.maxVisibleItems,
|
|
|
|
this.items.length
|
|
|
|
) - 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
2018-06-10 04:50:57 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.redraw();
|
|
|
|
} else {
|
|
|
|
this.setFocusItemIndex(index);
|
|
|
|
}
|
2018-06-10 04:50:57 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return VerticalMenuView.super_.prototype.focusLast.call(this);
|
2018-06-10 04:45:01 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setFocusItems = function (items) {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setFocusItems.call(this, items);
|
2015-08-26 05:17:09 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.positionCacheExpired = true;
|
2015-10-11 22:05:45 +00:00
|
|
|
};
|
2015-08-26 05:17:09 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
VerticalMenuView.prototype.setItemSpacing = function (itemSpacing) {
|
2018-06-22 05:15:04 +00:00
|
|
|
VerticalMenuView.super_.prototype.setItemSpacing.call(this, itemSpacing);
|
2015-05-06 22:43:49 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.positionCacheExpired = true;
|
2022-06-05 20:04:25 +00:00
|
|
|
};
|