From a01f5d2f248d8af67b565ff5ae7987b05f41a157 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 4 May 2015 22:04:36 -0600 Subject: [PATCH] * Just some notes --- core/toggle_menu_view.js | 2 +- core/vertical_menu_view.js | 24 ++++++++++++++++++++++++ core/view.js | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/toggle_menu_view.js b/core/toggle_menu_view.js index 639df6aa..2dfd714f 100644 --- a/core/toggle_menu_view.js +++ b/core/toggle_menu_view.js @@ -24,7 +24,7 @@ function ToggleMenuView (options) { this.updateSelection = function() { assert(!self.positionCacheExpired); - assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length); + assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length); self.redraw(); }; diff --git a/core/vertical_menu_view.js b/core/vertical_menu_view.js index 10c6b486..85cff4df 100644 --- a/core/vertical_menu_view.js +++ b/core/vertical_menu_view.js @@ -8,6 +8,7 @@ var miscUtil = require('./misc_util.js'); var util = require('util'); var assert = require('assert'); +var _ = require('lodash'); exports.VerticalMenuView = VerticalMenuView; @@ -18,6 +19,29 @@ function VerticalMenuView(options) { var self = this; + // + // :TODO: view.setDimens() would set autoSize to false. Otherwise, we cna scale @ setItems() + // topViewIndex = top visibile item + // itemsInView = height * (1 + itemSpacing) + this.calculateDimens2 = function() { + if(this.autoSize) { + self.dimens = self.dimens || {}; + + if(!_.isNumber(this.dimens.height) || this.dimens.height < 1) { + this.dimens.height = 1; + } + + var l = 0; + self.items.forEach(function item(i) { + if(i.text.length > l) { + l = Math.min(l.text.length, self.client.term.termWidth - self.position.y); + } + }); + self.dimens.width = l; + } + }; + + this.calculateDimens = function() { if(!self.dimens || !self.dimens.width) { var l = 0; diff --git a/core/view.js b/core/view.js index 091ce0ee..d404f060 100644 --- a/core/view.js +++ b/core/view.js @@ -68,8 +68,8 @@ function View(options) { options.dimens = { width : 1, height : 1 }; } - options.dimens.width = options.dimens.width || 1; - options.dimens.height = options.dimens.height || 1; + //options.dimens.width = options.dimens.width || 1; + //options.dimens.height = options.dimens.height || 1; this.ansiSGR = options.ansiSGR || ansi.getSGRFromGraphicRendition( { fg : 39, bg : 49 }, true); this.ansiFocusSGR = options.ansiFocusSGR || this.ansiSGR;