* Properly handle item spacing in VerticalMenuView
This commit is contained in:
parent
d5017203ac
commit
6dfda0e6d4
|
@ -32,8 +32,7 @@ function MenuView(options) {
|
||||||
this.focusedItemIndex = options.focusedItemIndex || 0;
|
this.focusedItemIndex = options.focusedItemIndex || 0;
|
||||||
this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0;
|
this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0;
|
||||||
|
|
||||||
this.itemSpacing = options.itemSpacing || 1;
|
this.itemSpacing = _.isNumber(options.itemSpacing) ? options.itemSpacing : 0;
|
||||||
this.itemSpacing = parseInt(this.itemSpacing, 10);
|
|
||||||
|
|
||||||
this.focusPrefix = options.focusPrefix || '';
|
this.focusPrefix = options.focusPrefix || '';
|
||||||
this.focusSuffix = options.focusSuffix || '';
|
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) {
|
MenuView.prototype.setHotKeys = function(hotKeys) {
|
||||||
if(_.isObject(hotKeys)) {
|
if(_.isObject(hotKeys)) {
|
||||||
if(this.caseInsensitiveHotKeys) {
|
if(this.caseInsensitiveHotKeys) {
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
var MenuView = require('./menu_view.js').MenuView;
|
var MenuView = require('./menu_view.js').MenuView;
|
||||||
var ansi = require('./ansi_term.js');
|
var ansi = require('./ansi_term.js');
|
||||||
var strUtil = require('./string_util.js');
|
var strUtil = require('./string_util.js');
|
||||||
|
var miscUtil = require('./misc_util.js');
|
||||||
|
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
|
@ -16,8 +18,6 @@ function VerticalMenuView(options) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.itemSpacing = 3; // :TODO: bring from options/configurable
|
|
||||||
|
|
||||||
this.calculateDimens = function() {
|
this.calculateDimens = function() {
|
||||||
if(!self.dimens || !self.dimens.width) {
|
if(!self.dimens || !self.dimens.width) {
|
||||||
var l = 0;
|
var l = 0;
|
||||||
|
@ -31,7 +31,7 @@ function VerticalMenuView(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.items.length > 0) {
|
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 {
|
} else {
|
||||||
this.dimens.height = 0;
|
this.dimens.height = 0;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ function VerticalMenuView(options) {
|
||||||
var x = self.position.x;
|
var x = self.position.x;
|
||||||
for(var i = 0; i < count; ++i) {
|
for(var i = 0; i < count; ++i) {
|
||||||
if(i > 0) {
|
if(i > 0) {
|
||||||
x += self.itemSpacing;
|
x += self.itemSpacing + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.items[i].xPosition = x;
|
self.items[i].xPosition = x;
|
||||||
|
|
|
@ -178,9 +178,13 @@ function ViewController(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
setViewProp('items', function(v) { view.setItems(v); });
|
setViewProp('items', function(v) { view.setItems(v); });
|
||||||
|
setViewProp('itemSpacing', function(v) { view.setItemSpacing(v); });
|
||||||
|
|
||||||
setViewProp('text', function(v) { view.setText(v); });
|
setViewProp('text', function(v) { view.setText(v); });
|
||||||
setViewProp('textStyle');
|
setViewProp('textStyle');
|
||||||
setViewProp('focusTextStyle');
|
setViewProp('focusTextStyle');
|
||||||
|
setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); });
|
||||||
|
|
||||||
setViewProp('maxLength');
|
setViewProp('maxLength');
|
||||||
setViewProp('width', function(v) { view.dimens.width = parseInt(v, 10); });
|
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('hotKeys', function(v) { view.setHotKeys(v); });
|
||||||
|
|
||||||
setViewProp('submit', function(v) {
|
setViewProp('submit', function(v) {
|
||||||
|
|
|
@ -230,6 +230,7 @@
|
||||||
"Art Display",
|
"Art Display",
|
||||||
"Other"
|
"Other"
|
||||||
],
|
],
|
||||||
|
"itemSpacing" : 1,
|
||||||
// :TODO: justify not working??
|
// :TODO: justify not working??
|
||||||
"focusTextStyle" : "small i"
|
"focusTextStyle" : "small i"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue