* Some code cleanup

+ Bit of skeleton for TickerTextView
* Detach of events in ViewController
This commit is contained in:
Bryan Ashby 2014-11-04 00:34:54 -07:00
parent eaf2aae48d
commit d242546458
5 changed files with 104 additions and 4 deletions

View File

@ -36,7 +36,7 @@ function MenuView(client, options) {
this.justify = this.options.justify || 'none'; this.justify = this.options.justify || 'none';
this.moveSelection = function(fromIndex, toIndex) { this.moveSelection = function(fromIndex, toIndex) {
assert(!self.xPositionCacheExpired); assert(!self.positionCacheExpired);
assert(fromIndex >= 0 && fromIndex <= self.items.length); assert(fromIndex >= 0 && fromIndex <= self.items.length);
assert(toIndex >= 0 && toIndex <= self.items.length); assert(toIndex >= 0 && toIndex <= self.items.length);
@ -48,13 +48,14 @@ function MenuView(client, options) {
self.drawItem(toIndex); self.drawItem(toIndex);
}; };
/*
this.cachePositions = function() { this.cachePositions = function() {
// :TODO: implement me! // :TODO: implement me!
}; };
this.drawItem = function(index) { this.drawItem = function(index) {
// :TODO: implement me! // :TODO: implement me!
}; };*/
} }
util.inherits(MenuView, View); util.inherits(MenuView, View);

94
core/ticker_text_view.js Normal file
View File

@ -0,0 +1,94 @@
/* jslint node: true */
'use strict';
var View = require('./view.js').View;
var miscUtil = require('./misc_util.js');
var strUtil = require('./string_util.js');
var ansi = require('./ansi_term.js');
var util = require('util');
var assert = require('assert');
exports.TickerTextView = TickerTextView;
TickerTextView = function(client, options) {
View.call(this, client, options);
var self = this;
this.text = this.options.text || '';
this.tickerStyle = this.options.tickerStyle || 'rightToLeft';
asssert(this.tickerStyle in TickerTextView.TickerStyles);
// :TODO: Ticker |text| should have ANSI stripped before calculating any lengths/etc.
// strUtil.ansiTextLength(s)
// strUtil.pad(..., ignoreAnsi)
// strUtil.stylizeString(..., ignoreAnsi)
this.tickerState = {};
switch(this.tickerStyle) {
case 'rightToLeft' :
this.tickerState.pos = this.position.x + this.dimens.width;
break;
}
self.onTickerInterval = function() {
switch(self.tickerStyle) {
case 'rightToLeft' : self.updateRightToLeftTicker(); break;
}
};
self.updateRightToLeftTicker = function() {
// if pos < start
// drawRemain()
// if pos + remain > end
// drawRemain(0, spaceFor)
// else
// drawString() + remainPading
};
}
util.inherits(TickerTextView, View);
TickerTextView.TickerStyles = {
leftToRight : 1,
rightToLeft : 2,
bounce : 3,
slamLeft : 4,
slamRight : 5,
slamBounce : 6,
decrypt : 7,
typewriter : 8,
};
Object.freeze(TickerTextView.TickerStyles);
/*
TickerTextView.TICKER_STYLES = [
'leftToRight',
'rightToLeft',
'bounce',
'slamLeft',
'slamRight',
'slamBounce',
'decrypt',
'typewriter',
];
*/
TickerTextView.prototype.controllerAttached = function() {
// :TODO: call super
};
TickerTextView.prototype.controllerDetached = function() {
// :TODO: call super
};
TickerTextView.prototype.setText = function(text) {
this.text = strUtil.stylizeString(text, this.textStyle);
if(!this.dimens || !this.dimens.width) {
this.dimens.width = Math.ceil(this.text.length / 2);
}
};

View File

@ -101,6 +101,10 @@ ViewController.prototype.detachClientEvents = function() {
this.client.removeListener('key press', this.onClientKeyPress); this.client.removeListener('key press', this.onClientKeyPress);
this.client.removeListener('special key', this.onClientSpecialKeyPress); this.client.removeListener('special key', this.onClientSpecialKeyPress);
for(var id in this.views) {
this.views[id].removeAllListeners();
}
this.attached = false; this.attached = false;
}; };
@ -179,7 +183,7 @@ ViewController.prototype.loadFromMCIMap = function(mciMap) {
if(view) { if(view) {
view.on('action', self.onViewAction); view.on('action', self.onViewAction);
self.addView(view); // :TODO: Needs detached self.addView(view);
view.redraw(); // :TODO: This can result in double redraw() if we set focus on this item after view.redraw(); // :TODO: This can result in double redraw() if we set focus on this item after
} }
}); });

View File

@ -29,7 +29,7 @@ function entryPoint(client) {
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) { //art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
//client.user.properties.art_theme_id = ''; //client.user.properties.art_theme_id = '';
theme.getThemeArt('MATRIX_1.ANS', client.user.properties.art_theme_id, function onArt(err, theArt) { theme.getThemeArt('MCI_ET1.ANS', client.user.properties.art_theme_id, function onArt(err, theArt) {
//art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) { //art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) {
if(!err) { if(!err) {

View File

@ -35,6 +35,7 @@ function entryPoint(client) {
function artDisplayed(mci, callback) { function artDisplayed(mci, callback) {
var vc = new viewController.ViewController(client); var vc = new viewController.ViewController(client);
vc.loadFromMCIMap(mci); vc.loadFromMCIMap(mci);
vc.getView(1).setItems(['Item 1', 'Item Two', 'The Third']);
vc.setViewOrder(); vc.setViewOrder();
vc.switchFocus(1); vc.switchFocus(1);
} }