Add navigator

main
Devin Leamy 2023-10-28 15:15:50 -04:00
parent 46a196e301
commit f1b7cf6a85
2 changed files with 96 additions and 37 deletions

View File

@ -73,6 +73,7 @@ var TimerApp = /** @class */ (function () {
this.height = g.getWidth(); this.height = g.getWidth();
this.timers = []; this.timers = [];
this.displayedTimerIndex = 0; this.displayedTimerIndex = 0;
this.displayTextY = 20;
this.timeTextY = this.height * (2.0 / 5.0); this.timeTextY = this.height * (2.0 / 5.0);
this.lastTickTimeMS = Date.now(); this.lastTickTimeMS = Date.now();
this.loadStateOrDefault(); this.loadStateOrDefault();
@ -102,10 +103,11 @@ var TimerApp = /** @class */ (function () {
self.leftButton.onClick(x, y); self.leftButton.onClick(x, y);
self.rightButton.onClick(x, y); self.rightButton.onClick(x, y);
} }
self.topLeftButton.onClick(x, y);
self.topRightButton.onClick(x, y);
}, },
remove: function () { remove: function () {
self.pauseTimer(); self.pauseTimer();
// Bangle.removeListener("lcdPower", onLCDPower)
g.setTheme(originalTheme); g.setTheme(originalTheme);
} }
}); });
@ -116,6 +118,9 @@ var TimerApp = /** @class */ (function () {
g.fillRect(0, 0, this.width, this.height); g.fillRect(0, 0, this.width, this.height);
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
// These buttons don't update so they only need to be drawn once.
this.topLeftButton.draw();
this.topRightButton.draw();
}; };
TimerApp.prototype.initializeButtons = function () { TimerApp.prototype.initializeButtons = function () {
var self = this; var self = this;
@ -136,6 +141,13 @@ var TimerApp = /** @class */ (function () {
this.largeButton = new Button(0.0, (3.0 / 4.0) * this.height, this.width, this.height / 4.0, BLUE_COLOR, startOrPauseTimer, PLAY_IMG); this.largeButton = new Button(0.0, (3.0 / 4.0) * this.height, this.width, this.height / 4.0, BLUE_COLOR, startOrPauseTimer, PLAY_IMG);
this.leftButton = new Button(0.0, (3.0 / 4.0) * this.height, this.width / 2.0, this.height / 4.0, YELLOW_COLOR, resetTimer, PLAY_IMG); this.leftButton = new Button(0.0, (3.0 / 4.0) * this.height, this.width / 2.0, this.height / 4.0, YELLOW_COLOR, resetTimer, PLAY_IMG);
this.rightButton = new Button(this.width / 2.0, (3.0 / 4.0) * this.height, this.width / 2.0, this.height / 4.0, BLUE_COLOR, resumeTimer, PAUSE_IMG); this.rightButton = new Button(this.width / 2.0, (3.0 / 4.0) * this.height, this.width / 2.0, this.height / 4.0, BLUE_COLOR, resumeTimer, PAUSE_IMG);
var navigatorButtonSize = this.width / 8.0;
this.topLeftButton = new Button(0.0, 0.0, navigatorButtonSize, navigatorButtonSize, BLUE_COLOR, function () {
self.gotoPreviousTimer();
}, RESET_IMG);
this.topRightButton = new Button(this.width - navigatorButtonSize, 0.0, navigatorButtonSize, navigatorButtonSize, BLUE_COLOR, function () {
self.gotoNextTimer();
}, RESET_IMG);
}; };
TimerApp.prototype.startTimer = function () { TimerApp.prototype.startTimer = function () {
var self = this; var self = this;
@ -200,6 +212,9 @@ var TimerApp = /** @class */ (function () {
timers: this.timers timers: this.timers
}); });
}; };
TimerApp.prototype.timerCount = function () {
return this.timers.length;
};
TimerApp.prototype.loadStateOrDefault = function () { TimerApp.prototype.loadStateOrDefault = function () {
var state = require("Storage").readJSON(STORAGE_FILE, 1); var state = require("Storage").readJSON(STORAGE_FILE, 1);
if (state == undefined) { if (state == undefined) {
@ -245,6 +260,10 @@ var TimerApp = /** @class */ (function () {
g.setFontAlign(0, 0); g.setFontAlign(0, 0);
g.clearRect(0, this.timeTextY - 21, this.width, this.timeTextY + 21); g.clearRect(0, this.timeTextY - 21, this.width, this.timeTextY + 21);
g.drawString(timeText, this.width / 2, this.timeTextY); g.drawString(timeText, this.width / 2, this.timeTextY);
var displayText = this.displayText();
g.setFont("Vector", 14);
g.clearRect(this.width * 0.25, this.displayTextY - 21, this.width * 0.75, this.displayTextY + 21);
g.drawString(displayText, this.width / 2, this.displayTextY);
}; };
TimerApp.prototype.draw = function () { TimerApp.prototype.draw = function () {
g.setColor(g.theme.fg); g.setColor(g.theme.fg);
@ -257,24 +276,21 @@ var TimerApp = /** @class */ (function () {
this.updateInterval = undefined; this.updateInterval = undefined;
} }
}; };
return TimerApp; TimerApp.prototype.gotoNextTimer = function () {
}()); this.displayedTimerIndex = (this.displayedTimerIndex + 1) % this.timerCount();
var Timer = /** @class */ (function () { };
function Timer(state) { TimerApp.prototype.gotoPreviousTimer = function () {
this.totalTime = state.totalTime; this.displayedTimerIndex =
this.startTime = state.startTime; (this.displayedTimerIndex - 1 + this.timerCount()) % this.timerCount();
this.currentTime = state.currentTime; };
this.running = state.running; TimerApp.prototype.displayText = function () {
var text = "";
for (var i = 0; i < this.timerCount(); ++i) {
text += i == this.displayedTimerIndex ? "0" : "=";
} }
Timer.prototype.state = function () { return text;
return {
totalTime: this.totalTime,
startTime: this.startTime,
currentTime: this.currentTime,
running: this.running
}; };
}; return TimerApp;
return Timer;
}()); }());
var app = new TimerApp(); var app = new TimerApp();
app.run(); app.run();

View File

@ -116,9 +116,12 @@ class TimerApp {
timers: TimerState[] timers: TimerState[]
displayedTimerIndex: number displayedTimerIndex: number
timeTextY: number timeTextY: number
displayTextY: number
largeButton!: Button largeButton!: Button
leftButton!: Button leftButton!: Button
rightButton!: Button rightButton!: Button
topLeftButton!: Button
topRightButton!: Button
updateInterval: undefined | any updateInterval: undefined | any
lastTickTimeMS: number lastTickTimeMS: number
@ -127,6 +130,7 @@ class TimerApp {
this.height = g.getWidth() this.height = g.getWidth()
this.timers = [] this.timers = []
this.displayedTimerIndex = 0 this.displayedTimerIndex = 0
this.displayTextY = 20
this.timeTextY = this.height * (2.0 / 5.0) this.timeTextY = this.height * (2.0 / 5.0)
this.lastTickTimeMS = Date.now() this.lastTickTimeMS = Date.now()
this.loadStateOrDefault() this.loadStateOrDefault()
@ -158,10 +162,12 @@ class TimerApp {
self.leftButton.onClick(x, y) self.leftButton.onClick(x, y)
self.rightButton.onClick(x, y) self.rightButton.onClick(x, y)
} }
self.topLeftButton.onClick(x, y)
self.topRightButton.onClick(x, y)
}, },
remove: () => { remove: () => {
self.pauseTimer() self.pauseTimer()
// Bangle.removeListener("lcdPower", onLCDPower)
g.setTheme(originalTheme) g.setTheme(originalTheme)
}, },
}) })
@ -173,6 +179,9 @@ class TimerApp {
g.fillRect(0, 0, this.width, this.height) g.fillRect(0, 0, this.width, this.height)
Bangle.loadWidgets() Bangle.loadWidgets()
Bangle.drawWidgets() Bangle.drawWidgets()
// These buttons don't update so they only need to be drawn once.
this.topLeftButton.draw()
this.topRightButton.draw()
} }
initializeButtons() { initializeButtons() {
@ -222,6 +231,30 @@ class TimerApp {
resumeTimer, resumeTimer,
PAUSE_IMG PAUSE_IMG
) )
const navigatorButtonSize = this.width / 8.0
this.topLeftButton = new Button(
0.0,
0.0,
navigatorButtonSize,
navigatorButtonSize,
BLUE_COLOR,
function () {
self.gotoPreviousTimer()
},
RESET_IMG
)
this.topRightButton = new Button(
this.width - navigatorButtonSize,
0.0,
navigatorButtonSize,
navigatorButtonSize,
BLUE_COLOR,
function () {
self.gotoNextTimer()
},
RESET_IMG
)
} }
startTimer() { startTimer() {
@ -297,6 +330,10 @@ class TimerApp {
}) })
} }
timerCount() {
return this.timers.length
}
loadStateOrDefault() { loadStateOrDefault() {
let state = require("Storage").readJSON(STORAGE_FILE, 1) let state = require("Storage").readJSON(STORAGE_FILE, 1)
if (state == undefined) { if (state == undefined) {
@ -344,6 +381,17 @@ class TimerApp {
g.setFontAlign(0, 0) g.setFontAlign(0, 0)
g.clearRect(0, this.timeTextY - 21, this.width, this.timeTextY + 21) g.clearRect(0, this.timeTextY - 21, this.width, this.timeTextY + 21)
g.drawString(timeText, this.width / 2, this.timeTextY) g.drawString(timeText, this.width / 2, this.timeTextY)
const displayText = this.displayText()
g.setFont("Vector", 14)
g.clearRect(
this.width * 0.25,
this.displayTextY - 21,
this.width * 0.75,
this.displayTextY + 21
)
g.drawString(displayText, this.width / 2, this.displayTextY)
} }
draw() { draw() {
@ -358,28 +406,23 @@ class TimerApp {
this.updateInterval = undefined this.updateInterval = undefined
} }
} }
gotoNextTimer() {
this.displayedTimerIndex = (this.displayedTimerIndex + 1) % this.timerCount()
} }
class Timer { gotoPreviousTimer() {
totalTime: number this.displayedTimerIndex =
startTime: number (this.displayedTimerIndex - 1 + this.timerCount()) % this.timerCount()
currentTime: number
running: boolean
constructor(state: TimerState) {
this.totalTime = state.totalTime
this.startTime = state.startTime
this.currentTime = state.currentTime
this.running = state.running
} }
state(): TimerState { displayText(): string {
return { let text = ""
totalTime: this.totalTime, for (let i = 0; i < this.timerCount(); ++i) {
startTime: this.startTime, text += i == this.displayedTimerIndex ? "0" : "="
currentTime: this.currentTime,
running: this.running,
} }
return text
} }
} }