Улучшил отображение процентов в статус баре

This commit is contained in:
Book Pauk
2019-01-22 05:26:25 +07:00
parent dbb511b35e
commit 055aa5ff20
2 changed files with 20 additions and 8 deletions

View File

@@ -8,9 +8,9 @@ export default class DrawHelper {
const fh = h - 2*pad; const fh = h - 2*pad;
const fh2 = fh/2; const fh2 = fh/2;
const t1 = `${Math.floor(bookPos/1000)}k/${Math.floor(textLength/1000)}k`; const t1 = `${Math.floor((bookPos + 1)/1000)}k/${Math.floor(textLength/1000)}k`;
const w1 = context.measureText(t1).width + fh2; const w1 = context.measureText(t1).width + fh2;
const read = bookPos/textLength; const read = (bookPos + 1)/textLength;
const t2 = `${(read*100).toFixed(2)}%`; const t2 = `${(read*100).toFixed(2)}%`;
const w2 = context.measureText(t2).width; const w2 = context.measureText(t2).width;
let w3 = w - w1 - w2; let w3 = w - w1 - w2;

View File

@@ -274,10 +274,6 @@ class TextPage extends Vue {
if (!this.book || !this.parsed.textLength) if (!this.book || !this.parsed.textLength)
return; return;
if (this.showStatusBar)
this.drawHelper.drawStatusBar(context, this.statusBarTop, this.statusBarHeight,
this.statusBarColor, bookPos, this.parsed.textLength, this.title);
context.font = this.font; context.font = this.font;
context.fillStyle = this.textColor; context.fillStyle = this.textColor;
const spaceWidth = context.measureText(' ').width; const spaceWidth = context.measureText(' ').width;
@@ -354,6 +350,23 @@ class TextPage extends Vue {
} }
} }
} }
this.drawStatusBar(context, lines);
}
drawStatusBar(context, lines) {
if (!lines)
lines = this.linesDown;
if (this.showStatusBar) {
let i = this.pageLineCount;
if (this.keepLastToFirst)
i--;
i = (i > lines.length - 1 ? lines.length - 1 : i);
this.drawHelper.drawStatusBar(context, this.statusBarTop, this.statusBarHeight,
this.statusBarColor, lines[i].end, this.parsed.textLength, this.title);
}
} }
async refreshTime() { async refreshTime() {
@@ -362,8 +375,7 @@ class TextPage extends Vue {
await sleep(60*1000); await sleep(60*1000);
if (this.book && this.parsed.textLength) { if (this.book && this.parsed.textLength) {
this.drawHelper.drawStatusBar(this.context, this.statusBarTop, this.statusBarHeight, this.drawStatusBar(this.context);
this.statusBarColor, this.bookPos, this.parsed.textLength, this.title);
} }
this.timeRefreshing = false; this.timeRefreshing = false;
this.refreshTime(); this.refreshTime();