mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Update XtcReaderChapterSelectionActivity.cpp
This commit is contained in:
parent
fa28400e6f
commit
95b660541b
@ -12,7 +12,7 @@ int page = 1;
|
||||
} // namespace
|
||||
|
||||
int XtcReaderChapterSelectionActivity::getPageItems() const {
|
||||
return 25; // ✅ 优化:固定返回25,匹配业务逻辑
|
||||
return 25; // 固定返回25
|
||||
}
|
||||
|
||||
void XtcReaderChapterSelectionActivity::taskTrampoline(void* param) {
|
||||
@ -68,19 +68,19 @@ void XtcReaderChapterSelectionActivity::loop() {
|
||||
if (skipPage || isUpKey) {
|
||||
page -= 1;
|
||||
if(page < 1) page = 1;
|
||||
selectorIndex = (page-1)*25; // ✅ BUG修复:局部索引0,选中当前页第一个
|
||||
selectorIndex = (page-1)*25;
|
||||
} else {
|
||||
selectorIndex--; // ✅ BUG修复:局部索引减1
|
||||
if(selectorIndex < 0) selectorIndex = 0; // ✅ 边界防护
|
||||
selectorIndex--;
|
||||
if(selectorIndex < 0) selectorIndex = 0;
|
||||
}
|
||||
updateRequired = true;
|
||||
} else if (nextReleased) {
|
||||
bool isDownKey = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
||||
if (skipPage || isDownKey) {
|
||||
page += 1;
|
||||
selectorIndex = (page-1)*25; // ✅ BUG修复:局部索引24,选中当前页第一个
|
||||
selectorIndex = (page-1)*25;
|
||||
} else {
|
||||
selectorIndex++; // ✅ BUG修复:局部索引加1
|
||||
selectorIndex++;
|
||||
}
|
||||
updateRequired = true;
|
||||
}
|
||||
@ -100,7 +100,7 @@ void XtcReaderChapterSelectionActivity::renderScreen() {
|
||||
renderer.clearScreen();
|
||||
const int pagebegin=(page-1)*25;
|
||||
int page_chapter=25;
|
||||
static int parsedPage = -1; // ✅ 保留页码缓存,只解析1次
|
||||
static int parsedPage = -1;
|
||||
|
||||
if (parsedPage != page) {
|
||||
xtc->readChapters_gd(pagebegin);
|
||||
@ -113,22 +113,22 @@ void XtcReaderChapterSelectionActivity::renderScreen() {
|
||||
const int FIX_LINE_HEIGHT = 29;
|
||||
const int BASE_Y = 60;
|
||||
|
||||
// ✅ 强制循环渲染25章(pagebegin ~ pagebegin+24),无有效数判断、不截断、不满也留空行
|
||||
for (int i = pagebegin; i <= pagebegin + page_chapter - 1; i++) {
|
||||
int localIdx = i - pagebegin; // ✅ 保留核心修复:全局索引→局部索引0~24,必加!读取数据全靠它
|
||||
|
||||
uint32_t currOffset = this->xtc->getChapterstartpage(i); // ✅ 传局部索引,能读到正确数据
|
||||
std::string dirTitle = this->xtc->getChapterTitleByIndex(i); // ✅ 传局部索引,能读到正确标题
|
||||
for (int i = pagebegin; i <= pagebegin + page_chapter - 1; i++) {
|
||||
int localIdx = i - pagebegin;
|
||||
|
||||
uint32_t currOffset = this->xtc->getChapterstartpage(i);
|
||||
std::string dirTitle = this->xtc->getChapterTitleByIndex(i);
|
||||
|
||||
Serial.printf("[%lu] [XTC_CHAPTER] 第%d章,名字为:%s,页码为%d\n", millis(), i, dirTitle.c_str(),currOffset);
|
||||
static char title[64];
|
||||
strncpy(title, dirTitle.c_str(), sizeof(title)-1);
|
||||
title[sizeof(title)-1] = '\0';
|
||||
|
||||
int drawY = BASE_Y + localIdx * FIX_LINE_HEIGHT; // ✅ 简化计算,逻辑正确
|
||||
int drawY = BASE_Y + localIdx * FIX_LINE_HEIGHT;
|
||||
|
||||
Serial.printf("选中的选项是:%d\n",selectorIndex); // ✅ 补全换行符,日志整洁
|
||||
renderer.drawText(UI_10_FONT_ID, 20, drawY, title, i!= selectorIndex); // ✅ 核心修复:选中态正常,必加!
|
||||
Serial.printf("选中的选项是:%d\n",selectorIndex);
|
||||
renderer.drawText(UI_10_FONT_ID, 20, drawY, title, i!= selectorIndex);
|
||||
}
|
||||
|
||||
renderer.displayBuffer();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user