* Properly handle item spacing in VerticalMenuView

This commit is contained in:
Bryan Ashby 2015-05-04 15:39:48 -06:00
parent d5017203ac
commit 6dfda0e6d4
4 changed files with 18 additions and 7 deletions

View File

@ -32,8 +32,7 @@ function MenuView(options) {
this.focusedItemIndex = options.focusedItemIndex || 0;
this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0;
this.itemSpacing = options.itemSpacing || 1;
this.itemSpacing = parseInt(this.itemSpacing, 10);
this.itemSpacing = _.isNumber(options.itemSpacing) ? options.itemSpacing : 0;
this.focusPrefix = options.focusPrefix || '';
this.focusSuffix = options.focusSuffix || '';
@ -105,6 +104,13 @@ MenuView.prototype.setItems = function(items) {
}
};
MenuView.prototype.setItemSpacing = function(itemSpacing) {
assert(_.isNumber(itemSpacing));
this.itemSpacing = itemSpacing;
this.positionCacheExpired = true;
};
MenuView.prototype.setHotKeys = function(hotKeys) {
if(_.isObject(hotKeys)) {
if(this.caseInsensitiveHotKeys) {

View File

@ -4,6 +4,8 @@
var MenuView = require('./menu_view.js').MenuView;
var ansi = require('./ansi_term.js');
var strUtil = require('./string_util.js');
var miscUtil = require('./misc_util.js');
var util = require('util');
var assert = require('assert');
@ -16,8 +18,6 @@ function VerticalMenuView(options) {
var self = this;
this.itemSpacing = 3; // :TODO: bring from options/configurable
this.calculateDimens = function() {
if(!self.dimens || !self.dimens.width) {
var l = 0;
@ -31,7 +31,7 @@ function VerticalMenuView(options) {
}
if(this.items.length > 0) {
this.dimens.height = (self.items.length * self.itemSpacing) - (self.itemSpacing - 1);
this.dimens.height = (self.items.length * (self.itemSpacing + 1)) - (self.itemSpacing);
} else {
this.dimens.height = 0;
}
@ -45,7 +45,7 @@ function VerticalMenuView(options) {
var x = self.position.x;
for(var i = 0; i < count; ++i) {
if(i > 0) {
x += self.itemSpacing;
x += self.itemSpacing + 1;
}
self.items[i].xPosition = x;

View File

@ -178,9 +178,13 @@ function ViewController(options) {
}
setViewProp('items', function(v) { view.setItems(v); });
setViewProp('itemSpacing', function(v) { view.setItemSpacing(v); });
setViewProp('text', function(v) { view.setText(v); });
setViewProp('textStyle');
setViewProp('focusTextStyle');
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
setViewProp('maxLength');
setViewProp('width', function(v) { view.dimens.width = parseInt(v, 10); });
@ -208,7 +212,7 @@ function ViewController(options) {
}
});
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
setViewProp('hotKeys', function(v) { view.setHotKeys(v); });
setViewProp('submit', function(v) {

View File

@ -230,6 +230,7 @@
"Art Display",
"Other"
],
"itemSpacing" : 1,
// :TODO: justify not working??
"focusTextStyle" : "small i"
}