From d2c8bd90f088b9649a0bc573b24cb74f2cd78295 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 24 Dec 2015 11:54:03 -0700 Subject: [PATCH] setFocusItemIndex() support --- core/spinner_menu_view.js | 6 ++++++ core/text_view.js | 5 ++++- core/vertical_menu_view.js | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/spinner_menu_view.js b/core/spinner_menu_view.js index 8050015b..65ac10af 100644 --- a/core/spinner_menu_view.js +++ b/core/spinner_menu_view.js @@ -64,6 +64,12 @@ SpinnerMenuView.prototype.setFocus = function(focused) { this.redraw(); }; +SpinnerMenuView.prototype.setFocusItemIndex = function(index) { + SpinnerMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex + + this.updateSelection(); // will redraw +}; + SpinnerMenuView.prototype.onKeyPress = function(ch, key) { if(key) { if(this.isKeyMapped('up', key.name)) { diff --git a/core/text_view.js b/core/text_view.js index bea8570c..96261ec5 100644 --- a/core/text_view.js +++ b/core/text_view.js @@ -89,6 +89,7 @@ function TextView(options) { return this.position.col + offset; }; + // :TODO: Whatever needs init here should be done separately from setText() since it redraws/etc. this.setText(options.text || ''); } @@ -97,7 +98,9 @@ util.inherits(TextView, View); TextView.prototype.redraw = function() { TextView.super_.prototype.redraw.call(this); - this.drawText(this.text); + if(_.isString(this.text)) { + this.drawText(this.text); + } }; TextView.prototype.setFocus = function(focused) { diff --git a/core/vertical_menu_view.js b/core/vertical_menu_view.js index 72bc2a40..6e290969 100644 --- a/core/vertical_menu_view.js +++ b/core/vertical_menu_view.js @@ -146,6 +146,12 @@ VerticalMenuView.prototype.setFocus = function(focused) { this.redraw(); }; +VerticalMenuView.prototype.setFocusItemIndex = function(index) { + VerticalMenuView.super_.prototype.setFocusItemIndex.call(this, index); // sets this.focusedItemIndex + + this.redraw(); +}; + VerticalMenuView.prototype.onKeyPress = function(ch, key) { if(key) {