* Better view inheritance. Experimental ButtonView. User stuff

This commit is contained in:
NuSkooler 2014-10-23 22:18:38 -06:00
parent 8cd062be72
commit 668fdd9166
8 changed files with 171 additions and 202 deletions

View file

@ -2,9 +2,12 @@
'use strict';
var TextView = require('./text_view.js').TextView;
var miscUtil = require('./misc_util.js');
var util = require('util');
var assert = require('assert');
exports.ButtonView = ButtonView;
function ButtonView(client, options) {
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
@ -15,15 +18,10 @@ function ButtonView(client, options) {
util.inherits(ButtonView, TextView);
ButtonView.prototype.onKeyPress = function(key, isSpecial) {
// we accept input so this must be implemented -- nothing to do here, however
// :TODO: Move this to View along with default asserts; update EditTextView to call View
}
ButtonView.super_.prototype.onKeyPress.call(this, key, isSpecial);
ButtonView.prototype.onSpecialKeyPress = function(keyName) {
assert(this.hasFocus);
assert(this.acceptsInput);
assert(this.specialKeyMap);
// :TODO: see notes about making base handle 'enter' key(s)
// ...just make enter = enter | space for a button by default
}
// allow spacebar to 'click' buttons
if(' ' === key) {
this.emit('action', 'accept');
}
};