* Some code cleanup
+ Bit of skeleton for TickerTextView * Detach of events in ViewController
This commit is contained in:
parent
eaf2aae48d
commit
d242546458
|
@ -36,7 +36,7 @@ function MenuView(client, options) {
|
|||
this.justify = this.options.justify || 'none';
|
||||
|
||||
this.moveSelection = function(fromIndex, toIndex) {
|
||||
assert(!self.xPositionCacheExpired);
|
||||
assert(!self.positionCacheExpired);
|
||||
assert(fromIndex >= 0 && fromIndex <= self.items.length);
|
||||
assert(toIndex >= 0 && toIndex <= self.items.length);
|
||||
|
||||
|
@ -48,13 +48,14 @@ function MenuView(client, options) {
|
|||
self.drawItem(toIndex);
|
||||
};
|
||||
|
||||
/*
|
||||
this.cachePositions = function() {
|
||||
// :TODO: implement me!
|
||||
};
|
||||
|
||||
this.drawItem = function(index) {
|
||||
// :TODO: implement me!
|
||||
};
|
||||
};*/
|
||||
}
|
||||
|
||||
util.inherits(MenuView, View);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
|
@ -101,6 +101,10 @@ ViewController.prototype.detachClientEvents = function() {
|
|||
this.client.removeListener('key press', this.onClientKeyPress);
|
||||
this.client.removeListener('special key', this.onClientSpecialKeyPress);
|
||||
|
||||
for(var id in this.views) {
|
||||
this.views[id].removeAllListeners();
|
||||
}
|
||||
|
||||
this.attached = false;
|
||||
};
|
||||
|
||||
|
@ -179,7 +183,7 @@ ViewController.prototype.loadFromMCIMap = function(mciMap) {
|
|||
|
||||
if(view) {
|
||||
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
|
||||
}
|
||||
});
|
||||
|
|
|
@ -29,7 +29,7 @@ function entryPoint(client) {
|
|||
|
||||
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
|
||||
//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) {
|
||||
if(!err) {
|
||||
|
|
|
@ -35,6 +35,7 @@ function entryPoint(client) {
|
|||
function artDisplayed(mci, callback) {
|
||||
var vc = new viewController.ViewController(client);
|
||||
vc.loadFromMCIMap(mci);
|
||||
vc.getView(1).setItems(['Item 1', 'Item Two', 'The Third']);
|
||||
vc.setViewOrder();
|
||||
vc.switchFocus(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue