pace: factor out `drawSplit()`

master
Rob Pilling 2024-10-10 18:08:53 +01:00
parent 25b16a1738
commit 4493b343bd
1 changed files with 13 additions and 10 deletions

View File

@ -104,13 +104,10 @@ const drawSplits = () => {
g.setFont("6x8", 2).setFontAlign(-1, -1); g.setFont("6x8", 2).setFontAlign(-1, -1);
let i = 0; let i = 0;
let totalTime = 0;
for(; ; i++) { for(; ; i++) {
const split = splits[i + splitOffset]; const split = splits[i + splitOffset];
if (split == null) break; if (split == null) break;
totalTime += split;
const y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2; const y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
if (y > h) break; if (y > h) break;
@ -118,17 +115,23 @@ const drawSplits = () => {
g.setColor("#00f").fillRect(0, y, size, y + barSize); g.setColor("#00f").fillRect(0, y, size, y + barSize);
const splitPace = calculatePace(split, 1); // Pace per km const splitPace = calculatePace(split, 1); // Pace per km
g.setColor("#fff").drawString(`${i + 1 + splitOffset} @ ${splitPace.toFixed(2)}`, 0, y); drawSplit(i, y, splitPace);
} }
const pace = exs.stats.pacec.getString(); const pace = exs.stats.pacec.getString();
const splitTime = exs.state.duration - totalTime;
g.setColor("#fff").drawString( const y = Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2;
`${i + 1 + splitOffset} @ ${pace} (${(splitTime / 1000).toFixed(2)})`, drawSplit(i, y, pace);
0, };
Bangle.appRect.y + i * (barSize + barSpacing) + barSpacing / 2,
); const drawSplit = (i: number, y: number, pace: number | string) => {
g
.setColor("#fff")
.drawString(
`${i + 1 + splitOffset} ${typeof pace === "number" ? pace.toFixed(2) : pace}`,
0,
y
);
}; };
const pauseRun = () => { const pauseRun = () => {